diff --git a/client/sources/main_exe.c b/client/sources/main_exe.c index 71e1ecfd..83e4a9df 100644 --- a/client/sources/main_exe.c +++ b/client/sources/main_exe.c @@ -5,6 +5,7 @@ #include #include #include "pupy_load.h" +#include "debug.h" void on_exit_session(void); @@ -12,21 +13,21 @@ static BOOL on_exit_session_called = FALSE; LRESULT CALLBACK WinProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - switch (msg) { - case WM_QUERYENDSESSION: - case WM_CLOSE: - case WM_QUIT: - if (on_exit_session && !on_exit_session_called) { - on_exit_session_called = TRUE; - on_exit_session(); - } - return 1; + switch (msg) { + case WM_QUERYENDSESSION: + case WM_CLOSE: + case WM_QUIT: + if (on_exit_session && !on_exit_session_called) { + on_exit_session_called = TRUE; + on_exit_session(); + } + return 1; - default: - return DefWindowProc (hwnd, msg, wParam, lParam); - } + default: + return DefWindowProc (hwnd, msg, wParam, lParam); + } - return 0; + return 0; } int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, @@ -35,43 +36,56 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, MSG msg; BOOL bRet; WNDCLASS wc; - HWND hwndMain; - HINSTANCE hinst; - HANDLE hThread; - DWORD threadId; - DWORD dwWake; - WNDCLASSEX wx; - static const char class_name[] = "DUMMY"; + HWND hwndMain; + HINSTANCE hinst; + HANDLE hThread; + DWORD threadId; + DWORD dwWake; + WNDCLASSEX wx; + static const char class_name[] = "DUMMY"; #ifdef DEBUG - AttachConsole(-1); + AttachConsole(-1); #endif - ZeroMemory(&wx, sizeof(WNDCLASSEX)); + ZeroMemory(&wx, sizeof(WNDCLASSEX)); - wx.cbSize = sizeof(WNDCLASSEX); - wx.lpfnWndProc = WinProc; - wx.hInstance = hInstance; - wx.lpszClassName = class_name; - if ( ! RegisterClassEx(&wx) ) - return -1; + wx.cbSize = sizeof(WNDCLASSEX); + wx.lpfnWndProc = WinProc; + wx.hInstance = hInstance; + wx.lpszClassName = class_name; - hwndMain = CreateWindowEx( - 0, - class_name, - NULL, - 0, 0, 0, 0, 0, - NULL, NULL, NULL, NULL - ); + if ( ! RegisterClassEx(&wx) ) { + dprint("RegisterClassEx failed: %d\n", GetLastError()); + return -1; + } - hThread = CreateThread( - NULL, - 0, - mainThread, - NULL, - 0, - &threadId - ); + hwndMain = CreateWindowEx( + 0, + class_name, + NULL, + 0, 0, 0, 0, 0, + NULL, NULL, NULL, NULL + ); + + if (!hwndMain) { + dprint("CreateWindowEx failed: %d\n", GetLastError()); + return -2; + } + + hThread = CreateThread( + NULL, + 0, + mainThread, + NULL, + 0, + &threadId + ); + + if (!hThread) { + dprint("CreateThread failed: %d\n", GetLastError()); + return -GetLastError(); + } for (;;) { dwWake = MsgWaitForMultipleObjects( @@ -80,11 +94,11 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, FALSE, INFINITE, QS_ALLINPUT - ); + ); switch (dwWake) { case WAIT_FAILED: - return -1; + return -3; case WAIT_TIMEOUT: continue; @@ -99,7 +113,7 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } break; } - } + } - return 0; + return 0; }