I encountered a problem when writing a system. I couldn't call a DLL written in Delphi6 in C# because the parameters of the DLL were of type string. Then I searched for relevant information online, but still found no results. After much thinking, I have now solved it. I am writing this article to share my joy with you all!
dellphi dll file:
///////////////////////////////////////////////////// //////////////////
library mydll;
uses
sysutils,
classes;
{$r *.res}
function out_char(str1:pchar;str2:pchar):pchar;stdcall;
var
temp:pchar;
begin
getmem(temp,length(str1)+length(str2)+1);
strcopy(temp,str1);
strcat(temp,str2);
result := temp;
end;
exports
out_char;
begin
end.
///////////////////////////////////////////////////// /////////////
Calling method in c#:
[dllimport(mydll.dll)] public static extern string out_char(string str1,string str2);
Then the dll is implemented to pass string type data.
Haha~~~~~~~