📄 cguardedthreadhandler.h
字号:
//
// FILE: CGuardedThreadHandler.h
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////
#ifndef __CGuardedThreadHandler__
#define __CGuardedThreadHandler__
#include <CMclGlobal.h>
#include <CMclThread.h>
class CGuardedThreadHandler : public CMclThreadHandler
{
public:
// Thread handlers derived from CGuardedThreadHandler
// must override GuardedThreadHandlerProc to implement
// their main thread procedure.
//
virtual unsigned GuardedThreadHandlerProc( void ) = 0;
// The default implementation of ExceptionFilter will just return
// EXCEPTION_EXECUTE_HANDLER. If a thread handler overrides
// the default exception filter function, returning
// EXCEPTION_EXECUTE_HANDLER will cause the thread to be silently
// exited without passing the exception up to the process
// unhandled exception filter.
//
virtual int ExceptionFilter( DWORD dwExceptionCode, LPEXCEPTION_POINTERS pEP )
{
return(EXCEPTION_EXECUTE_HANDLER);
}
// The default implementation of TerminationHandler will just return
// the exception code, which is used as the thread exit code for the
// thread. Override this function to handle termination differently
// before the thread is exited.
//
virtual unsigned TerminationHandler( DWORD dwExceptionCode )
{
return(dwExceptionCode);
}
private:
virtual unsigned ThreadHandlerProc( void )
{
unsigned wExitCode;
DWORD dwExceptionCode;
__try {
// The real work for this thread is done here, within a guarded
// body.
//
wExitCode = GuardedThreadHandlerProc();
}
__except( ExceptionFilter(dwExceptionCode = GetExceptionCode(), GetExceptionInformation()) ) {
// If the exception filter evaluates to EXCEPTION_EXECUTE_HANDLER,
// this handler will cause a return from ThreadHandlerProc with a
// thread exit code code equal to the return value of the
// virtual TerminationHandler function.
//
wExitCode = TerminationHandler(dwExceptionCode);
}
return(wExitCode);
}
};
#endif // __CGuardedThreadHandler__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -