1. #include <Windows.h> 
  2. #include <SetupAPI.h> 
  3. #include <stdio.h> 
  4. #include <devguid.h> 
  5. #include <RegStr.h> 
  6.  
  7. BOOL EnumDeviceInterface(const GUID * InterfaceClassGUID){ 
  8.     HDEVINFO DeviceInfoSet; 
  9.     HDEVINFO NewDeviceInfoSet; 
  10.     SP_DEVICE_INTERFACE_DATA DeviceInterfaceData; 
  11.     PSP_DEVICE_INTERFACE_DETAIL_DATA lpDeviceInterfaceDetailData; 
  12.     DWORD dwBufferSize = 0; 
  13.     DWORD i; 
  14.  
  15.     DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL,NULL); 
  16.     if(DeviceInfoSet == INVALID_HANDLE_VALUE){ 
  17.         printf("Create device interface failed.(%d)\n",GetLastError()); 
  18.         return 0; 
  19.     } 
  20.     NewDeviceInfoSet = SetupDiGetClassDevsEx(InterfaceClassGUID,NULL,NULL,DIGCF_DEVICEINTERFACE|DIGCF_PRESENT,DeviceInfoSet,NULL,NULL); 
  21.     if(NewDeviceInfoSet == INVALID_HANDLE_VALUE){ 
  22.         printf("Get device interface infomation failed."); 
  23.         return 0; 
  24.     } 
  25.     DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData); 
  26.     for(i=0;;i++){ 
  27.         BOOL bResult = SetupDiEnumDeviceInterfaces(NewDeviceInfoSet,NULL,InterfaceClassGUID,i,&DeviceInterfaceData); 
  28.         if(!bResult){ 
  29.             if(bResult != NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS){ 
  30.                 printf("ERROR:%d\n",GetLastError()); 
  31.                 return FALSE; 
  32.             } 
  33.             break
  34.         }else
  35.             lpDeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)HeapAlloc(GetProcessHeap(),0,sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA)); 
  36.             lpDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); 
  37.             dwBufferSize = lpDeviceInterfaceDetailData->cbSize; 
  38.             while(!SetupDiGetDeviceInterfaceDetail(NewDeviceInfoSet,&DeviceInterfaceData,lpDeviceInterfaceDetailData,dwBufferSize,&dwBufferSize,NULL)){ 
  39.                 if(ERROR_INSUFFICIENT_BUFFER == GetLastError()){ 
  40.                     lpDeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)HeapReAlloc(GetProcessHeap(),0,lpDeviceInterfaceDetailData,dwBufferSize); 
  41.                     lpDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); 
  42.                 } 
  43.             } 
  44.             printf("DevicePath:%s\n",lpDeviceInterfaceDetailData->DevicePath); 
  45.             HeapFree(GetProcessHeap(),0,lpDeviceInterfaceDetailData); 
  46.         } 
  47.     } 
  48.     return TRUE; 
  49.  
  50. int main(int argc,char * argv[],char *envp[]){ 
  51.     printf("Get device interface information.\n"); 
  52.     EnumDeviceInterface(&GUID_DEVINTERFACE_DISK); 
  53.     return 0;