CreateProcess异常(kernel32.lib)

use*_*392 0 c c++ winapi win32-process

我运行此代码时遇到异常:

STARTUPINFO si;
PROCESS_INFORMATION pi;

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

CreateProcess(NULL, L"program.dat", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles. 
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
Run Code Online (Sandbox Code Playgroud)

我在WaitForSingleObject上得到了异常.

谢谢 :)

Abh*_*eet 6

很明显,可以在文档中说明 ::

此函数的Unicode版本CreateProcessW可以修改此字符串的内容.因此,此参数不能是只读内存的指针(例如const变量或文字字符串).如果此参数是常量字符串,则该函数可能会导致访问冲突.

你的L"program.dat"属于这条规则.将字符串复制到某个WCHAR变量中并传递它.