直接传个空的定长String进去也可以啊 不过函数声明的时候要声明是ByVal xxx As StringDim X As String*255 '定长String
直接string传过去,VB会自动转换
API函数原型: "C" __declspec(dllexport) int putValue(char * session,char * key,char * value);VB中声明: Private Declare Function putValue Lib "abc.dll" (session As Byte, key As Byte, value As Byte) As Long 'Private Declare Function putValue Lib "abc.dll" (session As String, key As String, value As String) As Long我用上面两种方法声明和调用函数都会出错: Bad DLL calling convention请问是怎么回事?
Private Declare Function putValue Lib "abc.dll" (byval session As String, byval key As String, byval value As String) As Long Private Declare Function putValue Lib "abc.dll" (byval session As Long, byval key As Long, byval value As Long) As Long '调用putValue StrPtr(s),StrPtr(k),StrPtr(v),不行的话dim b1() as byte,b2() as byte,b3() as byte;b1=strconv(s,vbfromunicode);b2=strconv(k,vbfromunicode);b3=strconv(v,vbfromunicode);putValue varptr(b1(0)),varptr(b2(0)),varptr(b3(0)) 这3种试试
Dim a() As Byte
a = StrConv("测试一下", vbFromUnicode)
For i = LBound(a) To UBound(a)
Debug.Print a(i)
Next
不过函数声明的时候要声明是ByVal xxx As StringDim X As String*255 '定长String
"C" __declspec(dllexport) int putValue(char * session,char * key,char * value);VB中声明:
Private Declare Function putValue Lib "abc.dll" (session As Byte, key As Byte, value As Byte) As Long
'Private Declare Function putValue Lib "abc.dll" (session As String, key As String, value As String) As Long我用上面两种方法声明和调用函数都会出错:
Bad DLL calling convention请问是怎么回事?
Private Declare Function putValue Lib "abc.dll" (byval session As String, byval key As String, byval value As String) As Long
Private Declare Function putValue Lib "abc.dll" (byval session As Long, byval key As Long, byval value As Long) As Long '调用putValue StrPtr(s),StrPtr(k),StrPtr(v),不行的话dim b1() as byte,b2() as byte,b3() as byte;b1=strconv(s,vbfromunicode);b2=strconv(k,vbfromunicode);b3=strconv(v,vbfromunicode);putValue varptr(b1(0)),varptr(b2(0)),varptr(b3(0))
这3种试试