diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index b8c4fc845b..440f9b18ce 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -571,7 +571,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c CONST PMINIDUMP_EXCEPTION_INFORMATION, CONST PMINIDUMP_USER_STREAM_INFORMATION, CONST PMINIDUMP_CALLBACK_INFORMATION); - MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump"); + MiniDumpWriteDump_t funcMiniDumpWriteDump = GetProcAddressT(dbghelp, "MiniDumpWriteDump"); if (funcMiniDumpWriteDump != nullptr) { seprintf(filename, filename_last, "%scrash.dmp", _personal_dir.c_str()); HANDLE file = CreateFile(OTTD2FS(filename).c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0); diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp index 6b224c40fc..da8aab8bd5 100644 --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -623,7 +623,7 @@ void LoadWin32Font(FontSize fs) /* Try a nice little undocumented function first for getting the internal font name. * Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */ typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD); - static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(L"Gdi32"), "GetFontResourceInfoW"); + static PFNGETFONTRESOURCEINFO GetFontResourceInfo = GetProcAddressT(GetModuleHandle(L"Gdi32"), "GetFontResourceInfoW"); if (GetFontResourceInfo != nullptr) { /* Try to query an array of LOGFONTs that describe the file. */ diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index cb34391e67..fea5a4192c 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -40,10 +40,6 @@ #include "../../safeguards.h" -#ifdef __MINGW32__ -#pragma GCC diagnostic ignored "-Wcast-function-type" -#endif /* __MINGW32__ */ - static bool _has_console; static bool _cursor_disable = true; static bool _cursor_visible = true; @@ -71,13 +67,13 @@ bool LoadLibraryList(Function proc[], const char *dll) if (lib == nullptr) return false; for (;;) { - FARPROC p; + Function p; while (*dll++ != '\0') { /* Nothing */ } if (*dll == '\0') break; - p = GetProcAddress(lib, dll); + p = GetProcAddressT(lib, dll); if (p == nullptr) return false; - *proc++ = (Function)p; + *proc++ = p; } dll++; } @@ -693,7 +689,7 @@ int OTTDStringCompare(const char *s1, const char *s2) #endif if (first_time) { - _CompareStringEx = (PFNCOMPARESTRINGEX)GetProcAddress(GetModuleHandle(L"Kernel32"), "CompareStringEx"); + _CompareStringEx = GetProcAddressT(GetModuleHandle(L"Kernel32"), "CompareStringEx"); first_time = false; } diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h index d65bf78efd..0180ed4ff3 100644 --- a/src/os/windows/win32.h +++ b/src/os/windows/win32.h @@ -26,4 +26,20 @@ wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen); void Win32SetCurrentLocaleName(const char *iso_code); int OTTDStringCompare(const char *s1, const char *s2); +#ifdef __MINGW32__ + /* GCC doesn't understand the expected usage of GetProcAddress(). */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif /* __MINGW32__ */ + +template +T GetProcAddressT(HMODULE hModule, LPCSTR lpProcName) +{ + return reinterpret_cast(GetProcAddress(hModule, lpProcName)); +} + +#ifdef __MINGW32__ +#pragma GCC diagnostic pop +#endif + #endif /* WIN32_H */ diff --git a/src/sound/xaudio2_s.cpp b/src/sound/xaudio2_s.cpp index 3eb5dd1d3d..5a16ee06de 100644 --- a/src/sound/xaudio2_s.cpp +++ b/src/sound/xaudio2_s.cpp @@ -158,7 +158,7 @@ const char *SoundDriver_XAudio2::Start(const StringList &parm) return "Failed to load XAudio2 DLL"; } - API_XAudio2Create xAudio2Create = (API_XAudio2Create) GetProcAddress(_xaudio_dll_handle, "XAudio2Create"); + API_XAudio2Create xAudio2Create = GetProcAddressT(_xaudio_dll_handle, "XAudio2Create"); if (xAudio2Create == nullptr) { diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 2673d9e17b..7c09bb77fd 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -962,9 +962,9 @@ float VideoDriver_Win32Base::GetDPIScale() if (!init_done) { init_done = true; - _GetDpiForWindow = (PFNGETDPIFORWINDOW)GetProcAddress(GetModuleHandle(L"User32"), "GetDpiForWindow"); - _GetDpiForSystem = (PFNGETDPIFORSYSTEM)GetProcAddress(GetModuleHandle(L"User32"), "GetDpiForSystem"); - _GetDpiForMonitor = (PFNGETDPIFORMONITOR)GetProcAddress(LoadLibrary(L"Shcore.dll"), "GetDpiForMonitor"); + _GetDpiForWindow = GetProcAddressT(GetModuleHandle(L"User32"), "GetDpiForWindow"); + _GetDpiForSystem = GetProcAddressT(GetModuleHandle(L"User32"), "GetDpiForSystem"); + _GetDpiForMonitor = GetProcAddressT(LoadLibrary(L"Shcore.dll"), "GetDpiForMonitor"); } UINT cur_dpi = 0;