小编use*_*858的帖子

如何使用字符串参数在Delphi中调用C++ DLL?

我的Delphi应用程序从一个C++ DLL调用一个函数,它应该返回这样的字符串.

C++ DLL

__declspec( dllexport ) void sample(char* str1, char* str2)
{
    strcpy(str1, "123");
    strcpy(str2, "abc");
}
Run Code Online (Sandbox Code Playgroud)

德尔福

procedure sample(Str1, Str2: pchar); cdecl; external 'cpp.dll';
var
  buf1 : Pchar;
  buf2 : Pchar;
begin
  sample(@buf1, @buf2);
  //display buf1 and buf2
  //ShowMessage(buf1); //it display random ascii characters 
end;
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

c++ delphi

3
推荐指数
1
解决办法
1300
查看次数

标签 统计

c++ ×1

delphi ×1