CreateProcess() c++ file not found

后端 未结 4 1036
星月不相逢
星月不相逢 2021-01-22 15:18

I\'m trying to use CreateProcess to start a child process, however I keep getting error 2, which, according to the documentation is file not found.

4条回答
  •  悲&欢浪女
    2021-01-22 15:25

    Error 2 is ERROR_FILE_NOT_FOUND. As others have told you, you are relying on a relative path when you need to use an absolute path instead.

    Also, LPCTSTR("test.exe") is not valid code. If UNICODE is defined, CreateFile() maps to CreateFileW(), and LPCTSTR maps to LPCWSTR ie const wchar_t*. You cannot typecast a char* to a wchar_t* and end up with meaningful data. If you want to use TCHAR-sensitive literals, use the TEXT() macro instead, eg:

    if (!CreateProcess(TEXT("full path to\\test.exe"), ...))
    

    Otherwise, forget using TCHAR and just write Ansi-specific or Unicode-specific code instead, depending on your needs:

    if (!CreateProcessA("full path to\\test.exe", ...))
    

    if (!CreateProcessW(L"full path to\\test.exe", ...))
    

提交回复
热议问题