@@ -326,77 +326,34 @@ long long SharedUtil::GetWMITotalPhysicalMemory()
326
326
//
327
327
//
328
328
// ///////////////////////////////////////////////////////////////////
329
- unsigned int SharedUtil::GetWMIVideoAdapterMemorySize (const SString& strDisplay )
329
+ unsigned int SharedUtil::GetWMIVideoAdapterMemorySize (const unsigned long ulVen, const unsigned long ulDev )
330
330
{
331
- // This won't change after the first call
332
- static unsigned int uiResult = 0 ;
333
-
334
- if (uiResult == 0 )
335
- {
336
- SString strDeviceId;
337
-
338
- // Find a device id for the display
339
- for (int i = 0 ; true ; i++)
340
- {
341
- DISPLAY_DEVICE device;
342
- device.cb = sizeof (device);
331
+ unsigned int uiResult = 0 ;
343
332
344
- // Get next DISPLAY_DEVICE from the system
345
- if (!EnumDisplayDevicesA (NULL , i, &device, 0 ))
346
- break ;
333
+ SString DevVen;
334
+ DevVen.Format (" VEN_%04X&DEV_%04X" , ulVen, ulDev);
347
335
348
- // Calc flags
349
- bool bAttachedToDesktop = (device. StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0 ;
350
- bool bMirroringDriver = (device. StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) != 0 ;
336
+ // Get WMI info about all video controllers
337
+ SQueryWMIResult result ;
338
+ QueryWMI (result, " Win32_VideoController " , " PNPDeviceID,AdapterRAM,Availability " ) ;
351
339
352
- // Only check attached, non mirror displays
353
- if (bAttachedToDesktop && !bMirroringDriver)
354
- {
355
- if (strDisplay.CompareI (device.DeviceName ))
356
- {
357
- // Found a match
358
- strDeviceId = device.DeviceID ;
359
- break ;
360
- }
361
- }
362
- }
340
+ // Check each controller for a device id match
341
+ for (uint i = 0 ; i < result.size (); i++)
342
+ {
343
+ const SString& PNPDeviceID = result[i][0 ];
344
+ const SString& AdapterRAM = result[i][1 ];
345
+ const SString& Availability = result[i][2 ];
363
346
364
- // Get WMI info about all video controllers
365
- SQueryWMIResult result;
366
- QueryWMI (result, " Win32_VideoController" , " PNPDeviceID,AdapterRAM,Availability" );
347
+ unsigned int uiAdapterRAM = atoi (AdapterRAM);
348
+ int iAvailability = atoi (Availability);
367
349
368
- // Check each controller for a device id match
369
- for (uint i = 0 ; i < result.size (); i++)
350
+ if ((iAvailability == 8 || iAvailability == 3 ) && PNPDeviceID.Contains (DevVen))
370
351
{
371
- const SString& PNPDeviceID = result[i][0 ];
372
- const SString& AdapterRAM = result[i][1 ];
373
- const SString& Availability = result[i][2 ];
374
-
375
- unsigned int uiAdapterRAM = atoi (AdapterRAM);
376
- int iAvailability = atoi (Availability);
377
-
378
- if (uiResult == 0 )
379
- uiResult = uiAdapterRAM;
380
-
381
- if (iAvailability == 3 )
382
- uiResult = std::max (uiResult, uiAdapterRAM);
383
-
384
- if (uiAdapterRAM != 0 )
385
- {
386
- // If this matches the previously found device, return the adapter RAM
387
- if (!strDeviceId.empty () && PNPDeviceID.BeginsWithI (strDeviceId))
388
- {
389
- uiResult = uiAdapterRAM;
390
- break ; // Found match
391
- }
392
- }
352
+ uiResult = uiAdapterRAM;
353
+ break ; // Found match
393
354
}
394
355
}
395
356
396
- if (uiResult == 0 )
397
- {
398
- uiResult = 2LL * 1024 * 1024 * 1024 ; // 2GB
399
- }
400
357
return uiResult;
401
358
}
402
359
0 commit comments