我正在使用这段代码来启动我的程序
int _tmain(int argc, _TCHAR* argv[])
{
STARTUPINFO cif;
ZeroMemory(&cif,sizeof(STARTUPINFO));
PROCESS_INFORMATION pi;
if (CreateProcess(L"C:\\test\\test.exe",NULL,
NULL,NULL,FALSE,CREATE_UNICODE_ENVIRONMENT,NULL,NULL,&cif,&pi)==TRUE)
{
cout << "process" << endl;
cout << "handle " << pi.hProcess << endl;
}
system("pause");
return 0;
}程序正常启动,但立即失败(无响应并失败)。CreateProcess返回true。当我不从代码启动test.exe时,它可以正常工作。
发布于 2011-11-03 03:05:57
您必须将STARTUPINFO和PROCESS_INFORMATION的内存清零,并且必须设置STARTUPINFO结构的cb字段。
复制sample code in the Microsoft documentation是一个很好的起点。
发布于 2011-11-03 22:54:45
我发现问题是我没有为test.exe设置目录(CreateProcess中的第8个参数)。感谢所有人
https://stackoverflow.com/questions/7984428
复制相似问题