I tried to create a process with CreateProcess in C++. But this function always returns false.
Here is some pieces of my code:
#if UNICODE std::wstring exename = #else char* exename = #endif _T("c:\\Windows\\Notepad.exe"); STARTUPINFO si; memset(&si, 0, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOW; PROCESS_INFORMATION pi; if (!CreateProcess(exename, NULL, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { cout << "Error code=" << GetLastError() << endl; } The program shows error code 123. And I tried make exename as the second parameter, then the error code changed to 2.
I have googled it for a day and have tried changing charset of the project into Multibyte or Unicode, replacing CreateProcess with CreateProcessA or CreateProcessW, replacing char * with LPCSTR or LPCWSTR and many other attempts. None of them solved the problem but show same error code.
I am running that code in Windows 10 and compile it with Visual Studio 2013. I am sure that "c:\Windows\Notepad.exe" exists on my computer.
It has driven me mad, please help me. Any hint shall be appreciated.
Solution of this problem:
Don't copy and paste the file path from properties dialog of Windows explorer, it may contain some hidden characters.

GetLastErrorfunction immediately when a function's return value indicates that such a call will return useful data." You aren't, and the return value is meaningless at the point where you are calling it. It's unclear, why you are using generic text mappings at all. Just call the Unicode version and call it a day. If you must use generic text mappings, just do this:auto const exename{ _T("c:\\Windows\\Notepad.exe") };.UNICODEis defined then your code will not compile, since you can't pass astd::wstringas-is toCreateProcess(), you need to call itsc_str()ordata()method, which you are not doing.