我在 dll 中有这个函数:
int createChildProcess()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
int res;
si.cb=sizeof(STARTUPINFO);
STARTUPINFO* ptr=&si;
if(!CreateProcess(L"c:\\windows\\notepad.exe", NULL, 0, 0, false, CREATE_NEW_CONSOLE, 0, 0, &si, &pi))
{
mylog << "CreateProcess error: " << GetLastError() << std::endl;
res = 0;
}
else
res = pi.dwProcessId;
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return res;
}
我发现了2个问题:
1)函数第一次调用,总是返回错误码87(参数不正确)。
2)第二次,函数工作,但是创建了一个处于挂起状态的子进程,并且父进程的cpu使用率达到100%。
我用winXP sp3测试,我的dll是在vs 2010中编译的。
有什么帮助吗?