MinGW: Avoid function cast warnings with GetProcAddress
This commit is contained in:
@@ -571,7 +571,7 @@ char *CrashLogWindows::AppendDecodedStacktrace(char *buffer, const char *last) c
|
|||||||
CONST PMINIDUMP_EXCEPTION_INFORMATION,
|
CONST PMINIDUMP_EXCEPTION_INFORMATION,
|
||||||
CONST PMINIDUMP_USER_STREAM_INFORMATION,
|
CONST PMINIDUMP_USER_STREAM_INFORMATION,
|
||||||
CONST PMINIDUMP_CALLBACK_INFORMATION);
|
CONST PMINIDUMP_CALLBACK_INFORMATION);
|
||||||
MiniDumpWriteDump_t funcMiniDumpWriteDump = (MiniDumpWriteDump_t)GetProcAddress(dbghelp, "MiniDumpWriteDump");
|
MiniDumpWriteDump_t funcMiniDumpWriteDump = GetProcAddressT<MiniDumpWriteDump_t>(dbghelp, "MiniDumpWriteDump");
|
||||||
if (funcMiniDumpWriteDump != nullptr) {
|
if (funcMiniDumpWriteDump != nullptr) {
|
||||||
seprintf(filename, filename_last, "%scrash.dmp", _personal_dir.c_str());
|
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);
|
HANDLE file = CreateFile(OTTD2FS(filename).c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, 0);
|
||||||
|
@@ -623,7 +623,7 @@ void LoadWin32Font(FontSize fs)
|
|||||||
/* Try a nice little undocumented function first for getting the internal font name.
|
/* Try a nice little undocumented function first for getting the internal font name.
|
||||||
* Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
|
* Some documentation is found at: http://www.undocprint.org/winspool/getfontresourceinfo */
|
||||||
typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
|
typedef BOOL(WINAPI *PFNGETFONTRESOURCEINFO)(LPCTSTR, LPDWORD, LPVOID, DWORD);
|
||||||
static PFNGETFONTRESOURCEINFO GetFontResourceInfo = (PFNGETFONTRESOURCEINFO)GetProcAddress(GetModuleHandle(L"Gdi32"), "GetFontResourceInfoW");
|
static PFNGETFONTRESOURCEINFO GetFontResourceInfo = GetProcAddressT<PFNGETFONTRESOURCEINFO>(GetModuleHandle(L"Gdi32"), "GetFontResourceInfoW");
|
||||||
|
|
||||||
if (GetFontResourceInfo != nullptr) {
|
if (GetFontResourceInfo != nullptr) {
|
||||||
/* Try to query an array of LOGFONTs that describe the file. */
|
/* Try to query an array of LOGFONTs that describe the file. */
|
||||||
|
@@ -40,10 +40,6 @@
|
|||||||
|
|
||||||
#include "../../safeguards.h"
|
#include "../../safeguards.h"
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
|
||||||
#endif /* __MINGW32__ */
|
|
||||||
|
|
||||||
static bool _has_console;
|
static bool _has_console;
|
||||||
static bool _cursor_disable = true;
|
static bool _cursor_disable = true;
|
||||||
static bool _cursor_visible = true;
|
static bool _cursor_visible = true;
|
||||||
@@ -71,13 +67,13 @@ bool LoadLibraryList(Function proc[], const char *dll)
|
|||||||
|
|
||||||
if (lib == nullptr) return false;
|
if (lib == nullptr) return false;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
FARPROC p;
|
Function p;
|
||||||
|
|
||||||
while (*dll++ != '\0') { /* Nothing */ }
|
while (*dll++ != '\0') { /* Nothing */ }
|
||||||
if (*dll == '\0') break;
|
if (*dll == '\0') break;
|
||||||
p = GetProcAddress(lib, dll);
|
p = GetProcAddressT<Function>(lib, dll);
|
||||||
if (p == nullptr) return false;
|
if (p == nullptr) return false;
|
||||||
*proc++ = (Function)p;
|
*proc++ = p;
|
||||||
}
|
}
|
||||||
dll++;
|
dll++;
|
||||||
}
|
}
|
||||||
@@ -693,7 +689,7 @@ int OTTDStringCompare(const char *s1, const char *s2)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
_CompareStringEx = (PFNCOMPARESTRINGEX)GetProcAddress(GetModuleHandle(L"Kernel32"), "CompareStringEx");
|
_CompareStringEx = GetProcAddressT<PFNCOMPARESTRINGEX>(GetModuleHandle(L"Kernel32"), "CompareStringEx");
|
||||||
first_time = false;
|
first_time = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
void Win32SetCurrentLocaleName(const char *iso_code);
|
||||||
int OTTDStringCompare(const char *s1, const char *s2);
|
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 <typename T>
|
||||||
|
T GetProcAddressT(HMODULE hModule, LPCSTR lpProcName)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<T>(GetProcAddress(hModule, lpProcName));
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* WIN32_H */
|
#endif /* WIN32_H */
|
||||||
|
@@ -158,7 +158,7 @@ const char *SoundDriver_XAudio2::Start(const StringList &parm)
|
|||||||
return "Failed to load XAudio2 DLL";
|
return "Failed to load XAudio2 DLL";
|
||||||
}
|
}
|
||||||
|
|
||||||
API_XAudio2Create xAudio2Create = (API_XAudio2Create) GetProcAddress(_xaudio_dll_handle, "XAudio2Create");
|
API_XAudio2Create xAudio2Create = GetProcAddressT<API_XAudio2Create>(_xaudio_dll_handle, "XAudio2Create");
|
||||||
|
|
||||||
if (xAudio2Create == nullptr)
|
if (xAudio2Create == nullptr)
|
||||||
{
|
{
|
||||||
|
@@ -962,9 +962,9 @@ float VideoDriver_Win32Base::GetDPIScale()
|
|||||||
if (!init_done) {
|
if (!init_done) {
|
||||||
init_done = true;
|
init_done = true;
|
||||||
|
|
||||||
_GetDpiForWindow = (PFNGETDPIFORWINDOW)GetProcAddress(GetModuleHandle(L"User32"), "GetDpiForWindow");
|
_GetDpiForWindow = GetProcAddressT<PFNGETDPIFORWINDOW>(GetModuleHandle(L"User32"), "GetDpiForWindow");
|
||||||
_GetDpiForSystem = (PFNGETDPIFORSYSTEM)GetProcAddress(GetModuleHandle(L"User32"), "GetDpiForSystem");
|
_GetDpiForSystem = GetProcAddressT<PFNGETDPIFORSYSTEM>(GetModuleHandle(L"User32"), "GetDpiForSystem");
|
||||||
_GetDpiForMonitor = (PFNGETDPIFORMONITOR)GetProcAddress(LoadLibrary(L"Shcore.dll"), "GetDpiForMonitor");
|
_GetDpiForMonitor = GetProcAddressT<PFNGETDPIFORMONITOR>(LoadLibrary(L"Shcore.dll"), "GetDpiForMonitor");
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT cur_dpi = 0;
|
UINT cur_dpi = 0;
|
||||||
|
Reference in New Issue
Block a user