#define STRICT #define WIN32_LEAN_AND_MEAN #include #include #include #include "launcher.h" KLauncher:: KLauncher() { // Important, don't forget this initialisation block. ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); // This member must be set to NULL before passing the // structure to CreateProcess.(MSDN). si.lpReserved = NULL; ZeroMemory( &pi, sizeof(pi) ); szAppName = new TCHAR[255]; szCurrentDirectory = new TCHAR[255]; //StringCchCopy(szAppName, (size_t)255, L"c:\\Temp\\dumb.exe"); //StringCchCopy(szCurrentDirectory, (size_t)255, L"c:\\Temp\\"); StringCchCopy(szAppName, (size_t)255, L"c:\\Windows\\System32\\notepad.exe"); StringCchCopy(szCurrentDirectory, (size_t)255, L"c:\\"); } KLauncher:: ~KLauncher() { delete szAppName; delete szCurrentDirectory; } DWORD KLauncher:: GetThreadId(void) { return pi.dwThreadId; } bool KLauncher:: LaunchApp() { BOOL b_ret; DWORD dw_ret; b_ret = CreateProcess( szAppName, NULL, NULL, NULL, FALSE, 0, NULL, szCurrentDirectory, &si, &pi ); if(b_ret == 0) return false; #ifdef KDEBUG e_win.Test(b_ret, __FILE__, __LINE__, "CreateProcess"); #endif // Wait for the target process to initialise. dw_ret = WaitForInputIdle( pi.hProcess, INFINITE ); if(dw_ret == 0) return true; else return false; #ifdef KDEBUG if(dw_ret == WAIT_TIMEOUT) { e_win.SetErrString("WaitForInputIdle returned WAIT_TIMEOUT.\n \ The wait was terminated because the time-out interval elapsed."); throw e_win; } else if(dw_ret == WAIT_FAILED) { e_win.Test(false, __FILE__, __LINE__, "WaitForInputIdle"); } #endif }