[DUG] USB device information

Phil Middlemiss phil at tumonz.co.nz
Fri Jul 22 11:55:30 NZST 2005


The arguments for the DeviceIOControl call will be specific to the 
device I think (at least the were with the Garmin devices), so it is 
probably a case of looking for an SDK for the hardware. But I don't 
think you need to necessarily call DeviceIOControl to get the 
information, you could probably get the information out of the registry 
using
SetupDiGetDeviceRegistryProperty - one of the routines I use is below:

function TGarminUSBDevice.GetRegistryPropertyString(PnPHandle: HDEVINFO;
  const DevData: TSPDevInfoData; Prop: DWORD): string;
var
  bytesreturned: DWORD;
  regdatatype:   DWORD;
  buffer:        array [0..256] of Char;
  adevdata : TSPDevInfoData;
begin
  bytesreturned := 0;
  regdatatype   := 0;
  buffer[0]     := #0;
  adevdata := DevData;
  SetupDiGetDeviceRegistryProperty(PnPHandle, adevdata, Prop,
    @regdatatype, PBYTE(@buffer[0]), SizeOf(buffer), @bytesreturned);
  result := buffer;
end;

which I then call like this:
  // primary information
  FCapabilities    := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_CAPABILITIES);
  FClassDescr      := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_CLASS);
  FClassGUID       := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_CLASSGUID);
  FCompatibleIDs   := GetRegistryPropertyStringList(APnPHandle, 
ADevData, SPDRP_COMPATIBLEIDS);
  FConfigFlags     := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_CONFIGFLAGS);
  FDeviceDescr     := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_DEVICEDESC);
  FDriver          := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_DRIVER);
  FFriendlyName    := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_FRIENDLYNAME);
  FHardwareID      := GetRegistryPropertyStringList(APnPHandle, 
ADevData, SPDRP_HARDWAREID);
  FLowerFilters    := GetRegistryPropertyStringList(APnPHandle, 
ADevData, SPDRP_LOWERFILTERS);
  FMfg             := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_MFG);
  FUpperFilters    := GetRegistryPropertyStringList(APnPHandle, 
ADevData, SPDRP_UPPERFILTERS);
  FService         := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_SERVICE);

  // secondary information not all likely to exist for a HID device
  FAddress         := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_ADDRESS);
  FBusNumber       := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_BUSNUMBER);
  FBusType         := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_BUSTYPEGUID);
  FCharacteristics := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_CHARACTERISTICS);
  FDevType         := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_DEVTYPE);
  FEnumeratorName  := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_ENUMERATOR_NAME);
  FExclusive       := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_EXCLUSIVE);
  FLegacyBusType   := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_LEGACYBUSTYPE);
  FLocationInfo    := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_LOCATION_INFORMATION);
  FPhysDevObjName  := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_PHYSICAL_DEVICE_OBJECT_NAME);
  FSecuritySDS     := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_SECURITY_SDS);
  FUINumber        := GetRegistryPropertyDWord     (APnPHandle, 
ADevData, SPDRP_UI_NUMBER);
  FUINumberFormat  := GetRegistryPropertyString    (APnPHandle, 
ADevData, SPDRP_UI_NUMBER_DESC_FORMAT);

I have similar versions for DWord and StringList aswell.

Phil.

Tom Munro Glass wrote:

>OK, I've managed to get to the point where I've got a device path, and I 
>understand that I'm meant to open that with CreateFile. Unfortunately this 
>isn't working, I get the message "A device attached to the system is not 
>functioning". 
>
>If I manage to get CreateFile to work, what do I do next to retrieve the 
>details from the device, I'd guess a DeviceIOControl call but I don't know 
>what arguments to use.
>
>If anyone can provide more details, I'd be grateful. By the way, I need this 
>to work on Win2K if that makes any difference.
>
>Tom
>


More information about the Delphi mailing list