自从我从delphi 5升级到XE以来,我一直在使用不久前编译的特定Dll。我的阻塞点似乎与 unicode/ansi 字符有关,但我还没有找到如何解决问题
下面是一个过程示例:
procedure GetFilename(Buffer: PChar; BufSize: Integer); stdcall;
在我的代码中,我以这种方式调用它
implementation
procedure GetFilename; external 'myDll.dll' name 'GetFilename';
procedure myproc
var
buffer : Array [0..255] of Char;
begin
GetFilename(buffer, length(buffer)-1);
Showmessage(buffer); //This gives me chinese character
end;
缓冲区包含以下内容:
byte((@buffer[0])^); // 67 which is the ASCII for C
byte((@buffer[1])^); // 92 which is the ASCII for
我期望正常的是以"C:\"开头的字符串
有没有人遇到过同样的问题?
因为 dll 是使用 Delphi 的非 Unicode 版本制作的,所以您必须将声明从
procedure GetFilename(Buffer: PChar; BufSize: Integer); stdcall;
自
procedure GetFilename(Buffer: PAnsiChar; BufSize: Integer); stdcall;
和缓冲区变量来自
buffer : Array [0..255] of Char;
自
buffer : Array [0..255] of AnsiChar;
此外,要了解Delphi Unicode支持,请查看Marco Cantú的Delphi and Unicode
白皮书。