Hi,
If SetupDiClassGuidsFromName is called to get GUID for class "USB",
SetupDiEnumInterfaceDevice always return false though there are 4 USB ports
available.
and if SetupDiClassGuidsFromName is called to get GUID for class "Ports",
its listing only 2 though there are 4 USB ports. (Devices are attached in
both the cases.)
Sample Code:
----------------------------------------------------------------------------
------------------------------------------------------------------------
var
RequiredSize: Cardinal;
vDeviceList : OleVariant
Guid: TGUID;
DevInfoHandle: HDEVINFO;
// Comments
DeviceInfoData: TSPDevInfoData;
MemberIndex: Cardinal;
PropertyRegDataType: DWord;
RegProperty: Cardinal;
RegTyp: Cardinal;
Key: Hkey;
Info: TRegKeyInfo;
S1,S2: string;
hc: THandle;
hLib : HINST;
needed : DWORD;
hINfo : HDEVINFO;
Interface_Info : TSPDeviceInterfaceData;
interface_detail : PSPDeviceInterfaceDetailData;
sdname : pChar;
strDeviceName : String;
vattachedUSBList : OleVariant;
slDynamicBuil : TStringList;
begin
try
try
if SetupDiClassGuidsFromName('Ports',@Guid,RequiredSize,RequiredSize)
then // get 'Ports' class guid from name
begin
DevInfoHandle
:=SetupDiGetClassDevs(@Guid,Nil,0,DIGCF_INTERFACEDEVICE);//());//get object
handle of 'Ports' class to interate all devices
if Cardinal(DevInfoHandle)<>Invalid_Handle_Value then
begin
try
MemberIndex:=0;
repeat //iterate device list
Interface_Info.cbSize := SizeOf(_SP_DEVICE_INTERFACE_DATA);
//28; //SizeOf(Interface_Info) 28;
if (not SetupDiEnumInterfaceDevice(DevInfoHandle,
nil,Guid,MemberIndex,Interface_Info)) then
begin
SetupDiDestroyDeviceInfoList(DevInfoHandle);
break;
end;
SetupDiGetInterfaceDeviceDetail(DevInfoHandle,
@Interface_Info, nil, 0, @needed, nil);
interface_detail := AllocMem(needed);
interface_detail.cbSize :=
SizeOf(_SP_DEVICE_INTERFACE_DETAIL_DATA_A); //5; //SizeOf(interface_detail)
5;
SetupDiGetInterfaceDeviceDetail(DevInfoHandle,@Interface_Info,interface_deta
il, needed,@needed, 0);
sdName := StrAlloc(MAX_PATH);
StrCopy(sdName,interface_detail.DevicePath);
VarArrayRedim(vDeviceList,MemberIndex);
vDeviceList[MemberIndex] := StrPas(sdName);
FreeMemory(interface_detail);
Inc(MemberIndex);
until False;
finally
SetupDiDestroyDeviceInfoList(DevInfoHandle);
end;
end;
end;
finally
// Result := vUSBList;
end;
except
on E:Exception do
ShowMessage(e.Message);
end;