I need to create a variable to use in the CreateProcess:
CreateProcess(z7Cmdline, z7Arg, NULL, NULL, FALSE, NULL, NULL, NULL, &startInfo, &processInfo);
The variable z7Arg is a argument list for 7 -zip which contains a file name based on the current date ie: 2017-12-13.zip.
string buArg = "-o""c:\\moshe"" a " + buDir + buFileName + "c:\\moshe\\*.pdf";
I want to copy buArg into z7Arg as a LPTSTR to use in the CreateProcess routine
How do I go about it?
I am new at coding in C++, 30 years ago I programed in IBM Fortran & Assembly language for Grumman Aerospace, but have done little coding since then.
When compiling for Unicode,
TCHAR-based APIs map towchar_t-based functions, and when compiling for ANSI/MCBS, they map tochar-based functions instead.So, in your case, the
TCHAR-basedCreateProcess()macro maps to eitherCreateProcessA()takingchar*strings, orCreateProcessW()takingwchar_t*strings.std::stringoperates withcharonly, andstd::wstringoperates withwchar_tonly.So, the simplest solution to your issue is to just call
CreateProcessA()directly, eg:If you want to call
CreateProcessW(), usestd::wstringinstead:In this latter case, if your input must be
std:string, then you have to use a runtime conversion, viaMultiByteToWideChar(),std::wstring_convert, etc.Or, you could use
std::basic_string<TCHAR>instead: