××××dll中的函数function test():string;stdcall;
begin
result:='成功返回字符串';
end;××××在VB中调用Private Declare Function test Lib "Project1.dll" () As StringPrivate Sub Command1_Click()
MsgBox test
End Sub这样会非法操作~~~该怎么办呢???

解决方案 »

  1.   

    把String改为ShortString或Pchar类型
      

  2.   

    从DLL中返回字符串到VB时,VB要首先分配内存,然后传进去:××××dll中的函数procedure test(s:pchar);stdcall;
    begin
    result:='成功返回字符串';
    end;××××在VB中调用Private Declare Sub test Lib "Project1.dll" (s As String)Private Sub Command1_Click()
      Dim s As String*256  s = ""
      test(s)
      MsgBox s
    End Sub
      

  3.   

    代码有误,更正如下:(已通过测试)××××dll中的函数 Project1.dpruses 
      SysUtils, Classes, Windows;...procedure test(s:pchar);stdcall;
    var
      A: string;
    begin
      A:='成功返回字符串';
      CopyMemory(s, @A[1], Length(A));
    end;××××在VB中调用Private Declare Sub test Lib "Project1.dll" (ByVal s As String)Private Sub Command1_Click()
      Dim s As String * 256  s = ""
      test(s)
      MsgBox s
    End Sub