Panda3D
|
00001 // Filename: winDetectDx.h 00002 // Created by: aignacio (18Jan07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 typedef struct { 00016 D3DFORMAT d3d_format; 00017 int bits_per_pixel; 00018 int fullscreen_only; 00019 } 00020 DISPLAY_FORMAT; 00021 00022 typedef union 00023 { 00024 struct 00025 { 00026 unsigned int day : 8; 00027 unsigned int month : 8; 00028 unsigned int year : 16; 00029 }; 00030 DWORD whql; 00031 } 00032 WHQL; 00033 00034 static DISPLAY_FORMAT display_format_array [ ] = { 00035 D3DFMT_X8R8G8B8, 32, FALSE, 00036 D3DFMT_R5G6B5, 16, FALSE, 00037 D3DFMT_X1R5G5B5, 16, FALSE, 00038 00039 #if DX8 00040 #else 00041 D3DFMT_A2R10G10B10, 32, TRUE, 00042 #endif 00043 00044 // terminator 00045 D3DFMT_UNKNOWN, 0, FALSE, 00046 }; 00047 00048 typedef BOOL (WINAPI *GlobalMemoryStatusExType) (LPMEMORYSTATUSEX lpBuffer); 00049 00050 static int d3d_format_to_bits_per_pixel (D3DFORMAT d3d_format) { 00051 int format_index; 00052 int bits_per_pixel; 00053 00054 format_index = 0; 00055 bits_per_pixel = 0; 00056 while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) { 00057 if (d3d_format == display_format_array [format_index].d3d_format) { 00058 bits_per_pixel = display_format_array [format_index].bits_per_pixel; 00059 break; 00060 } 00061 00062 format_index++; 00063 } 00064 00065 return bits_per_pixel; 00066 } 00067 00068 static DWORD _GetLastError (char *message_prefix) { 00069 LPVOID ptr; 00070 DWORD error; 00071 00072 ptr = 0; 00073 error = GetLastError ( ); 00074 if (FormatMessage ( 00075 FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM, 00076 NULL, error, MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ), 00077 (LPTSTR)&ptr,0, NULL)) { 00078 cout << "ERROR: "<< message_prefix << " result = " << (char*) ptr << "\n"; 00079 LocalFree( ptr ); 00080 } 00081 00082 return error; 00083 } 00084 00085 static LRESULT CALLBACK window_procedure (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { 00086 return DefWindowProc(hwnd, msg, wparam, lparam); 00087 } 00088 00089 static DWORD print_GetLastError (char *message_prefix) 00090 { 00091 LPVOID ptr; 00092 DWORD error; 00093 00094 ptr = 0; 00095 error = GetLastError ( ); 00096 if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | 00097 FORMAT_MESSAGE_FROM_SYSTEM, 00098 NULL, 00099 error, 00100 MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ), 00101 (LPTSTR)&ptr, 00102 0, NULL)) 00103 { 00104 cout << "ERROR: "<< message_prefix << " result = " << (char*) ptr << "\n"; 00105 LocalFree( ptr ); 00106 } 00107 00108 return error; 00109 } 00110 00111 static int get_display_information (DisplaySearchParameters &display_search_parameters, DisplayInformation *display_information) { 00112 00113 int debug = false; 00114 00115 int success; 00116 DisplayInformation::DetectionState state; 00117 int get_adapter_display_mode_state; 00118 int get_device_caps_state; 00119 00120 int shader_model; 00121 UINT minimum_width; 00122 UINT maximum_width; 00123 UINT minimum_height; 00124 UINT maximum_height; 00125 int minimum_bits_per_pixel; 00126 int maximum_bits_per_pixel; 00127 00128 UINT texture_memory; 00129 UINT video_memory; 00130 00131 int window_width; 00132 int window_height; 00133 int window_bits_per_pixel; 00134 int total_display_modes; 00135 DisplayMode *display_mode_array; 00136 00137 PN_uint64 physical_memory; 00138 PN_uint64 available_physical_memory; 00139 00140 int vendor_id; 00141 int device_id; 00142 00143 int product; 00144 int version; 00145 int sub_version; 00146 int build; 00147 00148 int month; 00149 int day; 00150 int year; 00151 00152 success = false; 00153 window_width = 0; 00154 window_height = 0; 00155 window_bits_per_pixel = 0; 00156 total_display_modes = 0; 00157 display_mode_array = NULL; 00158 00159 minimum_width = display_search_parameters._minimum_width; 00160 minimum_height = display_search_parameters._minimum_height; 00161 maximum_width = display_search_parameters._maximum_width; 00162 maximum_height = display_search_parameters._maximum_height; 00163 minimum_bits_per_pixel = display_search_parameters._minimum_bits_per_pixel; 00164 maximum_bits_per_pixel = display_search_parameters._maximum_bits_per_pixel; 00165 00166 shader_model = GraphicsStateGuardian::SM_00; 00167 video_memory = 0; 00168 texture_memory = 0; 00169 00170 state = DisplayInformation::DS_unknown; 00171 get_adapter_display_mode_state = false; 00172 get_device_caps_state = false; 00173 00174 physical_memory = 0; 00175 available_physical_memory = 0; 00176 00177 vendor_id = 0; 00178 device_id = 0; 00179 00180 product = 0; 00181 version = 0; 00182 sub_version = 0; 00183 build = 0; 00184 00185 month = 0; 00186 day = 0; 00187 year = 0; 00188 00189 HMODULE d3d_dll; 00190 DIRECT_3D_CREATE Direct3DCreate; 00191 00192 d3d_dll = LoadLibrary (d3d_dll_name); 00193 if (d3d_dll) { 00194 Direct3DCreate = (DIRECT_3D_CREATE) GetProcAddress (d3d_dll, direct_3d_create_function_name); 00195 if (Direct3DCreate) { 00196 DIRECT_3D direct_3d; 00197 00198 direct_3d = Direct3DCreate (D3D_SDK_VERSION); 00199 if (direct_3d != NULL) { 00200 DWORD flags; 00201 UINT adapter; 00202 D3DDEVTYPE device_type; 00203 D3DDISPLAYMODE current_d3d_display_mode; 00204 D3DADAPTER_IDENTIFIER d3d_adapter_identifier; 00205 D3DCAPS d3d_caps; 00206 00207 adapter = D3DADAPTER_DEFAULT; 00208 device_type = D3DDEVTYPE_HAL; 00209 00210 // windowed mode max res and format 00211 if (direct_3d -> GetAdapterDisplayMode (adapter, ¤t_d3d_display_mode) == D3D_OK) { 00212 if (debug) { 00213 printf ("current mode w = %d h = %d r = %d f = %d \n", 00214 current_d3d_display_mode.Width, 00215 current_d3d_display_mode.Height, 00216 current_d3d_display_mode.RefreshRate, 00217 current_d3d_display_mode.Format); 00218 } 00219 00220 window_width = current_d3d_display_mode.Width; 00221 window_height = current_d3d_display_mode.Height; 00222 window_bits_per_pixel = d3d_format_to_bits_per_pixel (current_d3d_display_mode.Format); 00223 00224 get_adapter_display_mode_state = true; 00225 } 00226 else { 00227 get_adapter_display_mode_state = false; 00228 } 00229 00230 flags = 0; 00231 if (direct_3d -> GetAdapterIdentifier (adapter, flags, &d3d_adapter_identifier) == D3D_OK) { 00232 // print adapter info 00233 d3d_adapter_identifier.Driver; 00234 d3d_adapter_identifier.Description; 00235 #if DX8 00236 #else 00237 d3d_adapter_identifier.DeviceName; 00238 #endif 00239 d3d_adapter_identifier.DriverVersion; 00240 d3d_adapter_identifier.VendorId; 00241 d3d_adapter_identifier.DeviceId; 00242 d3d_adapter_identifier.SubSysId; 00243 d3d_adapter_identifier.Revision; 00244 d3d_adapter_identifier.DeviceIdentifier; 00245 d3d_adapter_identifier.WHQLLevel; 00246 00247 if (debug) { 00248 printf ("Driver: %s\n", d3d_adapter_identifier.Driver); 00249 printf ("Description: %s\n", d3d_adapter_identifier.Description); 00250 } 00251 00252 char system_directory [MAX_PATH]; 00253 char dll_file_path [MAX_PATH]; 00254 00255 // find the dll in the system directory if possible and get the date of the file 00256 if (GetSystemDirectory (system_directory, MAX_PATH) > 0) { 00257 if (debug) { 00258 printf ("system_directory = %s \n", system_directory); 00259 } 00260 sprintf (dll_file_path, "%s\\%s", system_directory, d3d_adapter_identifier.Driver); 00261 00262 intptr_t find; 00263 struct _finddata_t find_data; 00264 00265 find = _findfirst (dll_file_path, &find_data); 00266 if (find != -1) { 00267 struct tm *dll_time; 00268 00269 dll_time = localtime(&find_data.time_write); 00270 00271 month = dll_time -> tm_mon + 1; 00272 day = dll_time -> tm_mday; 00273 year = dll_time -> tm_year + 1900; 00274 00275 if (debug) { 00276 printf ("Driver Date: %d/%d/%d\n", month, day, year); 00277 } 00278 00279 _findclose (find); 00280 } 00281 } 00282 00283 /* 00284 HMODULE driver_dll; 00285 00286 driver_dll = LoadLibrary (d3d_adapter_identifier.Driver); 00287 if (driver_dll) 00288 { 00289 DWORD length; 00290 TCHAR file_path [MAX_PATH]; 00291 00292 length = GetModuleFileName(driver_dll, file_path, MAX_PATH); 00293 if (length > 0) 00294 { 00295 printf ("DLL file path = %s \n", file_path); 00296 } 00297 else 00298 { 00299 printf ("ERROR: could not get GetModuleFileName for %s \n", d3d_adapter_identifier.Driver); 00300 } 00301 00302 FreeLibrary (driver_dll); 00303 } 00304 else 00305 { 00306 print_GetLastError (""); 00307 printf ("ERROR: could not load = %s \n", d3d_adapter_identifier.Driver); 00308 } 00309 */ 00310 00311 if (debug) { 00312 printf ("VendorId = 0x%x\n", d3d_adapter_identifier.VendorId); 00313 printf ("DeviceId = 0x%x\n", d3d_adapter_identifier.DeviceId); 00314 } 00315 00316 vendor_id = d3d_adapter_identifier.VendorId; 00317 device_id = d3d_adapter_identifier.DeviceId; 00318 00319 product = HIWORD(d3d_adapter_identifier.DriverVersion.HighPart); 00320 version = LOWORD(d3d_adapter_identifier.DriverVersion.HighPart); 00321 sub_version = HIWORD(d3d_adapter_identifier.DriverVersion.LowPart); 00322 build = LOWORD(d3d_adapter_identifier.DriverVersion.LowPart); 00323 00324 if (debug) { 00325 printf ("DRIVER VERSION: %d.%d.%d.%d \n", product, version, sub_version, build); 00326 } 00327 00328 WHQL whql; 00329 00330 whql.whql= d3d_adapter_identifier.WHQLLevel; 00331 00332 if (debug) { 00333 printf ("WHQL: %d %d %d \n", whql.day, whql.day, whql.year); 00334 } 00335 } 00336 00337 if (direct_3d -> GetDeviceCaps (adapter, device_type, &d3d_caps) == D3D_OK) { 00338 00339 #if DX8 00340 // shaders not supported in DX8 00341 #else 00342 int vertex_shader_version_major; 00343 int vertex_shader_version_minor; 00344 int pixel_shader_version_major; 00345 int pixel_shader_version_minor; 00346 00347 vertex_shader_version_major = D3DSHADER_VERSION_MAJOR (d3d_caps.VertexShaderVersion); 00348 vertex_shader_version_minor = D3DSHADER_VERSION_MINOR (d3d_caps.VertexShaderVersion); 00349 pixel_shader_version_major = D3DSHADER_VERSION_MAJOR (d3d_caps.PixelShaderVersion); 00350 pixel_shader_version_minor = D3DSHADER_VERSION_MINOR (d3d_caps.PixelShaderVersion); 00351 00352 switch (pixel_shader_version_major) 00353 { 00354 case 0: 00355 shader_model = GraphicsStateGuardian::SM_00; 00356 break; 00357 case 1: 00358 shader_model = GraphicsStateGuardian::SM_11; 00359 break; 00360 case 2: 00361 // minimim specification for pixel shader 2.0 is 96 instruction slots 00362 shader_model = GraphicsStateGuardian::SM_20; 00363 if (d3d_caps.PS20Caps.NumInstructionSlots >= 512) { 00364 shader_model = GraphicsStateGuardian::SM_2X; 00365 } 00366 break; 00367 case 3: 00368 shader_model = GraphicsStateGuardian::SM_30; 00369 break; 00370 case 4: 00371 default: 00372 shader_model = GraphicsStateGuardian::SM_40; 00373 break; 00374 } 00375 #endif 00376 00377 if (debug) { 00378 printf ("shader_model = %d \n", shader_model); 00379 } 00380 get_device_caps_state = true; 00381 } 00382 else { 00383 get_device_caps_state = false; 00384 } 00385 00386 // count display modes 00387 int format_index; 00388 int maximum_display_modes; 00389 UINT display_mode_count; 00390 D3DFORMAT d3d_format; 00391 00392 format_index = 0; 00393 maximum_display_modes = 0; 00394 00395 while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) { 00396 d3d_format = display_format_array [format_index].d3d_format; 00397 00398 #if DX8 00399 display_mode_count = direct_3d -> GetAdapterModeCount (adapter); 00400 #else 00401 display_mode_count = direct_3d -> GetAdapterModeCount (adapter, d3d_format); 00402 #endif 00403 if (display_mode_count > 0) { 00404 UINT mode_index; 00405 D3DDISPLAYMODE d3d_display_mode; 00406 00407 for (mode_index = 0; mode_index < display_mode_count; mode_index++) { 00408 #if DX8 00409 if (direct_3d -> EnumAdapterModes (adapter, mode_index, &d3d_display_mode) == D3D_OK) 00410 #else 00411 if (direct_3d -> EnumAdapterModes (adapter, d3d_format, mode_index, &d3d_display_mode) == D3D_OK) 00412 #endif 00413 { 00414 if (d3d_display_mode.Width >= minimum_width && d3d_display_mode.Height >= minimum_height && 00415 d3d_display_mode.Width <= maximum_width && d3d_display_mode.Height <= maximum_height) { 00416 if (display_format_array [format_index].bits_per_pixel >= minimum_bits_per_pixel && 00417 display_format_array [format_index].bits_per_pixel <= maximum_bits_per_pixel) { 00418 if (d3d_format == d3d_display_mode.Format) { 00419 maximum_display_modes++; 00420 } 00421 } 00422 } 00423 } 00424 } 00425 } 00426 00427 format_index++; 00428 } 00429 00430 if (debug) { 00431 printf ("maximum_display_modes %d \n", maximum_display_modes); 00432 } 00433 00434 display_mode_array = new DisplayMode [maximum_display_modes]; 00435 00436 format_index = 0; 00437 while (display_format_array [format_index].d3d_format != D3DFMT_UNKNOWN) { 00438 d3d_format = display_format_array [format_index].d3d_format; 00439 #if DX8 00440 display_mode_count = direct_3d -> GetAdapterModeCount (adapter); 00441 #else 00442 display_mode_count = direct_3d -> GetAdapterModeCount (adapter, d3d_format); 00443 #endif 00444 if (display_mode_count > 0) { 00445 UINT mode_index; 00446 D3DDISPLAYMODE d3d_display_mode; 00447 00448 for (mode_index = 0; mode_index < display_mode_count; mode_index++) { 00449 #if DX8 00450 if (direct_3d -> EnumAdapterModes (adapter, mode_index, &d3d_display_mode) == D3D_OK) 00451 #else 00452 if (direct_3d -> EnumAdapterModes (adapter, d3d_format, mode_index, &d3d_display_mode) == D3D_OK) 00453 #endif 00454 { 00455 if (d3d_display_mode.Width >= minimum_width && d3d_display_mode.Height >= minimum_height && 00456 d3d_display_mode.Width <= maximum_width && d3d_display_mode.Height <= maximum_height) { 00457 if (display_format_array [format_index].bits_per_pixel >= minimum_bits_per_pixel && 00458 display_format_array [format_index].bits_per_pixel <= maximum_bits_per_pixel) { 00459 if (debug) { 00460 printf ("w = %d h = %d r = %d f = %d \n", 00461 d3d_display_mode.Width, 00462 d3d_display_mode.Height, 00463 d3d_display_mode.RefreshRate, 00464 d3d_display_mode.Format); 00465 } 00466 00467 if (d3d_format == d3d_display_mode.Format) { 00468 DisplayMode *display_mode; 00469 00470 display_mode = &display_mode_array [total_display_modes]; 00471 display_mode -> width = d3d_display_mode.Width; 00472 display_mode -> height = d3d_display_mode.Height; 00473 display_mode -> bits_per_pixel = display_format_array [format_index].bits_per_pixel; 00474 display_mode -> refresh_rate = d3d_display_mode.RefreshRate; 00475 display_mode -> fullscreen_only = display_format_array [format_index].fullscreen_only; 00476 00477 total_display_modes++; 00478 } 00479 } 00480 } 00481 } 00482 } 00483 } 00484 00485 format_index++; 00486 } 00487 00488 UINT width; 00489 UINT height; 00490 00491 width = 640; 00492 height = 480; 00493 00494 // make a window 00495 WNDCLASSEX window_class = 00496 { 00497 sizeof (WNDCLASSEX), CS_CLASSDC, window_procedure, 0L, 0L, 00498 GetModuleHandle(NULL), NULL, NULL, NULL, NULL, 00499 "class_name", NULL 00500 }; 00501 RegisterClassEx (&window_class); 00502 00503 HWND window_handle; 00504 00505 window_handle = CreateWindow ("class_name", "window_name", WS_DISABLED, 0, 0, width, height, (HWND) NULL, (HMENU) NULL, window_class.hInstance, NULL); 00506 if (window_handle != NULL) { 00507 ShowWindow (window_handle, SW_HIDE); 00508 00509 DIRECT_3D_DEVICE direct_3d_device; 00510 D3DPRESENT_PARAMETERS present_parameters; 00511 DWORD behavior_flags; 00512 00513 direct_3d_device = 0; 00514 memset (&present_parameters, 0, sizeof (D3DPRESENT_PARAMETERS)); 00515 00516 present_parameters.BackBufferWidth = width; 00517 present_parameters.BackBufferHeight = height; 00518 present_parameters.BackBufferFormat = D3DFMT_X8R8G8B8; 00519 present_parameters.BackBufferCount = 1; 00520 00521 present_parameters.SwapEffect = D3DSWAPEFFECT_FLIP; 00522 present_parameters.hDeviceWindow = window_handle; 00523 00524 present_parameters.Windowed = true; 00525 present_parameters.EnableAutoDepthStencil = true; 00526 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8; 00527 00528 present_parameters.FullScreen_RefreshRateInHz; 00529 00530 #if DX8 00531 #else 00532 present_parameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; 00533 #endif 00534 00535 if (d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { 00536 behavior_flags = D3DCREATE_HARDWARE_VERTEXPROCESSING; 00537 } 00538 else { 00539 behavior_flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; 00540 } 00541 // This is important to prevent DirectX from forcing the FPU into single-precision mode. 00542 behavior_flags |= D3DCREATE_FPU_PRESERVE; 00543 00544 HRESULT result; 00545 00546 result = direct_3d -> CreateDevice (adapter, device_type, window_handle, behavior_flags, &present_parameters, &direct_3d_device); 00547 if (result == D3D_OK) { 00548 00549 // allocate 512x512 32-bit textures (1MB size) until we run out or hit the limit 00550 #define MAXIMUM_TEXTURES (2048 - 1) 00551 00552 int total_textures; 00553 HRESULT texture_result; 00554 #if DX8 00555 IDirect3DTexture8 *texture_array [MAXIMUM_TEXTURES]; 00556 #else 00557 IDirect3DTexture9 *texture_array [MAXIMUM_TEXTURES]; 00558 #endif 00559 00560 total_textures = 0; 00561 while (total_textures < MAXIMUM_TEXTURES) { 00562 00563 #if DX8 00564 texture_result = direct_3d_device -> CreateTexture ( 00565 512, 00566 512, 00567 1, 00568 D3DUSAGE_RENDERTARGET, 00569 D3DFMT_A8R8G8B8, 00570 D3DPOOL_DEFAULT, 00571 &texture_array [total_textures]); 00572 #else 00573 texture_result = direct_3d_device -> CreateTexture ( 00574 512, 00575 512, 00576 1, 00577 D3DUSAGE_RENDERTARGET, 00578 D3DFMT_A8R8G8B8, 00579 D3DPOOL_DEFAULT, 00580 &texture_array [total_textures], 00581 NULL); 00582 #endif 00583 if (texture_result == D3D_OK) { 00584 total_textures++; 00585 } 00586 else { 00587 if (texture_result == D3DERR_OUTOFVIDEOMEMORY) { 00588 if (debug) { 00589 printf ("D3DERR_OUTOFVIDEOMEMORY \n"); 00590 } 00591 } 00592 break; 00593 } 00594 } 00595 00596 // free all allocated textures 00597 int index; 00598 for (index = 0; index < total_textures; index++) { 00599 texture_array [index] -> Release ( ); 00600 } 00601 00602 video_memory = (total_textures * 1024 * 1024); 00603 00604 if (debug) { 00605 printf ("video_memory = %d \n", video_memory); 00606 } 00607 00608 texture_memory = direct_3d_device -> GetAvailableTextureMem ( ); 00609 if (debug) { 00610 printf ("texture_memory = %d \n", texture_memory); 00611 } 00612 00613 direct_3d_device -> Release ( ); 00614 00615 state = DisplayInformation::DS_success; 00616 success = true; 00617 } 00618 else 00619 { 00620 if (debug) { 00621 printf ("CreateDevice failed.\n"); 00622 } 00623 00624 state = DisplayInformation::DS_create_device_error; 00625 success = true; 00626 } 00627 00628 DestroyWindow (window_handle); 00629 } 00630 else { 00631 _GetLastError ("CreateWindow"); 00632 state = DisplayInformation::DS_create_window_error; 00633 } 00634 00635 direct_3d -> Release ( ); 00636 } 00637 else { 00638 state = DisplayInformation::DS_direct_3d_create_error; 00639 } 00640 } 00641 else { 00642 state = DisplayInformation::DS_direct_3d_create_error; 00643 } 00644 00645 FreeLibrary (d3d_dll); 00646 } 00647 else { 00648 state = DisplayInformation::DS_direct_3d_create_error; 00649 } 00650 00651 if (success) { 00652 display_information -> _state = state; 00653 display_information -> _get_adapter_display_mode_state = get_adapter_display_mode_state; 00654 display_information -> _get_device_caps_state = get_device_caps_state; 00655 display_information -> _maximum_window_width = window_width; 00656 display_information -> _maximum_window_height = window_height; 00657 display_information -> _window_bits_per_pixel = window_bits_per_pixel; 00658 display_information -> _total_display_modes = total_display_modes; 00659 display_information -> _display_mode_array = display_mode_array; 00660 display_information -> _shader_model = shader_model; 00661 display_information -> _video_memory = video_memory; 00662 display_information -> _texture_memory = texture_memory; 00663 display_information -> _vendor_id = vendor_id; 00664 display_information -> _device_id = device_id; 00665 display_information -> _driver_product = product; 00666 display_information -> _driver_version = version; 00667 display_information -> _driver_sub_version = sub_version; 00668 display_information -> _driver_build = build; 00669 00670 display_information -> _driver_date_month = month; 00671 display_information -> _driver_date_day = day; 00672 display_information -> _driver_date_year = year; 00673 } 00674 00675 // memory 00676 bool memory_state; 00677 HMODULE kernel32_dll; 00678 00679 memory_state = false; 00680 kernel32_dll = LoadLibrary ("kernel32.dll"); 00681 if (kernel32_dll) { 00682 GlobalMemoryStatusExType GlobalMemoryStatusExFunction; 00683 00684 GlobalMemoryStatusExFunction = (GlobalMemoryStatusExType) GetProcAddress (kernel32_dll, "GlobalMemoryStatusEx"); 00685 if (GlobalMemoryStatusExFunction) { 00686 MEMORYSTATUSEX memory_status; 00687 00688 memory_status.dwLength = sizeof (MEMORYSTATUSEX); 00689 if (GlobalMemoryStatusExFunction (&memory_status)) { 00690 physical_memory = memory_status.ullTotalPhys; 00691 available_physical_memory = memory_status.ullAvailPhys; 00692 memory_state = true; 00693 } 00694 } 00695 FreeLibrary (kernel32_dll); 00696 } 00697 if (memory_state == false) { 00698 MEMORYSTATUS memory_status; 00699 00700 memory_status.dwLength = sizeof (MEMORYSTATUS); 00701 GlobalMemoryStatus (&memory_status); 00702 00703 physical_memory = memory_status.dwTotalPhys; 00704 available_physical_memory = memory_status.dwAvailPhys; 00705 } 00706 00707 if (debug) { 00708 printf ("physical_memory %I64d \n", physical_memory); 00709 printf ("available_physical_memory %I64d \n", available_physical_memory); 00710 } 00711 00712 display_information -> _physical_memory = physical_memory; 00713 display_information -> _available_physical_memory = available_physical_memory; 00714 00715 return success; 00716 }