1

对于如何将 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;

...

感谢您的时间。

4

2 回答 2

3

.Net,因此 .Net 的 Delphi 无法编组 win32 Delphi 的 AnsiString。它确实知道如何编组 PChar。将 win32 参数更改为 PChar 应该可以。

function ImportLineworksFromPROFile(FileName          :PChar;
                                    TargetFileNameDXF :PChar) :Integer; stdcall;

PS:非托管函数使用ANSI编码,不是Unicode。如果您希望非托管代码处理 unicode,则应在托管端使用 PWideChar 或 WideString 而不是 PChar 和 CharSet = CharSet.Unicode。

于 2010-05-31T07:04:28.733 回答
0

我不完全知道 Delphi.NET 是如何处理事情的,但我有一些结合原生 win32 Delphi 和 C# .NET 代码的经验,如果你可以使用COMInterOp,你会看到 TLB 类库导入单元使用WideString和处理接口对你来说,所以我会朝这个方向研究。

于 2010-05-31T11:24:37.763 回答