本文整理汇总了C++中WaitForInputIdle函数的典型用法代码示例。如果您正苦于以下问题:C++ WaitForInputIdle函数的具体用法?C++ WaitForInputIdle怎么用?C++ WaitForInputIdle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WaitForInputIdle函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_free
Process::ProcessImpl::ProcessImpl(const std::string& cmd, const std::vector<std::string>& argv) :
m_free(false)
{
std::string args;
for (unsigned int i = 0; i < argv.size(); ++i) {
args += argv[i];
if (i + 1 < argv.size())
args += ' ';
}
ZeroMemory(&m_startup_info, sizeof(STARTUPINFO));
m_startup_info.cb = sizeof(STARTUPINFO);
ZeroMemory(&m_process_info, sizeof(PROCESS_INFORMATION));
if (!CreateProcess(const_cast<char*>(cmd.c_str()), const_cast<char*>(args.c_str()), 0, 0, false,
CREATE_NO_WINDOW, 0, 0, &m_startup_info, &m_process_info)) {
std::string err_str;
DWORD err = GetLastError();
DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM;
LPSTR buf;
if (FormatMessageA(flags, 0, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buf, 0, 0)) {
err_str += buf;
LocalFree(buf);
}
throw std::runtime_error("Process::Process : Failed to create child process. Windows error was: \"" + err_str + "\"");
}
WaitForInputIdle(m_process_info.hProcess, 1000); // wait for process to finish setting up, or for 1 sec, which ever comes first
}
示例2: WaitForInputIdle
STDMETHODIMP CShellExt::SendToWindow(HANDLE hProcess, LPCSTR pszText)
{
//Wait for the process to be ready to accept input
WaitForInputIdle(hProcess, INFINITE);
CSendKeys sk;
sk.SendKeys(pszText);
return NOERROR;
}
示例3: WaitForInputIdle
WaitResult System::WaitInputIdle( const HProcess & hProcess, UInt iMilliseconds ) const
{
DWord dwResult = WaitForInputIdle( hProcess.m_hThreadingObject, (DWord)iMilliseconds );
if ( dwResult == 0 )
return WAIT_OK;
if ( dwResult == WAIT_TIMEOUT )
return WAIT_EXPIRED;
return WAIT_ERROR;
}
示例4: ErrorBox
//通过匿名管道连接引擎引擎
bool CEngine::LinkEngineWithUnnamed()
{
status = 0;//引擎连接未就绪
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor=NULL;//Default security attributes
sa.bInheritHandle= TRUE;//handle can be inherited
if(!CreatePipe(&pde.engine_read,&pde.platform_write,&sa,BUFSIZE) ||!CreatePipe(&pde.platform_read,&pde.engine_write,&sa,BUFSIZE))//创建两个平台与引擎之间互相通信的匿名管道
{
ErrorBox("CreatePipe failed");
return false;
}
char Filter[]="(exe files)|*.exe|(all files)|*.*||";//文件滤镜
CFileDialog FileName(true,NULL,NULL,Filter,NULL,gameSet.EngineInitDir);//定义文件对话框类实例
if(FileName.DoModal()==IDOK)
{
path=FileName.GetFilePath();
LPCTSTR folder=FileName.GetFolderPath(path);
char EngineDir[MAX_PATH]={0};
strcpy(EngineDir,folder);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si,sizeof(si));
si.cb=sizeof(si);
si.dwFlags=STARTF_USESHOWWINDOW |STARTF_USESTDHANDLES;
si.wShowWindow=SW_HIDE;
si.hStdInput=pde.engine_read;
si.hStdOutput=pde.engine_write;
si.hStdError=pde.engine_write;
if(!CreateProcess(path,"",NULL,NULL,true,0,NULL,EngineDir,&si,&pi))//打开引擎进程
{
ErrorBox("CreateProcess failed");
status = -1;
return false;
}
CloseHandle(pde.engine_read);
CloseHandle(pde.engine_write);
WaitForInputIdle(pi.hProcess,INFINITE);
pde.hEProcess = pi.hProcess;
CloseHandle(pi.hThread);
SetCurrentDirectory(gameSet.CurDir);//恢复当前主应用程序的进程
CreateEngineInfoBoard();
}
else
{
status = -1;
return false;
}
return true;
}
示例5: cleanCommandLine
bool CCommonAppUtils::LaunchApplication
( const CString& sCommandLine
, UINT idErrMessageFormat
, bool bWaitForStartup
, bool bWaitForExit
, HANDLE hWaitHandle)
{
PROCESS_INFORMATION process;
// make sure we get a writable copy of the command line
size_t bufferLen = sCommandLine.GetLength()+1;
std::unique_ptr<TCHAR[]> cleanCommandLine (new TCHAR[bufferLen]);
memcpy (cleanCommandLine.get(),
(LPCTSTR)sCommandLine,
sizeof (TCHAR) * bufferLen);
if (!CCreateProcessHelper::CreateProcess(NULL, cleanCommandLine.get(), sOrigCWD, &process))
{
if(idErrMessageFormat != 0)
{
CFormatMessageWrapper errorDetails;
CString msg;
msg.Format(idErrMessageFormat, (LPCTSTR)errorDetails);
CString title;
title.LoadString(IDS_APPNAME);
MessageBox(NULL, msg, title, MB_OK | MB_ICONINFORMATION);
}
return false;
}
AllowSetForegroundWindow(process.dwProcessId);
if (bWaitForStartup)
WaitForInputIdle(process.hProcess, 10000);
if (bWaitForExit)
{
DWORD count = 1;
HANDLE handles[2];
handles[0] = process.hProcess;
if (hWaitHandle)
{
count = 2;
handles[1] = hWaitHandle;
}
WaitForMultipleObjects(count, handles, FALSE, INFINITE);
if (hWaitHandle)
CloseHandle(hWaitHandle);
}
CloseHandle(process.hThread);
CloseHandle(process.hProcess);
return true;
}
示例6: edit
int ActivePet::launch(std::wstring exePath, std::wstring originalDocPath){
wchar_t commandLine[4096] = { '\0' };
if (originalDocPath != L"") {
// Build the command line.
std::wstring editableDocPath = edit(originalDocPath);
wcscat(commandLine, L"\"");
wcscat(commandLine, exePath.c_str());
wcscat(commandLine, L"\" \"");
wcscat(commandLine, editableDocPath.c_str());
wcscat(commandLine, L"\"");
}
auto_close<void*, &::DestroyEnvironmentBlock> environment(NULL);
if (!CreateEnvironmentBlock(&environment, m_session.get(), FALSE)) {
printf("CreateEnvironmentBlock() failed: %d", GetLastError());
return -30;
}
STARTUPINFO si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi = {};
if (!CreateProcessAsUser(m_session.get(),
exePath.c_str(),
commandLine,
NULL,
NULL,
FALSE,
CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE,
environment.get(),
NULL, // lpCurrentDirectory,
&si,
&pi)) {
printf("CreateProcessAsUser() failed: %d", GetLastError());
return -30;
}
if (!AssignProcessToJobObject(m_job.get(), pi.hProcess)) {
printf("AssignProcessToJobObject() failed: %d", GetLastError());
return -30;
}
if (!ResumeThread(pi.hThread)) {
printf("ResumeThread() failed: %d", GetLastError());
return -30;
}
if (WaitForInputIdle(pi.hProcess, INFINITE) != ERROR_SUCCESS) {
printf("WaitForInputIdle() failed: %d", GetLastError());
return -30;
}
InjectAndCall(pi.hProcess, "ApplyHooks", 10000);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
示例7: ExecuteTarget
STATIC int ExecuteTarget(LPTSTR lpCmdLine)
{
HWND hWnd = NULL;
// DWORD dwExitCode = ERROR_SUCCESS;
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { sizeof(STARTUPINFO), 0 };
/* Execute the process */
if (CreateProcess(
NULL, /* No module name (use command line) */
lpCmdLine, /* Command line */
NULL, /* Process handle not inheritable */
NULL, /* Thread handle not inheritable */
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 */
)) {
DWORD dwProcessId = 0;
/* Wait until target executable has finished its initialization */
WaitForInputIdle(pi.hProcess, INFINITE);
/* Find target executable window */
hWnd = GetTopWindow(0);
while(hWnd != NULL) {
GetWindowThreadProcessId(hWnd, &dwProcessId);
if (dwProcessId == pi.dwProcessId) {
/* And move it to the top. */
SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
break;
}
hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);
}
/* Wait until target executable exits. */
// Nah
//WaitForSingleObject(pi.hProcess, INFINITE);
//GetExitCodeProcess(pi.hProcess, &dwExitCode);
/* Close process and thread handles. */
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
} else {
FatalError(ERROR_SUCCESS, _T("Failed to execute cmdline: %s"), lpCmdLine);
xfree(lpCmdLine);
}
return ERROR_SUCCESS;
}
示例8: launch_putty
HWND launch_putty(int action, char *path)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD wait;
HWND pwin;
struct process_record *pr;
char buf[BUFSIZE];
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
sprintf(buf, "%s -%s \"%s\"", config->putty_path,
action ? "edit" : "load", path);
if (!CreateProcess(config->putty_path, buf, NULL, NULL,
FALSE, 0, NULL, NULL, &si, &pi))
return NULL;
wait = WaitForInputIdle(pi.hProcess, LAUNCH_TIMEOUT);
if (wait != 0) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return NULL;
};
CloseHandle(pi.hThread);
pwin = NULL;
EnumThreadWindows(pi.dwThreadId, FindPuttyWindowCallback, (LPARAM) &pwin);
if (!pwin) {
CloseHandle(pi.hProcess);
return NULL;
};
pr = (struct process_record *) malloc(sizeof(struct process_record));
pr->pid = pi.dwProcessId;
pr->tid = pi.dwThreadId;
pr->hprocess = pi.hProcess;
pr->window = pwin;
pr->path = dupstr(path);
item_insert((void *) &process_handles, &nprocesses, pi.hProcess);
nprocesses -= 1;
item_insert((void *) &process_records, &nprocesses, pr);
return pwin;
};
示例9: ASSERT
void StartupRunner::_SpawnProcess(LPTSTR ptzCommandLine, DWORD dwFlags)
{
ASSERT(!(dwFlags & ERK_WAITFOR_QUIT && dwFlags & ERK_WAITFOR_IDLE));
//
// The following cases need to be supported:
//
// 1. "C:\Program Files\App\App.exe" -params
// 2. C:\Program Files\App\App.exe -params
// 3. App.exe -params (App.exe is in %path% or HKLM->REGSTR_PATH_APPPATHS)
// and all the above cases without arguments.
//
// Note that 'App.exe' may contain spaces too
//
// CreateProcess handles 1 and 2, ShellExecuteEx handles 1 and 3.
// So if the first token doesn't contain path characters (':' or '\')
// ShellExecuteEx is used. That's really ugly but it *should* work.
//
TCHAR tzToken[MAX_LINE_LENGTH] = { 0 };
LPCTSTR ptzArgs = NULL;
GetToken(ptzCommandLine, tzToken, &ptzArgs, FALSE);
HANDLE hProcess = NULL;
if (strchr(tzToken, _T('\\')) || strchr(tzToken, _T(':')))
{
hProcess = _CreateProcess(ptzCommandLine);
}
else
{
hProcess = _ShellExecuteEx(tzToken, ptzArgs);
}
if (hProcess != NULL)
{
if (dwFlags & ERK_WAITFOR_QUIT)
{
WaitForSingleObject(hProcess, INFINITE);
}
else if (dwFlags & ERK_WAITFOR_IDLE)
{
WaitForInputIdle(hProcess, INFINITE);
}
CloseHandle(hProcess);
}
else
{
TRACE("StartupRunner failed to launch '%s'", ptzCommandLine);
}
}
示例10: DoDelay
//---------------------------------------------------------------------------
//do inter-key delay
void TPushKeys::DoKeyDelay()
{
if (Process==NULL)
{
//timed delay
DoDelay(KeyDelayValue);
}
else //wait for input buffer to empty from process passed to onpus event
{
WaitForInputIdle(Process,ProcessWait);
}
}
示例11: _IL_Process_WaitForInputIdle
/*
* private static bool WaitForInputIdle(IntPtr processHandle,
* int processID, int milliseconds);
*/
ILBool _IL_Process_WaitForInputIdle(ILExecThread *_thread,
ILNativeInt processHandle,
ILInt32 processID,
ILInt32 milliseconds)
{
#ifdef IL_WIN32_PLATFORM
return WaitForInputIdle((HANDLE)processHandle, (DWORD)milliseconds);
#else
/* "Idle" has no meaning on non-Win32 platforms so just pretend
that the process is fully initialized and ready to go */
return 1;
#endif
}
示例12: OpenProcess
bool CWSWindow::GetWindowFromProcID()
{
m_hWnd = NULL;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, TRUE, m_dwProcID);
if (hProc == NULL)
{
LOG_WS_ERROR(_T("OpenProcess failed"));
return false;
}
WaitForInputIdle(hProc, INFINITE);
EnumWindows(&EnumWindowsProc, reinterpret_cast<LPARAM>(this));
return (m_hWnd != NULL);
}
示例13: ExtractLinks
static int ExtractLinks()
{
static WCHAR szNotepad[16];
PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {sizeof(STARTUPINFO)};
lstrcpy(szNotepad, L"Notepad.exe");
GetStartupInfo(&si);
if(!CreateProcess(0, szNotepad, 0, 0, 0, 0, 0, 0, &si, &pi))
return 0;
WaitForInputIdle(pi.hProcess, INFINITE);
EnumThreadWindows(pi.dwThreadId, NotepadMainWndFindProc, 0);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;
}
示例14: StartExplorer
BOOL StartExplorer(DWORD timeout, NS_UNUSED BOOL kill)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
TCHAR shellpath[MAX_PATH];
OutputDebugString(_T("nsRE::StartExplorer"));
if (FindWindow(SHELLWND, NULL))
NS_FAILED(NULL, _T("Explorer already running"));
GetWindowsDirectory(shellpath, MAX_PATH - 1);
shellpath[MAX_PATH - 1] = 0;
_tcsncat(shellpath, SHELL, MAX_PATH - 1);
shellpath[MAX_PATH - 1] = 0;
FakeStartupIsDone();
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
if(!CreateProcess(NULL, /* No module name (use command line) */
shellpath, /* Command line */
NULL, /* Process handle not inheritable */
NULL, /* Thread handle not inheritable */
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 */
NS_FAILED(NULL, _T("Cannot spawn explorer process"));
switch (WaitForInputIdle(pi.hProcess, timeout))
{
case 0 : break; /* OK */
case WAIT_TIMEOUT :
if (timeout == IGNORE) break; /* OK as requested */
NS_FAILED(pi.hProcess, _T("Timeout while waiting for explorer process"));
case WAIT_FAILED : NS_FAILED(pi.hProcess, _T("Error while waiting for explorer process"));
default : NS_FAILED(pi.hProcess, _T("This should not be reached"));
}
return TRUE;
}
示例15: InitDbgConsole
void InitDbgConsole()
{
WCHAR CommandLine[200];
STARTUPINFO siStartInfo;
//定义一个用于产生子进程的PROCESS_INFORMATION结构体 (定义见CreateProcess,函数说明)
PROCESS_INFORMATION piProcInfo;
SECURITY_ATTRIBUTES sec_att;
sec_att.bInheritHandle = TRUE;
sec_att.lpSecurityDescriptor = NULL;
sec_att.nLength = sizeof(SECURITY_ATTRIBUTES);
if (!CreatePipe(&hRead, &hWrite,&sec_att, 0))
return;
HANDLE hCurrentProcess;
DuplicateHandle(GetCurrentProcess(),GetCurrentProcess(),GetCurrentProcess(),&hCurrentProcess, 0, TRUE, DUPLICATE_SAME_ACCESS);
wsprintfW(CommandLine,L"DbgDisplay.exe %d %d",hRead,hCurrentProcess);
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.wShowWindow=TRUE;//此成员设为TRUE的话则显示新建进程的主窗口
siStartInfo.dwFlags |= STARTF_USESHOWWINDOW;
/*siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
siStartInfo.hStdOutput = 0; //意思是:子进程的stdout输出到hStdOutWrite
siStartInfo.hStdError = 0; //意思是:子进程的stderr输出到hStdErrWrite
siStartInfo.hStdInput = hRead; */
// 产生子进程,具体参数说明见CreateProcess函数
int bSuccess = CreateProcess(NULL,
CommandLine, // 子进程的命令行
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
CREATE_NEW_CONSOLE, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
//如果失败,退出
if (!bSuccess )
return;
WaitForInputIdle(piProcInfo.hProcess,100);
}