[DUG] USB device information
Tom Munro Glass
gentoo at tmgcon.com
Thu Jul 21 17:56:30 NZST 2005
Thanks guys, this is just what I needed. One more question - where do you find
out the GUIDs for different types of devices?
Tom
On Thu, 21 Jul 2005 16:49, Stefan Mueller wrote:
> Try GUID_CLASS_USB_DEVICE: TGUID =
> '{A5DCBF10-6530-11D2-901F-00C04FB951ED}' to enumerate all USB devices, not
> only the Garmin usb devices.
>
> .. or pass DIGCF_ALLCLASSES flag to the SetupDiGetClassDevsEx function (but
> then you get all device handlers, not just for usb).
>
> Regards,
> Stefan
>
>
>
> -----Original Message-----
> From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz] On
> Behalf Of Phil Middlemiss
> Sent: Thursday, July 21, 2005 4:07 PM
> To: NZ Borland Developers Group - Delphi List
> Subject: Re: [DUG] USB device information
>
> Here is some code that we use to scan for Garmin USB GPS devices. You
> will have to adapt it to your purposes, but it should give you an idea
> of the routines you need to use, and the order in which you need to use
> them:
>
> { scan for USB devices }
> deviceinfoset := SetupDiCreateDeviceInfoList(nil, 0);
> if (DWORD(deviceinfoset) <> INVALID_HANDLE_VALUE) then
> try
> // Retrieve the device information set for the interface class.
> guid := GUID_DEVINTERFACE_GRMNUSB;
> aguid := @GUID_DEVINTERFACE_GRMNUSB;
> newdeviceinfoset := SetupDiGetClassDevsEx(aguid, nil, 0,
> DIGCF_PRESENT or DIGCF_DEVICEINTERFACE,
> deviceinfoset, nil, nil);
> if(DWORD(newdeviceinfoset) <> INVALID_HANDLE_VALUE) then
> try
> { enumerate the devices }
> aindex := 0;
> while True do
> begin
> infodata.cbSize := SizeOf(TSPDevInfoData);
> { for each device }
> if SetupDiEnumDeviceInfo(newdeviceinfoset, aindex, infodata) then
> begin
> pinfodata := @infodata;
> bindex := 0;
> while True do
> begin
> { for each interface }
> interfacedata.cbSize := SizeOf(TSPDeviceInterfaceData);
> if SetupDiEnumDeviceInterfaces(newdeviceinfoset,
> pinfodata, guid, bindex, interfacedata) then
> begin
> pinterfacedata := @interfacedata;
> preqsize := @reqsize;
> { get the buffer size }
> if (not
> SetupDiGetDeviceInterfaceDetail(newdeviceinfoset, pinterfacedata, nil, 0,
> preqsize, nil)) and (GetLastError =
> ERROR_INSUFFICIENT_BUFFER) then
> begin
> { allocate the buffer }
> pdetaildata := AllocMem(reqsize);
> pdetaildata.cbSize :=
> SizeOf(TSPDeviceInterfaceDetailData);
> { get the details }
> try
> if SetupDiGetDeviceInterfaceDetail(newdeviceinfoset,
> pinterfacedata, pdetaildata, Cardinal(reqsize),
> preqsize, pinfodata) then
> begin
> { check if the device has already been found }
> apath := PChar(@pdetaildata.DevicePath);
> alreadyfound := False;
> for i := 0 to High(foundevices) do
> begin
> alreadyfound := foundevices[i].path = apath;
> if alreadyfound then
> begin
> foundevices[i].found := True;
> break;
> end;
> end;
> if alreadyfound then
> begin
> Inc(bindex);
> continue;
> end;
> { add the device }
>
> <snip>
>
> finally
> FreeMem(pdetaildata);
> end;
> end;
> end
> else
> begin
> anerror := GetLastError;
> if anerror = ERROR_NO_MORE_ITEMS then
> break;
> end;
> Inc(bindex);
> end;
> end
> else
> begin
> anerror := GetLastError;
> if anerror = ERROR_NO_MORE_ITEMS then
> break;
> end;
> Inc(aindex);
> end;
> finally
> SetupDiDestroyDeviceInfoList(newdeviceinfoset);
> end;
> finally
> SetupDiDestroyDeviceInfoList(deviceinfoset);
> end;
>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
More information about the Delphi
mailing list