Win-specific: Watchdog timer in x64 helper

This commit is contained in:
Abs62 2012-02-07 16:49:44 +04:00
parent a02c98d3a1
commit b5eb907d26

View file

@ -12,6 +12,23 @@
typedef void ( *ActivateSpyFn )( BOOL ); typedef void ( *ActivateSpyFn )( BOOL );
HANDLE hGDProcess;
UINT_PTR timerID;
void CALLBACK TimerFunc(HWND hWnd,UINT nMsg,UINT_PTR nTimerID,DWORD dwTime)
{
(void) hWnd;
(void) nMsg;
(void) dwTime;
if( nTimerID == timerID )
{
DWORD wso = WaitForSingleObject( hGDProcess, 0 );
if( wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED )
PostThreadMessage( GetCurrentThreadId(), WM_QUIT, 0, 0 );
}
}
BOOL parentIsGD() BOOL parentIsGD()
{ {
HANDLE hSnapshot, hModuleSnapshot; HANDLE hSnapshot, hModuleSnapshot;
@ -41,6 +58,8 @@ BOOL b;
b = n >= 14 && lstrcmpi( me.szExePath + n - 14, _T("GoldenDict.exe") ) == 0; b = n >= 14 && lstrcmpi( me.szExePath + n - 14, _T("GoldenDict.exe") ) == 0;
} }
CloseHandle( hModuleSnapshot ); CloseHandle( hModuleSnapshot );
if( b )
hGDProcess = OpenProcess( SYNCHRONIZE, FALSE, pe.th32ParentProcessID );
break; break;
} }
b = Process32Next( hSnapshot, &pe ); b = Process32Next( hSnapshot, &pe );
@ -93,6 +112,8 @@ MSG msg;
if( !parentIsGD() ) if( !parentIsGD() )
return -1; return -1;
if( hGDProcess == NULL )
return -1;
while( 1 ) { while( 1 ) {
ThTypes_Init(); ThTypes_Init();
@ -122,17 +143,23 @@ MSG msg;
break; break;
} }
timerID = SetTimer( 0, 0, 1000, TimerFunc );
activateSpyFn( TRUE ); activateSpyFn( TRUE );
while( GetMessage( &msg, 0, 0, 0 ) ) while( GetMessage( &msg, 0, 0, 0 ) )
DispatchMessage( &msg ); DispatchMessage( &msg );
if( timerID )
KillTimer( NULL, timerID);
activateSpyFn( FALSE ); activateSpyFn( FALSE );
ret = 0; ret = 0;
break; break;
} }
CloseHandle( hGDProcess );
if( spyDll ) if( spyDll )
FreeLibrary( spyDll ); FreeLibrary( spyDll );
ThTypes_End(); ThTypes_End();