DWORD WINAPI _threadCheckState(LPVOID lpParameter)
{

	CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"进入监控线程");

	HWND hMainFrame = (*(HWND*)(lpParameter));

	DWORD dwMainProcessId = 0;
	::GetWindowThreadProcessId(hMainFrame, &dwMainProcessId);

	HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwMainProcessId);
	if (hProcess == NULL)
	{
		CleanHistory();
		::TerminateProcess(::GetCurrentProcess(), 1);
	}

	HANDLE _hMainProcessMutex = NULL;
	DWORD dwExitCode = 0;
	while(1)
	{
		LPCTSTR lpszProcessMutex = _T("_Moneyhub_{878B413D-D8FF-49e7-808D-9A9E6DDCF2B6}");
		_hMainProcessMutex  = OpenMutexW(NULL, TRUE, lpszProcessMutex);

		DWORD err = GetLastError();
		if(_hMainProcessMutex != NULL)
			::CloseHandle(_hMainProcessMutex);

		// 当内核对象已经存在或者禁止进入时,说明主框架进程还在
		if (err == ERROR_ALREADY_EXISTS || err == ERROR_ACCESS_DENIED)
		{
			Sleep(1300);
		}
		else // 如果主框架进程被杀了
		{
			CRecordProgram::GetInstance()->RecordCommonInfo(MY_PRO_NAME, MY_THREAD_ID_INIT, L"监控线程关闭内核进程");
			CleanHistory();
			::TerminateProcess(::GetCurrentProcess(), 1);
		}
	}


	return 0;
}
Exemple #2
0
INT CommandHistory (LPTSTR param)
{
	LPTSTR tmp;
	INT tmp_int;
	LPHIST_ENTRY h_tmp;
	TCHAR szBuffer[2048];

	tmp=_tcschr(param,_T('/'));

	if (tmp)
	{
		param=tmp;
		switch (_totupper(param[1]))
		{
			case _T('F'):/*delete history*/
				CleanHistory();InitHistory();
				break;

			case _T('R'):/*read history from standard in*/
				//hIn=GetStdHandle (STD_INPUT_HANDLE);

				for(;;)
				{
					ConInString(szBuffer,sizeof(szBuffer)/sizeof(TCHAR));
					if (*szBuffer!=_T('\0'))
						History(0,szBuffer);
					else
						break;
				}
				break;

			case _T('A'):/*add an antry*/
				History(0,param+2);
				break;

			case _T('S'):/*set history size*/
				if ((tmp_int=_ttoi(param+2)))
					set_size(tmp_int);
				break;

			default:
				return 1;
		}
	}
	else
	{
		for (h_tmp = Top->prev; h_tmp != Bottom; h_tmp = h_tmp->prev)
			ConErrPuts(h_tmp->string);
	}
	return 0;
}