读书人

byte()数组的有关问题

发布时间: 2012-02-21 16:26:23 作者: rapoo

byte()数组的问题
在做项目的时候,我在调用一个别人写好的XXX.dll的时候,我用c#写是完全通过的,然后我转成vb。net之后,byte()数组没有通过
以下是api调用的参数
vb.net的
demo(int count,byref A1, byref A2 )
c#的
demo(int count,ref A1, out A2)
c#我已经写通过了,求为什么vb。net不能通过
c#:
byte[] a =new byte[8];
string k="1234567";
byte[] str;
str = System.Text.Encoding.Default.GetBytes( k );
demo(k.length,str,a)//这里成功了
我转vb.net
dim a as byte()=new byte(8){}
dim k as string="1234567"
dim str() as byte
str=System.Text.Encoding.Default.GetBytes( k )
demo(k.length-1,str,a)'这里就出错了
是因为byte数组的问题吗?如果是的话该如何转化

[解决办法]
dim a as byte()=new byte(8){}
=>
dim a() as byte=new byte(8){}

[解决办法]
Declare Function demo Lib "XXX.dll" (count As Integer, ByRef A1 As Byte(), <Out()> ByRef A2 As Byte())

[解决办法]
定长非托管数组需要封送处理之后,才能被托管代码识别。

<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.U1, SizeConst:=8)> Private a() As Byte

读书人网 >VB Dotnet

热点推荐