Windows API函数的参数是char *类型的,查了资料说申明时用Byte来转换,我的数据都是String类型的。我在使用这个API函数的时候,是不是需要将String转换为Byte?如何转换?

解决方案 »

  1.   

    Dim i As Integer
        Dim a() As Byte
        a = StrConv("测试一下", vbFromUnicode)
        For i = LBound(a) To UBound(a)
            Debug.Print a(i)
        Next
      

  2.   

    对于char* 的api参数,声明的时候用byref。传参的时候传入数组的第一个元素(比如上面给你的例子把a(0)传进去即可)
      

  3.   

    直接传个空的定长String进去也可以啊
    不过函数声明的时候要声明是ByVal xxx As StringDim X As String*255 '定长String
      

  4.   

    直接string传过去,VB会自动转换
      

  5.   

    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请问是怎么回事?
      

  6.   

    C" __declspec(dllexport) __stdcall int putValue(char *  session,char * key,char * value);
      

  7.   

    C" __declspec(dllexport) int __stdcall putValue(char *  session,char * key,char * value);
      

  8.   

    DLL中API函数的导出方式有问题?非改不可吗?那个DLL是别人写的:(
      

  9.   

    如果你真的非要用这个dll, 我帮你改成stdcall去吧
      

  10.   

    恩  对的  vc的 dll  如果要给vb 用 必须使用stdcall的方式
      

  11.   


    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种试试