如何使用字符串参数在Delphi中调用C DLL?
我的Delphi应用程序从一个C DLL调用一个函数,该函数应该返回这样的字符串.
C DLL
__declspec( dllexport ) void sample(char* str1, char* str2)
{
strcpy(str1, "123");
strcpy(str2, "abc");
}
德尔福
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;
这样做的正确方法是什么?