【发布时间】:2013-12-29 19:02:51
【问题描述】:
我目前正在做 DirectX11 并尝试将 UTF8 字符串转换为 LPCWSTR。我编写了一个实用函数来帮助我进行转换:
// Convert an UTF8 string to a wide Unicode String
std::wstring WidenString(const std::string &string)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, string.c_str(), string.size(), NULL, 0);
std::wstring wstring(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, string.c_str(), string.size(), &wstring[0], size_needed);
return wstring;
}
我已经使用调试器来验证它是否有效。这是有效的:
调试器说 wndClassEx.lpszClassName = L"Hello"
std::wstring str = WidenString("Hello");
wndClassEx.lpszClassName = str.c_str();
这不起作用:
调试器说wndClassEx.lpszClassName = L “ووووووووووووووووووووووووووووووو...” P>
wndClassEx.lpszClassName = WidenString("Hello").c_str();
有人可以向我解释我的代码有什么问题吗?
【问题讨论】:
标签: c++ visual-c++ c++11 directx directx-11