mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Win-specific: Watchdog timer in x64 helper
This commit is contained in:
parent
a02c98d3a1
commit
b5eb907d26
|
@ -12,6 +12,23 @@
|
|||
|
||||
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()
|
||||
{
|
||||
HANDLE hSnapshot, hModuleSnapshot;
|
||||
|
@ -41,6 +58,8 @@ BOOL b;
|
|||
b = n >= 14 && lstrcmpi( me.szExePath + n - 14, _T("GoldenDict.exe") ) == 0;
|
||||
}
|
||||
CloseHandle( hModuleSnapshot );
|
||||
if( b )
|
||||
hGDProcess = OpenProcess( SYNCHRONIZE, FALSE, pe.th32ParentProcessID );
|
||||
break;
|
||||
}
|
||||
b = Process32Next( hSnapshot, &pe );
|
||||
|
@ -93,6 +112,8 @@ MSG msg;
|
|||
|
||||
if( !parentIsGD() )
|
||||
return -1;
|
||||
if( hGDProcess == NULL )
|
||||
return -1;
|
||||
|
||||
while( 1 ) {
|
||||
ThTypes_Init();
|
||||
|
@ -122,17 +143,23 @@ MSG msg;
|
|||
break;
|
||||
}
|
||||
|
||||
timerID = SetTimer( 0, 0, 1000, TimerFunc );
|
||||
|
||||
activateSpyFn( TRUE );
|
||||
|
||||
while( GetMessage( &msg, 0, 0, 0 ) )
|
||||
DispatchMessage( &msg );
|
||||
|
||||
if( timerID )
|
||||
KillTimer( NULL, timerID);
|
||||
|
||||
activateSpyFn( FALSE );
|
||||
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
CloseHandle( hGDProcess );
|
||||
if( spyDll )
|
||||
FreeLibrary( spyDll );
|
||||
ThTypes_End();
|
||||
|
|
Loading…
Reference in a new issue