diff --git a/panda/src/windisplay/winDetectDx.h b/panda/src/windisplay/winDetectDx.h index 31afa3de3b..85e815bcda 100644 --- a/panda/src/windisplay/winDetectDx.h +++ b/panda/src/windisplay/winDetectDx.h @@ -38,6 +38,8 @@ static DISPLAY_FORMAT display_format_array [ ] = { D3DFMT_UNKNOWN, 0, FALSE, }; +typedef BOOL (WINAPI *GlobalMemoryStatusExType) (LPMEMORYSTATUSEX lpBuffer); + static int d3d_format_to_bits_per_pixel (D3DFORMAT d3d_format) { int format_index; int bits_per_pixel; @@ -442,14 +444,28 @@ static int get_display_information (DisplaySearchParameters &display_search_para } // memory - MEMORYSTATUSEX memory_status; + bool memory_state; + HMODULE kernel32_dll; + + memory_state = false; + kernel32_dll = LoadLibrary ("kernel32.dll"); + if (kernel32_dll) { + GlobalMemoryStatusExType GlobalMemoryStatusExFunction; - memory_status.dwLength = sizeof (MEMORYSTATUSEX); - if (GlobalMemoryStatusEx (&memory_status)) { - physical_memory = memory_status.ullTotalPhys; - available_physical_memory = memory_status.ullAvailPhys; + GlobalMemoryStatusExFunction = (GlobalMemoryStatusExType) GetProcAddress (kernel32_dll, "GlobalMemoryStatusEx"); + if (GlobalMemoryStatusExFunction) { + MEMORYSTATUSEX memory_status; + + memory_status.dwLength = sizeof (MEMORYSTATUSEX); + if (GlobalMemoryStatusExFunction (&memory_status)) { + physical_memory = memory_status.ullTotalPhys; + available_physical_memory = memory_status.ullAvailPhys; + memory_state = true; + } + } + FreeLibrary (kernel32_dll); } - else { + if (memory_state == false) { MEMORYSTATUS memory_status; memory_status.dwLength = sizeof (MEMORYSTATUS);