I want to pass a string to my CreateProcess function so that I can use this function for all my operations. How to do it correctly?
Below is my code:
CString ExecuteExternalProgram(CString pictureName)
{
CString parameterOne = _T(" -format \"%h\" C:\\");
CString filename = pictureName;
CString parameterLast = _T("\"");
CString parameterFull = parameterOne + filename + parameterLast;
CreateProcess(_T("C:\\identify.exe"), parameterFull,0,0,TRUE,
NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);
CloseHandle(wPipe);
.......
}
Error:
Error 2 error C2664: ‘CreateProcessW’ : cannot convert parameter 2 from ‘ATL::CString’ to ‘LPWSTR’ c:\a.cpp
You’ll need to do something like:
CreateProcess()wants a writeable buffer for the command line parameter for some reason, so the implicit conversion ofCStringto a plain old pointer doesn’t happen (since it’ll only perform the implicit conversion if it’s to a const pointer).If this isn’t the problem you’re running into, post more details about the error or unexpected behavior you’re running into.
As an example, the following runs a little utilty program that dumps the commandline it’s given: