diff --git a/Descent3/winmain.cpp b/Descent3/winmain.cpp index e7a3b73e..e14ac2d6 100644 --- a/Descent3/winmain.cpp +++ b/Descent3/winmain.cpp @@ -142,17 +142,17 @@ public: final_shutdown = true; }; - void run() { Descent3(); }; + void run() { Descent3(); } // returns 0 if we pass to default window handler. - virtual int WndProc(HWnd hwnd, unsigned msg, unsigned wParam, long lParam) { + virtual LResult WndProc(HWnd hwnd, unsigned msg, WParam wParam, LParam lParam) override { if (final_shutdown) { return oeWin32Application::WndProc(hwnd, msg, wParam, lParam); } switch (msg) { case WM_ACTIVATEAPP: { - if (wParam == false) { + if (wParam == FALSE) { this->deactivate(); if (!shutdown) { diff --git a/dd_sndlib/ds3dlib_internal.h b/dd_sndlib/ds3dlib_internal.h index 02ac4bac..c251eff1 100644 --- a/dd_sndlib/ds3dlib_internal.h +++ b/dd_sndlib/ds3dlib_internal.h @@ -141,7 +141,7 @@ typedef struct DSSTREAMTAG { int MaxWriteSamples; int MaxWriteBytes; - unsigned long thread_handle; + uintptr_t thread_handle; // unsigned thread_id; volatile bool thread_request_kill; volatile bool thread_alive; diff --git a/dd_sndlib/dsound3d.cpp b/dd_sndlib/dsound3d.cpp index 9ae4af6f..6231dcff 100644 --- a/dd_sndlib/dsound3d.cpp +++ b/dd_sndlib/dsound3d.cpp @@ -58,7 +58,7 @@ static struct t_sb_loop_thread_data { win_llsSystem *m_ll_sndsys; - int thread_handle; + uintptr_t thread_handle; short no_callbacks; bool request_kill; bool thread_alive; diff --git a/ddio_win/ddio_win.h b/ddio_win/ddio_win.h index 339a7992..843ccae6 100644 --- a/ddio_win/ddio_win.h +++ b/ddio_win/ddio_win.h @@ -100,7 +100,7 @@ void ddio_DebugMessage(unsigned err, char *fmt, ...); #define MAKE_DDIO_TIME(_ms) ddio_TickToSeconds(_ms) // hook in timer function at certain period. returns a handle to this function -DWORD timer_HookFunction(void(CALLBACK *fncptr)(UINT, UINT, DWORD, DWORD, DWORD), UINT period); +DWORD timer_HookFunction(void(CALLBACK *fncptr)(UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR), UINT period); // clears function from hook list specified by a handle returned from HookFunction void timer_ReleaseFunction(DWORD func); diff --git a/ddio_win/winkey.cpp b/ddio_win/winkey.cpp index db2daf79..65c9be00 100644 --- a/ddio_win/winkey.cpp +++ b/ddio_win/winkey.cpp @@ -196,8 +196,8 @@ static struct tWinKeyData { LPDIRECTINPUTDEVICE lpdikey; // key device HANDLE evtnotify; // notify event HHOOK winhook; // windows hook - unsigned long thread; // thread id - // osMutex keyframe_mutex; // mutex between + uintptr_t thread; // thread id + //osMutex keyframe_mutex; // mutex between // internal key frame and key thread. bool nextframe; // used for mutexing between keyframe and thread. bool acquired; // device acquired? @@ -243,9 +243,8 @@ bool dikey_Acquire(LPDIRECTINPUTDEVICE lpdikey, bool acquire); bool ddio_Win_KeyInit(); void ddio_Win_KeyClose(); -int ddio_KeyHandler(HWnd wnd, unsigned msg, unsigned wParam, long lParam); +int ddio_KeyHandler(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam); -void CALLBACK key_TimerProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2); LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam); // DirectInput Keyboard Thread @@ -290,7 +289,6 @@ retry_key_init: bool acquired = dikey_Acquire(lpdikey, true); if (acquired) { // create keyboard thread - unsigned long thrid; WKD.thread_active = true; WKD.lpdikey = lpdikey; WKD.thread = 0; @@ -299,8 +297,8 @@ retry_key_init: WKD.winhook = NULL; WKD.suspended = false; WKD.nextframe = false; - thrid = _beginthread(dikey_Thread, 0, NULL); - if (thrid == (unsigned long)(-1)) { + uintptr_t thrid = _beginthread(dikey_Thread, 0, nullptr); + if (thrid == -1) { mprintf((0, "DDIO: DI_Keyboard thread failed to initialize.\n")); WKD.thread_active = false; WKD.lpdikey = NULL; @@ -731,14 +729,14 @@ LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam) { return (!res); } -int ddio_KeyHandler(HWnd wnd, unsigned msg, unsigned wParam, long lParam) { +int ddio_KeyHandler(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { ubyte scan_code; float timer = timer_GetTime(); if (!WKD.winhook) return 1; - switch ((UINT)msg) { + switch (msg) { case WM_KEYDOWN: case WM_SYSKEYDOWN: scan_code = (unsigned char)((lParam >> 16) & 0xff); diff --git a/ddio_win/winmouse.cpp b/ddio_win/winmouse.cpp index 91bbff55..08d95366 100644 --- a/ddio_win/winmouse.cpp +++ b/ddio_win/winmouse.cpp @@ -234,7 +234,7 @@ void ddio_InternalMouseFrame() { void MouseError() { MessageBoxA(nullptr, "Failed to init raw input for mouse", "Error", MB_ICONERROR); } -int RawInputHandler(HWND hWnd, unsigned int msg, unsigned int wParam, long lParam) { +int RawInputHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { unsigned int buttons; t_mse_event ev; float curtime = timer_GetTime(); diff --git a/ddio_win/wintimer.cpp b/ddio_win/wintimer.cpp index 1fef6108..109788cf 100644 --- a/ddio_win/wintimer.cpp +++ b/ddio_win/wintimer.cpp @@ -201,7 +201,7 @@ longlong timer_GetMSTime() { // Internal functions // --------------------------------------------------------------------------- // hook in timer function at certain period. returns a handle to this function -DWORD timer_HookFunction(void(CALLBACK *fncptr)(UINT, UINT, DWORD, DWORD, DWORD), UINT delay) { +DWORD timer_HookFunction(void(CALLBACK *fncptr)(UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR), UINT delay) { DWORD time_event_id; time_event_id = timeSetEvent(delay, Timer_resolution, fncptr, 0, TIME_PERIODIC); diff --git a/lib/TaskSystem.h b/lib/TaskSystem.h index 44c8d6fd..c44faca1 100644 --- a/lib/TaskSystem.h +++ b/lib/TaskSystem.h @@ -56,7 +56,7 @@ public: private: #endif // DD_ACCESS_RING_0 #if defined(WIN32) - unsigned event_os_handle; // this is the Win32 Event Handle + void *event_os_handle; // this is the Win32 Event Handle #endif // WIN32 public: @@ -77,9 +77,8 @@ public: private: #endif // DD_ACCESS_RING_0 #if defined(WIN32) - unsigned task_os_handle; // This is the Win32 EventHandle - unsigned task_os_id; // Win32 Thread ID -#endif // WIN32 + void *task_os_handle; // This is the Win32 Thread Handle +#endif // WIN32 public: osTask(unsigned (*func)(void *), tTaskPriority priority, void *parm = NULL); diff --git a/lib/win/win32app.h b/lib/win/win32app.h index 04b4702b..3581baea 100644 --- a/lib/win/win32app.h +++ b/lib/win/win32app.h @@ -80,11 +80,16 @@ #ifndef WIN32APP_H #define WIN32APP_H +#include + #define MAX_MSG_FUNCTIONS 64 -/* Basic Application Win32 data types */ -typedef unsigned int HWnd; -typedef unsigned int HInstance; +/* Basic Application Win32 data types, to prevent include of windows.h */ +typedef uintptr_t HWnd; +typedef uintptr_t HInstance; +typedef uintptr_t WParam; +typedef intptr_t LParam; +typedef intptr_t LResult; // This structure is used to retrieve and set typedef struct tWin32AppInfo { @@ -129,7 +134,7 @@ tOEWin32MsgCallback: endif */ -typedef int (*tOEWin32MsgCallback)(HWnd, unsigned, unsigned, long); +typedef int (*tOEWin32MsgCallback)(HWnd, unsigned, WParam, LParam); class oeWin32Application : public oeApplication { #if defined(OEAPP_INTERNAL_MODULE) @@ -189,7 +194,7 @@ public: void set_sizepos(int x, int y, int w, int h); // returns -1 if we pass to default window handler. - virtual int WndProc(HWnd hwnd, unsigned msg, unsigned wParam, long lParam); + virtual LResult WndProc(HWnd hwnd, unsigned msg, WParam wParam, LParam lParam); // These functions allow you to add message handlers. bool add_handler(unsigned msg, tOEWin32MsgCallback fn); @@ -198,7 +203,7 @@ public: bool remove_handler(unsigned msg, tOEWin32MsgCallback fn); // Run handler for message (added by add_handler) - bool run_handler(HWnd wnd, unsigned msg, unsigned wParam, long lParam); + bool run_handler(HWnd wnd, unsigned msg, WParam wParam, LParam lParam); // clears handler list void clear_handlers(); diff --git a/win32/winapp.cpp b/win32/winapp.cpp index fb2b27ba..20d00d4d 100644 --- a/win32/winapp.cpp +++ b/win32/winapp.cpp @@ -191,14 +191,14 @@ const uint kWindowStyle_Console = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_B We also allow the option of setting these handles from outside the Application object. */ -extern LRESULT WINAPI MyConProc(HWND hWnd, UINT msg, UINT wParam, LPARAM lParam); +extern LRESULT WINAPI MyConProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern void con_Defer(); bool oeWin32Application::os_initialized = false; bool oeWin32Application::first_time = true; // this is the app's window proc. -LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, UINT wParam, LPARAM lParam); +LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); // Creates the window handle and instance oeWin32Application::oeWin32Application(const char *name, unsigned flags, HInstance hinst) : oeApplication() { @@ -531,7 +531,7 @@ tWin32OS oeWin32Application::version(int *major, int *minor, int *build, char *s } // This Window Procedure is called from the global WindowProc. -int oeWin32Application::WndProc(HWnd hwnd, unsigned msg, unsigned wParam, long lParam) { +LResult oeWin32Application::WndProc(HWnd hwnd, unsigned msg, WParam wParam, LParam lParam) { switch (msg) { case WM_ACTIVATEAPP: m_AppActive = wParam ? true : false; @@ -539,7 +539,7 @@ int oeWin32Application::WndProc(HWnd hwnd, unsigned msg, unsigned wParam, long l break; } - return DefWindowProc((HWND)hwnd, (UINT)msg, (UINT)wParam, (LPARAM)lParam); + return DefWindowProc((HWND)hwnd, (UINT)msg, (WPARAM)wParam, (LPARAM)lParam); } // These functions allow you to add message handlers. @@ -583,7 +583,7 @@ bool oeWin32Application::remove_handler(unsigned msg, tOEWin32MsgCallback fn) { } // Run handler for message (added by add_handler) -bool oeWin32Application::run_handler(HWnd wnd, unsigned msg, unsigned wParam, long lParam) { +bool oeWin32Application::run_handler(HWnd wnd, unsigned msg, WParam wParam, LParam lParam) { int j; // run user-defined message handlers // the guess here is that any callback that returns a 0, will not want to handle the window's WndProc function. @@ -622,7 +622,7 @@ void oeWin32Application::delay(float secs) { } while (result == DEFER_PROCESS_ACTIVE || result == DEFER_PROCESS_INPUT_IDLE); } -LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, UINT wParam, LPARAM lParam) { +LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { int i = -1; bool force_default = false; @@ -708,11 +708,11 @@ LRESULT WINAPI MyWndProc(HWND hWnd, UINT msg, UINT wParam, LPARAM lParam) { if (i == -1 || winapp == NULL || force_default) return DefWindowProc(hWnd, msg, wParam, lParam); - if (!winapp->run_handler((HWnd)hWnd, (unsigned)msg, (unsigned)wParam, (long)lParam)) + if (!winapp->run_handler((HWnd)hWnd, (unsigned)msg, (WParam)wParam, (LParam)lParam)) return 0; // run user defined window procedure. - return (LRESULT)winapp->WndProc((HWnd)hWnd, (unsigned)msg, (unsigned)wParam, (long)lParam); + return (LRESULT)winapp->WndProc((HWnd)hWnd, (unsigned)msg, (WParam)wParam, (LParam)lParam); } // detect if application can handle what we want of it. diff --git a/win32/wincon.cpp b/win32/wincon.cpp index 6dbb54bc..2743f308 100644 --- a/win32/wincon.cpp +++ b/win32/wincon.cpp @@ -164,7 +164,7 @@ void con_Defer() { } // console window. -LRESULT WINAPI MyConProc(HWND hWnd, UINT msg, UINT wParam, LPARAM lParam) { +LRESULT WINAPI MyConProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { HDC hdc; switch (msg) { diff --git a/win32/wintask.cpp b/win32/wintask.cpp index 90fc4370..7e257e89 100644 --- a/win32/wintask.cpp +++ b/win32/wintask.cpp @@ -61,11 +61,10 @@ osTask::osTask(unsigned (*func)(void *), tTaskPriority priority, void *parm) { int pri; - task_os_handle = 0; - task_os_id = 0; + task_os_handle = nullptr; - task_os_handle = (unsigned)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, (LPVOID)parm, 0, (LPDWORD)&task_os_id); - if (task_os_handle == 0) { + task_os_handle = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)func, (LPVOID)parm, 0, nullptr); + if (task_os_handle == nullptr) { Int3(); // Get Samir. } @@ -109,7 +108,7 @@ void osTask::resume() // resumes task // --------------------------------------------------------------------------- // osEvent implementation // --------------------------------------------------------------------------- -osEvent::osEvent(char *name) { event_os_handle = (unsigned)CreateEvent(NULL, TRUE, FALSE, name); } +osEvent::osEvent(char *name) { event_os_handle = CreateEvent(NULL, TRUE, FALSE, name); } osEvent::~osEvent() { if (event_os_handle) @@ -130,10 +129,8 @@ void osEvent::clear() { // block until signaled bool osEvent::block(int timeout) { - DWORD res; - if (event_os_handle) { - res = WaitForSingleObject((HANDLE)event_os_handle, (timeout == -1) ? INFINITE : timeout); + DWORD res = WaitForSingleObject((HANDLE)event_os_handle, (timeout == -1) ? INFINITE : timeout); if (res == WAIT_OBJECT_0) return 1; else if (res == WAIT_ABANDONED)