本文介绍了WRL Helper类将Platform :: String ^(PCWSTR)转换为ANSI char *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ATL有简单的宏可以在不同的字符格式之间进行转换(安全)。 WRL是否提供类似的功能?
ATL had easy macros to convert (securely) between the different character formats. Does WRL provide similar functionality?
如果不希望在整个地方使用WideCharToMultiByte和朋友(缓冲区溢出错误等待发生),建议的方法是什么?
Whats the recommended way to do that, if one does not want to use WideCharToMultiByte and friends all over the place (buffer overflow errors waiting to happen).
推荐答案
您可以自己编写此函数,如下所示:
You can write this function by yourself, like this:
String^ str1 = "AAAAAAAA";
wstring wstr( str1->Data() );
int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL);
char* buffer = new char[len + 1];
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL);
buffer[len] = '\0';
http://msdn.microsoft.com/en-us/library/hh438486(v = vs.110).aspx
最好的问候,
Jesse
Best regards,
Jesse
这篇关于WRL Helper类将Platform :: String ^(PCWSTR)转换为ANSI char *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!