作为不同的平台应用,经常会有非托管的dll文件需要调用. 在这里需要注意的两个地方,在这里我只说delphi编写的文件.非托管dll被C#调用首先是数据类型的问题,在delphi里面如果需要被其他程序语言调用,作为参数或者返回值的字符不能使用string类型,而是pchar.而对于recode,则对应是struct 比如,在delphi里面函数原形 function A():pchar;export; stdcall; c#调用 [DllImport(@"xxx.dll")]public static extern string A(); delphi type TypeA=packed recorda1:pChar;a2:pChar;end;function B(A:TypeA):boolean;export; stdcall; c# public TypeARsaKey B(TypeA A); 第二个问题是如果我们需要返回recode,那么我们不能使用函数返回模式,而应该使用var形式 delphi: type TypeA=packed recorda1:pChar;a2:pChar;end;function B(var A:TypeA):boolean;export; stdcall; c# public TypeARsaKey B(ref TypeA A); 相关文章: 2021-12-01 2022-02-01 2021-10-02 2022-12-23 2021-07-28 2022-12-23 2021-08-26 2022-12-23