From 3bac7674f40ac75bfe85b2cef4107443dc6560a9 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Thu, 5 Sep 2019 15:03:34 +0100 Subject: [PATCH] Correct some WinAPI usage All the broken stuff just happened to work on 32-bit, but would cause MinGW-w64 to explode if you tried building as 64-bit. I guess thanks to Microsoft keeping the basic C int types the same size in 64-bit as they were in 32-bit, this branch compiles as 64-bit just fine, despite Cave Story's many int-size dependencies. --- src/Dialog.cpp | 8 ++--- src/Dialog.h | 8 ++--- src/Generic.cpp | 79 ++++++++++++++++++++++++++----------------------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/Dialog.cpp b/src/Dialog.cpp index 7cb211a9..ba2803e2 100644 --- a/src/Dialog.cpp +++ b/src/Dialog.cpp @@ -17,7 +17,7 @@ static const char *version_string = ; // TODO - Inaccurate stack frame -BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +INT_PTR __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { char string_buffer[104]; @@ -56,7 +56,7 @@ BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) return FALSE; } -BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +INT_PTR __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { @@ -98,7 +98,7 @@ BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam return FALSE; } -BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +INT_PTR __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { char string[100]; @@ -129,7 +129,7 @@ BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam return FALSE; } -BOOL __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +INT_PTR __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { diff --git a/src/Dialog.h b/src/Dialog.h index 08fa948b..6ff69e82 100644 --- a/src/Dialog.h +++ b/src/Dialog.h @@ -2,7 +2,7 @@ #include "WindowsWrapper.h" -BOOL __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -BOOL __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -BOOL __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); -BOOL __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +INT_PTR __stdcall VersionDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +INT_PTR __stdcall DebugMuteDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +INT_PTR __stdcall DebugSaveDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +INT_PTR __stdcall QuitDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); diff --git a/src/Generic.cpp b/src/Generic.cpp index 8ee754f4..76439c4e 100644 --- a/src/Generic.cpp +++ b/src/Generic.cpp @@ -99,26 +99,53 @@ BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4) // TODO - Inaccurate stack frame BOOL OpenVolumeConfiguration(HWND hWnd) { +#ifdef FIX_BUGS char path[MAX_PATH]; char path2[MAX_PATH]; char path3[MAX_PATH]; -#ifdef FIX_BUGS - char path4[MAX_PATH]; - char path5[MAX_PATH]; -#endif - int error1; - int error2; -#ifdef FIX_BUGS - int error3; - int error4; -#endif + INT_PTR error; + size_t i; + + GetSystemDirectoryA(path, sizeof(path)); + GetSystemDirectoryA(path2, sizeof(path2)); + + i = strlen(path2); + while (path2[i] != '\\') + --i; + + path2[i] = '\0'; + + sprintf(path3, "%s\\Sndvol32.exe", path); + error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); + if (error > 32) + return TRUE; + + sprintf(path3, "%s\\Sndvol32.exe", path2); + error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); + if (error > 32) + return TRUE; + + sprintf(path3, "%s\\Sndvol.exe", path); + error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); + if (error > 32) + return TRUE; + + sprintf(path3, "%s\\Sndvol.exe", path2); + error = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); + if (error > 32) + return TRUE; + + return FALSE; +#else + char path[MAX_PATH]; + char path2[MAX_PATH]; + char path3[MAX_PATH]; + INT_PTR error1; + INT_PTR error2; size_t i; GetSystemDirectoryA(path, sizeof(path)); sprintf(path2, "%s\\Sndvol32.exe", path); -#ifdef FIX_BUGS - sprintf(path4, "%s\\Sndvol.exe", path); -#endif i = strlen(path); while (path[i] != '\\') @@ -126,31 +153,9 @@ BOOL OpenVolumeConfiguration(HWND hWnd) path[i] = '\0'; sprintf(path3, "%s\\Sndvol32.exe", path); -#ifdef FIX_BUGS - sprintf(path5, "%s\\Sndvol.exe", path); -#endif -#ifdef FIX_BUGS - error1 = (int)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW); - if (error1 > 32) - return TRUE; - - error2 = (int)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); - if (error2 > 32) - return TRUE; - - error3 = (int)ShellExecuteA(hWnd, "open", path4, NULL, NULL, SW_SHOW); - if (error3 > 32) - return TRUE; - - error4 = (int)ShellExecuteA(hWnd, "open", path5, NULL, NULL, SW_SHOW); - if (error4 > 32) - return TRUE; - - return FALSE; -#else - error1 = (int)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW); - error2 = (int)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); + error1 = (INT_PTR)ShellExecuteA(hWnd, "open", path2, NULL, NULL, SW_SHOW); + error2 = (INT_PTR)ShellExecuteA(hWnd, "open", path3, NULL, NULL, SW_SHOW); if (error1 <= 32 && error2 <= 32) return FALSE;