-
May 13th, 2011, 10:25 AM
#1
win32 CreateProcess cannot convert parameter 2 from 'char *__w64 ' to 'LPWSTR' error
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 FullPathToExe = 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'
the second error is : the code:
CHAR szPrintBuffer[512];
wsprintf(szPrintBuffer,
"ERROR: API = %s.\n error code = %d.\n message = %s.\n",
pszAPI, GetLastError(), (char *)lpvMessageBuffer);
and the error is :
error C2664: 'wsprintfW' : cannot convert parameter 1 from 'CHAR [512]' to 'LPWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
im not win32 programmer and this is new to me. Thanks for helping
c++ winapi Unicode
-
May 13th, 2011, 11:27 AM
#2
Re: win32 CreateProcess cannot convert parameter 2 from 'char *__w64 ' to 'LPWSTR' er
Since you're compiling for unicode you need to change every char to wchar_t and every string literal to L"MyString".
If you ever want to compile for multibyte use TCHAR for every char/wchar_t and _T("MyString") for every string literal.
-
May 13th, 2011, 01:08 PM
#3
Re: win32 CreateProcess cannot convert parameter 2 from 'char *__w64 ' to 'LPWSTR' er
Along with using the _T("") macro, consider using the CString class instead of the stl string or wstring classes. It correctly handles ANSI and UNICODE based on the compilers build settings.
The newer CString class is a templated class and doesn't rely on MFC (unlike the old CString class in VC6). To use it, just #include <atlstr.h>.
Code:
#include <atlstr.h>
CString sFilePath = _T("c:\\foo\\boo.exe");
if (!CreateProcess(NULL,
sFilePath,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&si,
&pi))
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|