데스크톱 Windows에서는에서 SetUnhandledExceptionFilter
기능을 사용할 수 windows.h
있지만 WinCE에서는 작동하지 않습니다. WinCE에서 처리되지 않은 예외를 어떻게 잡을 수 있습니까?
참고 : .NET이 아닌 C ++를 사용하고 있습니다.
지금까지 찾은 유일한 방법은 응용 프로그램의 모든 단일 스레드 실행을 다음과 같이 래핑하는 것입니다.
__try
{
// Call the thread start function here
}
__except(MyExceptionFilter(GetExceptionInformation())
{
// Handle the exception here
}
이것은 많은 작업처럼 들리지만 다음과 같이 스레드를 래핑하는 함수를 작성하면 비교적 쉽습니다.
typedef struct {
void* startFct;
void* args;
} ThreadHookArgs;
// "params" contains an heap-allocated instance of ThreadHookArgs
// with the wrapped thread start function and its arguments.
DWORD WINAPI wrapThread(LPVOID params) {
ThreadHookArgs threadParams;
memcpy(&args, params, sizeof(ThreadHookArgs));
// Delete the parameters, now we have a copy of them
delete params;
__try {
// Execute the thread start function
return ((LPTHREAD_START_ROUTINE) threadParams.startFct) (threadParams.args);
}
__except(MyExceptionFilter(GetExceptionInformation())
{
// Handle the exception here
return EXIT_FAILURE;
}
}
그런 다음 스레드 시작 함수 대신 후크를 호출하는 자체 스레드 생성 함수를 작성합니다.
// Drop-in replacement for CreateThread(), executes the given
// start function in a SEH exception handler
HANDLE MyCreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId)
{
HANDLE hThread;
DWORD dwThreadId;
LPTHREAD_START_ROUTINE startFct = lpStartAddress;
LPVOID startParam = lpParameter;
// Allocate the hook function arguments on the heap.
// The function will delete them when it runs.
ThreadHookArgs* hookArgs = new ThreadHookArgs;
hookArgs->fct = lpStartAddress;
hookArgs->args = lpParameter;
// Set the start function of the created thread to
// our exception handler hook function
startFct = (LPTHREAD_START_ROUTINE) &wrapThread;
startParam = hookArgs;
// Start the hook function, which will in turn execute
// the desired thread start function
hThread = CreateThread( lpThreadAttributes,
dwStackSize,
startFct,
startParam,
dwCreationFlags,
&dwThreadId );
return hThread;
}
Windows CE 6 이상을 사용하는 경우 해당 버전에는 벡터 예외 처리 기능이 있으므로 훨씬 더 쉽게 처리 할 수 있습니다.
http://msdn.microsoft.com/en-us/library/ee488606%28v=winembedded.60%29.aspx
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다