41#include <wx/msw/registry.h>
55 std::string ConvertWCSToMBS(
const wchar_t* pstr,
long wslen )
57 int len = ::WideCharToMultiByte( CP_ACP, 0, pstr, wslen, NULL, 0, NULL, NULL );
59 std::string dblstr( len,
'\0' );
60 len = ::WideCharToMultiByte( CP_ACP, 0 , pstr,
61 wslen , &dblstr[0], len, NULL,
68 std::string ConvertBSTRToMBS( BSTR bstr )
70 int wslen = ::SysStringLen( bstr );
71 return ConvertWCSToMBS( (
wchar_t*) bstr, wslen );
75 BSTR ConvertMBSToBSTR(
const std::string& str )
77 int wsLen = ::MultiByteToWideChar( CP_ACP, 0 , str.data(), str.length(), NULL,
80 BSTR wsData = ::SysAllocStringLen( NULL, wsLen );
81 if( ::MultiByteToWideChar( CP_ACP, 0 ,
88 ::SysFreeString( wsData );
114 hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator,
119 throw std::runtime_error(
"Failed to create IWbemLocator object." );
126 hres =
m_pLoc->ConnectServer( ConvertMBSToBSTR(
"ROOT\\CIMV2" ),
139 throw std::runtime_error(
"Could not connect to root\\cimv2." );
143 hres = CoSetProxyBlanket(
m_pSvc,
147 RPC_C_AUTHN_LEVEL_CALL,
148 RPC_C_IMP_LEVEL_IMPERSONATE,
157 throw std::runtime_error(
"Could not set proxy blanket." );
189 const std::string& aVersion )
191 if( aManufacturer.find(
"NVIDIA" ) != std::string::npos
192 || aManufacturer.find(
"Nvidia" ) != std::string::npos )
194 std::istringstream versionStream( aVersion );
196 std::vector<std::string> versionBits;
197 while( getline( versionStream, s,
'.' ) )
199 versionBits.push_back( s );
202 if( versionBits.size() == 4 )
204 unsigned int numChars2 = versionBits[2].length();
205 unsigned int numChars3 = versionBits[2].length();
206 if( numChars2 >= 1 && numChars3 >= 2 )
210 versionBits[3].insert( 0, ( 4 - versionBits[3].size() ),
'0' );
215 std::string major1 = versionBits[2].substr( numChars2 - 1, numChars2 - 1 );
216 std::string major2 = versionBits[3].substr( 0, 1 );
217 std::string major = major1 + major2;
218 std::string minor = versionBits[3].substr( 2, numChars3 - 1 );
221 return major +
"." + minor;
231 MEMORYSTATUSEX statex;
233 statex.dwLength =
sizeof( statex );
235 if( GlobalMemoryStatusEx( &statex ) != 0 )
237 aMemoryInfo.
Usage = statex.dwMemoryLoad;
241 aMemoryInfo.
FreePaging = statex.ullAvailPageFile;
257 IWbemClassObject* processors[2];
259 ConvertMBSToBSTR(
"WQL" ), ConvertMBSToBSTR(
"SELECT * FROM Win32_Processor" ),
260 WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 0, &
m_pEnumerator );
262 if( SUCCEEDED( hres ) )
264 hres =
m_pEnumerator->Next( WBEM_INFINITE, 2, processors, &returned );
265 if( FAILED( hres ) || returned == 0 )
274 std::string chRetValue =
"";
275 for( UINT ctrlIndex = 0; ctrlIndex < returned; ctrlIndex++ )
277 IWbemClassObject* processor = processors[ctrlIndex];
280 hres = processor->Get( ConvertMBSToBSTR(
"Name" ), 0, &var, NULL, NULL );
281 if( SUCCEEDED( hres ) )
284 cpuInfo.Name = chRetValue;
286 VariantClear( &var );
287 processor->Get( ConvertMBSToBSTR(
"Manufacturer" ), 0, &var, NULL, NULL );
289 cpuInfo.Manufacturer = chRetValue;
291 VariantClear( &var );
292 processor->Get( ConvertMBSToBSTR(
"NumberOfCores" ), 0, &var, NULL, NULL );
294 long long cores = atoll( chRetValue.c_str() );
295 cpuInfo.NumberCores = cores;
297 VariantClear( &var );
298 processor->Get( ConvertMBSToBSTR(
"NumberOfLogicalProcessors" ), 0, &var, NULL, NULL );
300 long long logical = atoll( chRetValue.c_str() );
301 cpuInfo.NumberLogical = logical;
304 aCpuInfos.push_back( cpuInfo );
307 VariantClear( &var );
317 wxString baseKeyName =
"SOFTWARE\\Microsoft\\DirectX";
318 wxRegKey key( wxRegKey::HKLM, baseKeyName );
321 if( key.HasSubkeys() )
323 wxString adapterGuid;
325 for(
bool cont = key.GetFirstKey( adapterGuid, index ); cont;
326 cont = key.GetNextKey( adapterGuid, index ) )
328 wxString subKeyName = baseKeyName +
"\\" + adapterGuid;
331 status = ::RegOpenKeyEx(
332 (HKEY) HKEY_LOCAL_MACHINE, subKeyName.t_str(), 0, KEY_READ, &tmpKey );
334 ULONGLONG adapterLuid;
335 DWORD dwType, dwSize =
sizeof(ULONGLONG);
336 status = ::RegQueryValueEx((HKEY)tmpKey, L
"AdapterLuid",
338 &dwType, (LPBYTE)&adapterLuid, &dwSize);
340 if (status != ERROR_SUCCESS)
342 ::RegCloseKey(tmpKey);
347 if ( dwType != REG_QWORD_LITTLE_ENDIAN && dwType != REG_QWORD ) {
348 ::RegCloseKey(tmpKey);
352 if (adapterLuid != aAdapterLuid)
354 ::RegCloseKey(tmpKey);
358 ULONGLONG driverVersion;
359 status = ::RegQueryValueEx((HKEY)tmpKey, L
"DriverVersion",
361 &dwType, (LPBYTE)&driverVersion, &dwSize);
363 if (status != ERROR_SUCCESS)
365 ::RegCloseKey(tmpKey);
370 if ( dwType != REG_QWORD_LITTLE_ENDIAN && dwType != REG_QWORD ) {
371 ::RegCloseKey(tmpKey);
375 std::stringstream fmt;
376 fmt << ( ( driverVersion >> 48 ) & 0xFFFF ) <<
"."
377 << ( ( driverVersion >> 32 ) & 0xFFFF ) <<
"."
378 << std::to_string( ( driverVersion >> 16 ) & 0xFFFF ) <<
"."
379 << std::to_string( driverVersion & 0xFFFF );
380 aDriverVersion = fmt.str();
382 ::RegCloseKey(tmpKey);
393 typedef HRESULT( WINAPI * LPCREATEDXGIFACTORY )( REFIID,
void** );
394 LPCREATEDXGIFACTORY pCreateDXGIFactory = NULL;
395 HMODULE hDXGI = NULL;
397 hDXGI = LoadLibrary( L
"dxgi.dll" );
404 IID iid_IDXGIFactory;
407 IIDFromString( L
"{7b7166ec-21c7-44ae-b21a-c9ae321ae369}", &iid_IDXGIFactory );
409 IDXGIAdapter* pAdapter = NULL;
410 pCreateDXGIFactory = (LPCREATEDXGIFACTORY) GetProcAddress( hDXGI,
"CreateDXGIFactory" );
411 if( pCreateDXGIFactory )
413 IDXGIFactory* pDXGIFactory;
414 HRESULT hr = pCreateDXGIFactory( iid_IDXGIFactory, (
void**) &pDXGIFactory );
415 if( SUCCEEDED( hr ) )
418 while( pDXGIFactory->EnumAdapters( adapter, &pAdapter ) != DXGI_ERROR_NOT_FOUND )
420 DXGI_ADAPTER_DESC desc;
421 hr = pAdapter->GetDesc( &desc );
422 if( SUCCEEDED( hr ) )
425 if( desc.VendorId == 5140 && desc.DeviceId == 140 )
432 char descriptionBuffer[260];
433 char defaultChar =
' ';
434 WideCharToMultiByte( CP_ACP, 0, desc.Description, -1, descriptionBuffer,
435 sizeof( descriptionBuffer ), &defaultChar, NULL );
437 gpuInfo.
Name = descriptionBuffer;
441 gpuInfo.
MemorySize = desc.DedicatedVideoMemory;
443 int64_t luid = ( ( (int64_t) desc.AdapterLuid.HighPart ) << 32 )
444 | desc.AdapterLuid.LowPart;
451 aGpuInfos.push_back( gpuInfo );
457 pDXGIFactory->Release();
461 FreeLibrary( hDXGI );
481 char returnBuffer[256];
487 aReturnString = ConvertBSTRToMBS( aVar->bstrVal );
492 if( VARIANT_TRUE == aVar->boolVal )
493 aReturnString =
"true";
495 aReturnString =
"false";
500 sprintf_s( returnBuffer,
sizeof( returnBuffer ) - 1,
"%u", aVar->uintVal );
502 aReturnString = returnBuffer;
507 sprintf_s( returnBuffer,
sizeof( returnBuffer ) - 1,
"%u", aVar->uintVal );
508 aReturnString = returnBuffer;
513 sprintf_s( returnBuffer,
sizeof( returnBuffer ) - 1,
"%u", aVar->uintVal );
514 aReturnString = returnBuffer;
517 case VT_BSTR | VT_ARRAY:
520 hr = SafeArrayAccessData( aVar->parray, (
void**) &raw );
522 const _bstr_t bstr( raw[0] );
523 hr = SafeArrayUnaccessData( aVar->parray );
525 aReturnString = ConvertBSTRToMBS( bstr );
528 case VT_I4 | VT_ARRAY:
532 SafeArrayGetLBound( aVar->parray, 1, &low );
533 SafeArrayGetUBound( aVar->parray, 1, &high );
535 hr = SafeArrayAccessData( aVar->parray, (
void HUGEP**) &pBuf );
536 hr = SafeArrayUnaccessData( aVar->parray );
538 high = std::min( high, (
long) MAX_PATH * 2 - 1 );
539 for( LONG i = low; i <= high; ++i )
541 sprintf_s( returnBuffer,
sizeof( returnBuffer ) - 1,
"%02X", pBuf[i] );
542 aReturnString += returnBuffer;