斑竹:
    向大家请教有关VB调用VC编写的DLL函数时遇到的问题,还请大家不吝赐教。
    我的源码是这样写的:VC++中编写的Dll文件:
.h头文件中的声明:
void __stdcall test(char* name,char* ver);
.def文件中的出口:
test @1
.cpp文件中的函数:
void __stdcall test(char* name,char* ver)
{
 char str1[]="***人名"; 
 char str2[]="Mike"; 
 name=str1;
 ver=str2;
}VB中:
声明:
Public Declare Sub test Lib "test.dll" (ByVal name As String, ByVal ver As String)
窗体中的函数:
Private Sub btnInfo_Click()
    Dim name As String
    Dim ver As String
    test name, ver
    lblInfo.Caption = name & ver
    MsgBox name & ver, vbExclamation, "432323@#$@#@#$@$#"
 
end Sub    问题出现了:在VB中调用test函数,为获得name 与 ver字符串值,但获取的值始终都是空,请问各位在VB中我该如何获得“***人名”与“Mike”的值。

解决方案 »

  1.   

    '去掉Byval
    Public Declare Sub test Lib "test.dll" (name As String, ver As String)
      

  2.   

    把ByVal改为ByRef,或直接去掉ByVal
      

  3.   

    char* 要用 BYTE()
    byref byte()
      

  4.   

    可以试试 SafeArray , 应该行, 需要例子PM我.
      

  5.   

    to ft1000:
        你好,我在Csdn上给你发了一个消息,请你给我回复,谢谢!
      

  6.   

    //问题出现了:在VB中调用test函数,为获得name 与 ver字符串值,但获取的值始终都是空,请问各位在VB中我该如何获得“***人名”与“Mike”的值。这是你没有为字串分配缓冲区的缘故Public Declare Sub test Lib "test.dll" (ByVal name As String, ByVal ver As String)
    窗体中的函数:
    Private Sub btnInfo_Click()
        Dim name As String
        Dim ver As String
        name=space(260)(或者用string函数分配)
        ver=string(260,chr(0))
        test name, ver
        '还要对字串进行处理,这个问题你应该会,就不写了,不会的话,提示:用instr和left
        lblInfo.Caption = name & ver
        MsgBox name & ver, vbExclamation, "432323@#$@#@#$@$#"
     
    end Sub
      

  7.   

    这样写声明:
    Public Declare Sub test Lib "test.dll" (ByVal name As String, ByVal ver As String)
    窗体中的函数:
    Private Sub btnInfo_Click()
        Dim pname As String
        Dim pver As String
        pname=string(256,0)
        pver=string(256,0)
        test name, ver
        pname=left$(pname,instr(1,pname,vbnullchar)-1)
        pver=left$(pver,instr(1,pver,vbnullchar)-1)
        lblInfo.Caption = pname & pver
        MsgBox pname & pver, vbExclamation, "432323@#$@#@#$@$#"
     
    end Sub