There is nothing new about Windows 10 in this respect. Your question is really about Unicode versus ANSI, and Visual Studio's new default settings which use Unicode.
CreateProcess
is a macro, it is defined as
#ifdef UNICODE
#define CreateProcess CreateProcessW
#else
#define CreateProcess CreateProcessA
#endif // !UNICODE
In addition STARTUPINFO
is a macro for STARTUPINFOA
and STARTUPINFOW
CreateProcessA
uses ANSI char strings char*
and STARTUPINFOA
CreateProcessW
uses Unicode wide char strings wchar_t*
and STARTUPINFOW
If you insist on using ANSI (not recommended) then go to Project Settings -> Character Set and disable Unicode.
If you insist on using ANSI version with Unicode settings (still not recommended), you need
//Using ANSI when UNICODE is defined (not recommended):
STARTUPINFOA si = { sizeof(si) };
PROCESS_INFORMATION pi;
std::string path = "c:\\windows\\notepad.exe \"c:\\test\\_text.txt\"";
//if not using C++11 or later, force a zero at the end
//to make sure path is null-ternminated
path.push_back(0);
if(CreateProcessA(NULL, &path[0], NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
Above code will work as long as the directory names are ANSI compatible. But the recommended version is:
//recommended:
{
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
std::wstring path = L"c:\\windows\\notepad.exe \"c:\\test\\_text.txt\"";
//if not using C++11 or later, force a zero at the end
//to make sure path is null-ternminated
path.push_back(0);
if(CreateProcess(0, &path[0], NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
Also, don't cast from constant string to string as follows:
wchar_t* arg_concat = const_cast<wchar_t*>( input.c_str() );
The second argument in CreateProcess
should be wchar_t*
because the process may modify the command line.