如何将unicode字符串从C++传递到delphi
How to pass unicode string from C++ to delphi?
我发现了许多关于从Delphi传递到C++的主题,但仍然感到困惑。
std::string s1(" look here ");
将它传递给delphi代码的正确方法是什么?
这些都不起作用,产生错误的字符
char * s = (char *)s1.c_str();
Call_Delphi_func(s);
.......
Memo1.Lines.Add(UTF8String(PChar(pointer(s))));
您没有说明您使用的是哪个版本的Delphi,但您使用UTF8String
的方式意味着您使用的是Delphi 2009或更高版本。如果是,则PChar
是PWideChar
(C和C++中的wchar_t*
(。显式使用PAnsiChar
(在C和C++中为char*
(,并去掉不必要的Pointer
类型转换:
std::string s1 = u8" look here ";
char * s = const_cast<char*>(s1.c_str());
Delphi_func(s);
procedure Delphi_func(s: PAnsiChar); stdcall;
begin
Memo1.Lines.Add(UTF8String(s));
end;
或者,将std::wstring
与PWideChar
一起使用:
std::wstring s1 = L" look here ";
wchar_t * s = const_cast<wchar_t*>(s1.c_str());
Delphi_func(s);
procedure Delphi_func(s: PWideChar); stdcall;
begin
Memo1.Lines.Add(s);
end;
相关文章:
- 如何将unicode字符串从C++传递到delphi
- 从 delphi 调用 c++ 函数
- 从Delphi调用C++DLL时发生访问冲突
- 可以从本机代码(如C++/Delphi)中使用.netCore DLL
- 在 c++ 中创建 dll 并在 delphi 中调用的标准方法
- 将 Delphi 的字符串转换为 std::字符串用于C++
- 从C++调用 Delphi DLL 函数
- 如何正确填充并将动态数组发送到Delphi中C 中的功能
- 可以将Delphi dll用于C#
- Delphi / C 构建器 - 在TDBGrid中设置活动 /选择的行颜色
- Invoke JNI_OnLoad from Delphi
- 从C++调用 Delphi DLL IStream 参数的问题
- 我将类型库(.tlb)导入到Delphi中,但函数参数似乎不正确.我应该如何解决它
- 如何将C/C 回调函数转换为Delphi
- 来自C DLL的视觉编辑Delphi记录
- 将C 回调功能转换为Delphi
- 如何在 c++ 中复制 Delphi 的索引属性?
- Delphi 2007 EXE和C++DLL:调试输出:027D4FF8处的堆块在027D5009处修改,超过了请求的9
- DLL函数导出一个指针做Delphi程序
- "Error creating variant or safe array" in TClientDataSet.LoadFromStream() in Delphi