转换的char *为LPWSTR [英] Convert char * to LPWSTR
问题描述
我想一个程序转换为多字节字符的Uni code。
I am trying to convert a program for multibyte character to Unicode.
我已经通过方案和$ P $不见了pceded与 L时字符串
让它们看起来像 L串
。
I have gone through the program and preceded the string literals with L
so they look like L"string"
.
这工作,但我现在只剩下一个C风格的字符串,将不符合。我曾尝试→
,并把它放在 TEXT()
但→
被添加到变量名 - 而不是字符串 - 如果我使用 TEXT()
This has worked but I am now left with a C style string that won't conform. I have tried the L
and putting it in TEXT()
but the L
gets added to the variable name -- not the string -- if I use TEXT()
.
我试图使它成为一个 TCHAR
但随后抱怨说,它不能转换 TCHAR
到的char *
。
I have tried making it a TCHAR
but then it complains that it cannot convert a TCHAR
to a char *
.
哪些选项是我离开?
在您downvote想疯了,我知道C和C ++是不同的。它是已在C ++工程中使用了几年来的老内部C库。
Before you downvote like crazy I know C and C++ are different. It is an old in-house C library that has been used in C++ projects for several years now.
推荐答案
的std :: mbstowcs
功能是你在找什么:
The std::mbstowcs
function is what you are looking for:
char text[] = "something";
wchar_t wtext[20];
mbstowcs(wtext, text, strlen(text)+1);//Plus null
LPWSTR ptr = wtext;
- > ED:将LpreFIX只适用于字符串,而不是变量。 < -
--> ED: The "L" prefix only works on string literals, not variables. <--
这篇关于转换的char *为LPWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!