/* function opens an existing process using its id */ BOOL Process::Open(DWORD _id) { /* buffering variable */ HANDLE lhProcess = OpenProcess(PROCESS_ALL_ACCESS, false, _id); if (lhProcess != nullptr) { if (hProcess != nullptr) Destroy(); hProcess = lhProcess; hThread = GetThreadByID(_id); /* register new 'exit' callback for new process */ RegisterExitCallback(exitCallback); /* get the command line of the process */ szCmdLine = GetCommandLine(hProcess); id = _id; /* call 'process started' */ OnStarted(); return TRUE; } return FALSE; }
/* function creates new process using command line */ BOOL Process::Create(TCHAR * _szCmdLine) { STARTUPINFOA si = { sizeof(STARTUPINFOA) }; PROCESS_INFORMATION pi; BOOL bProcessCreated = CreateProcess( NULL, // No module name (use command line) _szCmdLine, // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE CREATE_NO_WINDOW, // Process 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 if (bProcessCreated) { hProcess = pi.hProcess; // Save the process handle hThread = pi.hThread; // Save the thread handle id = pi.dwProcessId; // Save the process id szCmdLine = GetCommandLine(hProcess); /* calls 'process started' */ OnStarted(); } return bProcessCreated; }
void Application::Launch() { ShowWindow(mHWnd, SW_SHOW); mLog->Out("Application launched!"); OnStarted(); onStarted.Invoke(); o2Events.OnApplicationStarted(); MSG msg; memset(&msg, 0, sizeof(msg)); //mTimer->Reset(); while (msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { ProcessFrame(); } } o2Events.OnApplicationClosing(); OnClosing(); onClosing.Invoke(); }
bool App::Start() { if(m_isRunning) return false; SetCurrent(); m_isRunning = OnStart(); if(m_isRunning) { m_startTimeMS = getRunTimeMS(); //- TODO: Determine if this is bad to have by default - srand((unsigned int)time(NULL)); OnStarted(); } return m_isRunning; }
BOOL CService::Begin(LPTSTR serviceName) { if(!serviceName) return FALSE; // StartServiceCtrlDispatcher에서 등록할 서비스 환경 정보 SERVICE_TABLE_ENTRY DispatchTable[] = { {serviceName, ::RunCallback}, {NULL, NULL} }; _tcscpy(mServiceName, serviceName); OnStarted(); if(!StartServiceCtrlDispatcher(DispatchTable)) { // 실패 일때 _tprintf(_T("## Debug Console mode ##\n")); getchar(); } return TRUE; }