VB调用动态链接库关于指针参数的有关问题
VB调用动态链接库关于指针参数的问题
我在VC写了个DLL,原型如下:
extern "C " void __declspec(dllexport)Test(char *);
void Test(char *input)
{
input[0] = 'h ';
input[1] = 'e ';
input[2] = 'l ';
input[3] = 'l ';
input[4] = 'o ';
input[5] = '\0 ';
}
在VC调用的方法是
char a[6];
Test(a);
意思是先创建6个字节的空间,然后把这6个字节的首地址传入函数,在函数里面为这6个字节填值,那我在VB里面应该怎么调用这个DLL?
我试了
Declare Function Test Lib "mydll.dll " (ByRef a() As Byte)
Declare Function Test Lib "mydll.dll " (ByRef a As Byte)
Declare Function Test Lib "mydll.dll " (ByRef a As string)
都不行
------解决方案--------------------
Declare Function Test Lib "mydll.dll " (byval a as long)
调用一:
dim I(5) as byte
test varptr(i(0))
debug.print strconv(i,vbunicode)
调用二:
dim I as string * 255
test strptr(i) '如果这样用,最好在函数返回值里返回字符串长度,方便取出有效字符
debug.print i
------解决方案--------------------
同WM_JAWIN ,
Declare Function Test Lib "mydll.dll " (byval a As string)
vb调用api时能自动处理字符串。不过要预先设定长度,再作为参数传递
dim I as string * 255
我在VC写了个DLL,原型如下:
extern "C " void __declspec(dllexport)Test(char *);
void Test(char *input)
{
input[0] = 'h ';
input[1] = 'e ';
input[2] = 'l ';
input[3] = 'l ';
input[4] = 'o ';
input[5] = '\0 ';
}
在VC调用的方法是
char a[6];
Test(a);
意思是先创建6个字节的空间,然后把这6个字节的首地址传入函数,在函数里面为这6个字节填值,那我在VB里面应该怎么调用这个DLL?
我试了
Declare Function Test Lib "mydll.dll " (ByRef a() As Byte)
Declare Function Test Lib "mydll.dll " (ByRef a As Byte)
Declare Function Test Lib "mydll.dll " (ByRef a As string)
都不行
------解决方案--------------------
Declare Function Test Lib "mydll.dll " (byval a as long)
调用一:
dim I(5) as byte
test varptr(i(0))
debug.print strconv(i,vbunicode)
调用二:
dim I as string * 255
test strptr(i) '如果这样用,最好在函数返回值里返回字符串长度,方便取出有效字符
debug.print i
------解决方案--------------------
同WM_JAWIN ,
Declare Function Test Lib "mydll.dll " (byval a As string)
vb调用api时能自动处理字符串。不过要预先设定长度,再作为参数传递
dim I as string * 255