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;

Re: Enumerating USB Ports by Robert

Robert
Mon Sep 20 10:35:30 CDT 2004

I doubt that the others here can fluently read Delphi sources :-)

I have answered your questions on the Borland newsgroup already.
Lets stay there until i cannot help you anymore.

Re: Enumerating USB Ports by Dhiren

Dhiren
Tue Sep 21 07:46:23 CDT 2004

How do I get interface class for USB002?

"Pavel A." <pavel_a@geeklife.com> wrote in message
news:9676081E-FF5A-4AE2-A316-9E708A9C3341@microsoft.com...
> "Dhiren" wrote:
> > If SetupDiClassGuidsFromName is called to get GUID for class "USB",
> > SetupDiEnumInterfaceDevice always return false though there are 4 USB
ports
> > available.
>
> Because "USB" is a setup class and you need an interface class.
>
> --PA
>



Re: Enumerating USB Ports by Robert

Robert
Tue Sep 21 10:30:25 CDT 2004

Dhiren wrote:

> How do I get interface class for USB002?

You do not need to enumerate anything.
CreateFile('\\.\USB002', ...
What to do then is the problem. Probably a DeviceIoControl call.

Re: Enumerating USB Ports by Robert

Robert
Tue Sep 21 11:19:19 CDT 2004

After reading the manual for the printer it is now clear that there is
no USB involved at all.

It is a RS232 printer connected via USB to RS232 adapter.
Printing chars in a special "control" font will trigger actions like
opening the cash drawer which is connected to the printer.

RE: Enumerating USB Ports by pavel_a

pavel_a
Mon Sep 20 12:15:06 CDT 2004

"Dhiren" wrote:
> If SetupDiClassGuidsFromName is called to get GUID for class "USB",
> SetupDiEnumInterfaceDevice always return false though there are 4 USB ports
> available.

Because "USB" is a setup class and you need an interface class.

--PA