我将非常感谢任何人对如何将Unicode字符串从托管(Delphi .NET)传递(编组)到非托管(Delphi的Win32 DLL)函数的帮助。
托管环境(Delphi .NET):
...
interface
...
const TM_PRO_CONVERTER = 'TM.PROFileConverter.dll';
function ImportLineworksFromPROFile(FileName :String;
TargetFileNameDXF :String): Integer;
...
implementation
...
[DllImport(TM_PRO_CONVERTER, EntryPoint = 'ImportLineworksFromPROFile',
CharSet = CharSet.Ansi, SetLastError = True,
CallingConvention = CallingConvention.StdCall)]
function ImportLineworksFromPROFile(FileName :String;
TargetFileNameDXF :String): Integer; external;
...
非托管环境(Delphi的Win32 DLL):
library TM.PROFileConverter;
...
function ImportLineworksFromPROFile(FileName :String;
TargetFileNameDXF :String) :Integer; stdcall;
exports
ImportLineworksFromPROFile;
...
感谢您的时间。
答案 0 :(得分:3)
function ImportLineworksFromPROFile(FileName :PChar;
TargetFileNameDXF :PChar) :Integer; stdcall;
PS:非托管函数使用ANSI编码,而不是Unicode。如果您希望非托管代码处理unicode,您应该在托管端使用PWideChar或WideString而不是PChar和CharSet = CharSet.Unicode。
答案 1 :(得分:0)
我不知道Delphi.NET如何处理事情,但我有一些组合本机win32 Delphi和C#.NET代码的经验,如果你可以使用COM
InterOp,你会看到TLB类库导入单元使用WideString
并为您处理接口,因此我会朝这个方向进行研究。