2017-03-09 9 views

답변

0

DEVINST dnDevInst 당신은 예를 들어 CM_Get_Device_ID_ListW + CM_Locate_DevNode 또는 대체 사용 CM_Locate_DevNode + CM_Get_Child + CM_Get_Sibling

모든 장치를 열거 할 수 얻을 당신이 CM_Get_DevNode_Status

전화를 필요로하는 장치의 상태를 얻을 수에 대한 :

void enumDN(DEVINST dnDevInst) 
{ 
    union { 
     PVOID buf; 
     PBYTE pb; 
     PWSTR sz; 
    }; 

    ULONG cb = 0, rcb = 256; 

    static volatile UCHAR guz; 

    PVOID stack = alloca(guz); 

    WCHAR Name[MAX_DEVICE_ID_LEN]; 

    CONFIGRET err; 

    if (CM_Get_Device_ID(dnDevInst, Name, RTL_NUMBER_OF(Name), 0) == CR_SUCCESS) 
    { 
     DEVPROPTYPE PropertyType; 
     ULONG Status, ulProblemNumber; 

     if (CM_Get_DevInst_Status(&Status, &ulProblemNumber, dnDevInst, 0) == CR_SUCCESS) 
     { 
      PWSTR FriendlyName = NULL; 
      do 
      { 
       if (cb < rcb) 
       { 
        rcb = cb = RtlPointerToOffset(buf = alloca(rcb - cb), stack); 
       } 

       if ((err = CM_Get_DevNode_PropertyW(dnDevInst, &DEVPKEY_Device_FriendlyName, 
        &PropertyType, pb, &rcb, 0)) == CR_SUCCESS) 
       { 
        if (PropertyType == DEVPROP_TYPE_STRING) 
        { 
         FriendlyName = sz; 
        } 
       } 

      } while (err == CR_BUFFER_SMALL); 

      DbgPrint("%08x %S %S\n", Status, Name, FriendlyName); 
     } 
    } 

    if ((err = CM_Get_Child(&dnDevInst, dnDevInst, 0)) == CR_SUCCESS) 
    { 
     do 
     { 
      enumDN(dnDevInst); 

     } while ((err = CM_Get_Sibling(&dnDevInst, dnDevInst, 0)) == CR_SUCCESS); 
    } 
} 

void enumDN() 
{ 
    DEVINST dnDevInst; 
    if (CM_Locate_DevInstW(&dnDevInst, NULL, 0) == CR_SUCCESS) 
    { 
     enumDN(dnDevInst); 
    } 
}