hello all i have code from open source project that im integrating into my code . now my code settings in visual studio 2008 character set is Unicode . and the external code is Multi-Byte Character Set. when i change the character setting in my application after adding the new source im getting other errors in my code .
so reading from the net i guess i need to make some changes to the external code to support unicode. here is my code :string 开发者_如何学JAVAFullPathToExe = c:\\foo\\boo.exe;
vector<char> str2(FullPathToExe.begin(), FullPathToExe.end());
str2.push_back('\0');
if (!CreateProcess(NULL,
&str2[0],
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
&pi))
and the error is :
: error C2664: 'CreateProcessW' : cannot convert parameter 2 from 'char *__w64 '
to 'LPWSTR'
im not win32 programmer and this is new to me.
how can i support both developer that are using multi byte and Unicode ?
Thanks for helping
You need to use std::wstring
and vector<wchar_t>
and prefix your strings and chars with L.
For the first one use vector<wchar_t>
instead of vector<char>
.
For the second one use L"ERROR: API = %s.\n error code = %d.\n message = %s.\n"
instead of "ERROR: API = %s.\n error code = %d.\n message = %s.\n"
(note the L
at the start.
Do this instead:
wstring FullPathToExe = "c:\\foo\\boo.exe";
if (!CreateProcess(NULL,
FullPathToExe.c_str(),
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
&pi))
a) you may undefine UNICODE macro in your project settings
b) You may use ascii versions of functions you called, replace wsprintf with sprintf and CreateProcess with CreateProcessA
精彩评论