C ++ CreateprocessA失败错误

时间:2016-01-31 12:05:17

标签: c++ winapi createprocess

我使用此代码但是我收到一个失败的错误:2我知道这意味着该文件不存在但不知道出错了什么。

DWORD size = 1024;
TCHAR buff[1024];

 int err = AssocQueryString(ASSOCF_INIT_IGNOREUNKNOWN, ASSOCSTR_EXECUTABLE, _T(".html"), NULL, buff, &size);

 STARTUPINFOA si;
 PROCESS_INFORMATION pi;

 ZeroMemory(&si, sizeof(si));
 si.cb = sizeof(si);
 ZeroMemory(&pi, sizeof(pi));
 LPCSTR BrowLoc = (LPCSTR)buff;

 if (!CreateProcessA(BrowLoc,     // No module name (use command line)
     NULL,
     NULL,           // Process handle not inheritable
     NULL,           // Thread handle not inhberitable
     FALSE,          // Set handle inheritance to FALSE
     0,              // No creation flags
     NULL,           // Use parent's environment block
     NULL,           // Use parent's starting directory 
     &si,            // Pointer to STARTUPINFO structure
     &pi)           // Pointer to PROCESS_INFORMATION structure
     )
 {
     printf("CreateProcess failed (%d).\n", GetLastError());
     getchar();
     return 0;
 }

1 个答案:

答案 0 :(得分:0)

我猜你正在使用unicode。在这种情况下,强制使用AssocQueryString()的多字节字符。

使用以下代码作为前3行。

DWORD size = 1024;
char buff[1024];

 int err = AssocQueryStringA(ASSOCF_INIT_IGNOREUNKNOWN, ASSOCSTR_EXECUTABLE, ".html", NULL, buff, &size);