Use structured exception handling.
This commit is contained in:
parent
e0131ac18b
commit
8eba258624
@ -30,7 +30,7 @@
|
||||
#define VER_LAMEXP_MINOR_LO 3
|
||||
#define VER_LAMEXP_TYPE Alpha
|
||||
#define VER_LAMEXP_PATCH 1
|
||||
#define VER_LAMEXP_BUILD 580
|
||||
#define VER_LAMEXP_BUILD 582
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Tools versions
|
||||
|
@ -572,12 +572,28 @@ lamexp_cpu_t lamexp_detect_cpu_features(void)
|
||||
return features;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for debugger (detect routine)
|
||||
*/
|
||||
static bool lamexp_check_for_debugger(void)
|
||||
{
|
||||
__try
|
||||
{
|
||||
DebugBreak();
|
||||
}
|
||||
__except(GetExceptionCode() == EXCEPTION_BREAKPOINT ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for debugger (thread proc)
|
||||
*/
|
||||
static void WINAPI lamexp_debug_thread_proc(__in LPVOID lpParameter)
|
||||
{
|
||||
while(!IsDebuggerPresent())
|
||||
while(!(IsDebuggerPresent() || lamexp_check_for_debugger()))
|
||||
{
|
||||
Sleep(333);
|
||||
}
|
||||
@ -589,11 +605,12 @@ static void WINAPI lamexp_debug_thread_proc(__in LPVOID lpParameter)
|
||||
*/
|
||||
static HANDLE lamexp_debug_thread_init(void)
|
||||
{
|
||||
if(IsDebuggerPresent())
|
||||
if(IsDebuggerPresent() || lamexp_check_for_debugger())
|
||||
{
|
||||
FatalAppExit(0, L"Not a debug build. Please unload debugger and try again!");
|
||||
TerminateProcess(GetCurrentProcess(), -1);
|
||||
}
|
||||
|
||||
return CreateThread(NULL, NULL, reinterpret_cast<LPTHREAD_START_ROUTINE>(&lamexp_debug_thread_proc), NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
|
37
src/Main.cpp
37
src/Main.cpp
@ -43,7 +43,7 @@
|
||||
// Main function
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int lamexp_main(int argc, char* argv[])
|
||||
static int lamexp_main(int argc, char* argv[])
|
||||
{
|
||||
int iResult = -1;
|
||||
bool bAccepted = true;
|
||||
@ -181,7 +181,7 @@ int lamexp_main(int argc, char* argv[])
|
||||
// Applicaton entry point
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
static int _main(int argc, char* argv[])
|
||||
{
|
||||
if(LAMEXP_DEBUG)
|
||||
{
|
||||
@ -194,7 +194,6 @@ int main(int argc, char* argv[])
|
||||
else
|
||||
{
|
||||
int iResult = -1;
|
||||
SetUnhandledExceptionFilter(lamexp_exception_handler);
|
||||
try
|
||||
{
|
||||
qInstallMsgHandler(lamexp_message_handler);
|
||||
@ -229,11 +228,35 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
void __declspec(dllexport) __stdcall Test(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
||||
if(LAMEXP_DEBUG)
|
||||
{
|
||||
OutputDebugStringA(lpszCmdLine);
|
||||
MessageBoxA(0, lpszCmdLine, "LameXP is here!", MB_ICONINFORMATION);
|
||||
return _main(argc, argv);
|
||||
}
|
||||
else
|
||||
{
|
||||
__try
|
||||
{
|
||||
SetUnhandledExceptionFilter(lamexp_exception_handler);
|
||||
return _main(argc, argv);
|
||||
}
|
||||
__except(1)
|
||||
{
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
fprintf(stderr, "\nGURU MEDITATION !!!\n");
|
||||
FatalAppExit(0, L"Unhandeled exception error, application will exit!");
|
||||
TerminateProcess(GetCurrentProcess(), -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//extern "C"
|
||||
//{
|
||||
// void __declspec(dllexport) __stdcall Test(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
||||
// {
|
||||
// OutputDebugStringA(lpszCmdLine);
|
||||
// MessageBoxA(0, lpszCmdLine, "LameXP is here!", MB_ICONINFORMATION);
|
||||
// }
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user