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