关于这个问题我搜索了很多,关于如何将字符串从 delphi dll 传递到 .NET 没有明确的答案。下一个代码基于 msdn 帮助文件:http: //msdn.microsoft.com/en-us/图书馆/4zey12w5.aspx
//Delphi code
function myDelphiFunc(var Buffer: PChar): Integer; export; stdcall;
Buffer:='this is a test';
Return:=0;
end;
//vb.NET code
<DllImport(path)> _
Public Function myDelphiFunc(ByVal buffer As String) As Integer
Public Sub myNETFunc()
Dim buffer_size As integer = 25
Dim buffer As String = New String(CChar(" "), buffer_size )
Call myDelphiFunc(buffer)
MsgBox(Strings.Left(buffer, InStr(buffer, Chr(0)) - 1))
End Sub
调用 myDelphiFunc 时,我在“缓冲区”变量中收到一个空字符串。我究竟做错了什么?
提前致谢