为何我用CreateProcessW()方式运行C:\db\bin\mysqld --init-file=C:\db\my.ini会出现创建线程失败?
执行函数如下:
CString ExecuteCommandLine(CString strCmdLine)
{
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if (!CreatePipe(&hRead,&hWrite,&sa,0)) {
MessageBox(_T("Error On CreatePipe()"));
return _T("");
}
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdInput=NULL;
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
if (!CreateProcessW(NULL,strCmdLine.GetBuffer(),
NULL,NULL,TRUE,REALTIME_PRIORITY_CLASS,NULL,NULL,&si,&pi)) {
MessageBox(_T("Error on CreateProcess()"));
return _T("");
}
CloseHandle(hWrite);
char buffer[4096] = {0};
CString strBuffer;
DWORD bytesRead = 0;
do{
bytesRead = 0;
memset(buffer, 0, sizeof(buffer));
ReadFile(hRead,buffer,4096,&bytesRead,NULL);
strBuffer += buffer;
}while( bytesRead == 4096);
// Wait until child processes exit.
WaitForSingleObject( pi.hProcess, 0 );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return strBuffer;
}
------解决方案--------------------
这是创建进程,不是创建线程。。。。。
最好去MFC版面问。