获取设备管理器中显卡



2013-05-14 02:59 
Scott Guthrie Liu 
阅读(303
评论(0
编辑 
收藏 
举报

#include <stdio.h>
#include <windows.h>
#include <Setupapi.h>
#include <devguid.h>
#include "tchar.h"

#pragma comment(lib, "SetupAPI.lib")
int main(int argc, char ** argv) 
{
  HDEVINFO deviceInfoSet;
  GUID *guidDev = (GUID*) &GUID_DEVCLASS_DISPLAY; 
  deviceInfoSet = SetupDiGetClassDevs(guidDev, NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
 TCHAR buffer [4000];
  DWORD buffersize =4000;
  int memberIndex = 0;
  while (true) 
  {
   SP_DEVINFO_DATA deviceInfoData;
   ZeroMemory(&deviceInfoData, sizeof(SP_DEVINFO_DATA));
   deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
  if (SetupDiEnumDeviceInfo(deviceInfoSet, memberIndex, &deviceInfoData) == FALSE) 
  {
     if (GetLastError() == ERROR_NO_MORE_ITEMS) 
     {
       break;
     }
   }
   DWORD nSize=0 ;
   SetupDiGetDeviceInstanceId (deviceInfoSet, &deviceInfoData, buffer, sizeof(buffer), &nSize);
   buffer [nSize] =\'\0\';
   _tprintf (_T("%s\n"), buffer);
   BOOL res = SetupDiGetDeviceRegistryProperty(deviceInfoSet, &deviceInfoData,SPDRP_DEVICEDESC, 0, (BYTE*) buffer, sizeof(buffer), NULL);
   buffer [nSize] =\'\0\';
   _tprintf (_T("%s\n"), buffer);
   memberIndex++;
  }
  if (deviceInfoSet) 
  {
   SetupDiDestroyDeviceInfoList(deviceInfoSet);
  }
  return 0;
}

View Code

 http://www.codeproject.com/Articles/6597/CDeviceTree

http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/2555943e-0c69-4357-a85b-d6540bcaaf84

版权声明:本文为logitechlike原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/logitechlike/archive/2013/05/14/3077047.html