是PChar UTF-8编码的吗?

Dan*_*ler 1 delphi pascal utf-8 character-encoding

我正在编写一个使用C-DLL的工具.C-DLL的功能期望a char*,其为UTF-8格式.我的问题:我可以通过PChar或必须使用UTF8Encode(string)吗?

Dav*_*nan 5

考虑名为的字符串变量s.在ANSI Delphi上PChar(s)是ANSI编码的.在Unicode Delphi上,它是UTF-16编码的.

因此,无论哪种方式,您都需要转换s为UTF-8编码.然后您可以使用PAnsiChar(...)获取指向空终止的C字符串的指针.

所以,你需要的代码如下所示:

PAnsiChar(UTF8Encode(s))
Run Code Online (Sandbox Code Playgroud)

  • 它也不在Delphi 6中编译.它从未在任何版本的Delphi中编译. (3认同)