const
MAX_PATH = 260;
//--------------------------------------------------------------
// Configuration Manager return status codes
//--------------------------------------------------------------
CR_SUCCESS =$00000000;
type
//
// Define type for reference to device information set
//
THDEVINFO = Pointer;
//
// Device information structure (references a device instance
// that is a member of a device information set)
//
PSP_DevInfo_Data = ^TSP_DevInfo_Data;
SP_DEVINFO_DATA =
packed record
cbSize: DWORD;
ClassGuid: TGUID;
DevInst: DWORD;
// DEVINST handle
Reserved: LongWord;
end;
TSP_DevInfo_Data = SP_DEVINFO_DATA;
PDEVPROPKEY = ^TDEVPROPKEY;
DEVPROPKEY =
packed record
fmtid : TGUID ;
pid : Pointer;
end;
TDEVPROPKEY = DEVPROPKEY;
DEVPROPTYPE = Pointer;
PCWSTR = PWCHAR;
TDEVINST = DWord;
TPOSVERSIONINFOW = ^TOSVERSIONINFOW;
TOSVERSIONINFOW =
packed record
dwOSVersionInfoSize : DWORD ;
dwMajorVersion : DWORD ;
dwMinorVersion : DWORD ;
dwBuildNumber : DWORD ;
dwPlatformId : DWORD ;
szCSDVersion :
array[0..127]
of wchar;
end;
function SetupDiGetDeviceProperty(DeviceInfoSet: THDEVINFO; DeviceInfoData: PSP_DEVINFO_DATA;
const PropertyKey: PDEVPROPKEY;
var PropertyType:DEVPROPTYPE; PropertyBuffer:PBYTE;PropertyBufferSize:DWORD; RequiredSize:PDWORD; Flags:DWORD): BOOL;
stdcall;
external '
Setupapi.DLL'
name '
SetupDiGetDevicePropertyW';
function SetupDiGetClassDevsW(
const ClassGuid: PGUID; Enumerator: PCWSTR; hwndParent: HWND; Flags: DWORD): THDEVINFO;
stdcall;
external '
Setupapi.DLL'
name '
SetupDiGetClassDevsW';
function SetupDiEnumDeviceInfo(DeviceInfoSet: THDEVINFO; MemberIndex: DWORD; DeviceInfoData: PSP_DEVINFO_DATA): BOOL;
stdcall;
external '
Setupapi.DLL'
name '
SetupDiEnumDeviceInfo';
function CM_Get_Device_IDW(DeviceInstanceHandle: TDEVINst; Buffer:PCWSTR; Bufferlen : ULONG; ulFlags:ULONG): DWORD;
stdcall;
external '
Setupapi.DLL'
name '
CM_Get_Device_IDW';
function SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet: THDEVINFO;
const DeviceInfoData: SP_DevInfo_Data; Property_: DWORD;
var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD;
var RequiredSize: DWORD): BOOL;
stdcall;
external '
Setupapi.DLL'
name '
SetupDiGetDeviceRegistryPropertyW';
function GetVersionExW(OsVersion:TPOSVERSIONINFOW): BOOL;
stdcall;
external '
Kernel32.dll'
name '
GetVersionExW';
//
// Flags controlling what is included in the device information set built
// by SetupDiGetClassDevs
//
const // DIGCF_DEFAULT = $00000001; // only valid with DIGCF_DEVICEINTERFACE
DIGCF_PRESENT = $00000002;
DIGCF_ALLCLASSES = $00000004;
DIGCF_PROFILE = $00000008;
DIGCF_DEVICEINTERFACE = $00000010;
INVALID_HANDLE_VALUE = DWORD($FFFFFFFF);
MAX_DEVICE_ID_LEN = 200;
SPDRP_DEVICEDESC = ($00000000) ;
// DeviceDesc (R/W) ;
DEVPKEY_Device_BusReportedDeviceDesc : TDEVPROPKEY = (fmtid : '
{540b947e-8b40-45bc-a8a2-6a0b894cbda2}' ; pid : pointer(4) );
// DEVPROP_TYPE_STRING
procedure TForm1.Button1Click(Sender: TObject);
var GUID_CAM : TGUID;
hDevInfo : THDEVINFO ;
DeviceInfoData : TSP_DEVINFO_DATA ;
PDeviceInfoData : PSP_DEVINFO_DATA ;
successful : Bool;
i,r:DWORD;
Buffer:
array [0..MAX_DEVICE_ID_LEN]
of WCHAR;
dwSize, dwPropertyRegDataType : DWORD;
szDesc :
array[0..1023]
of char;
OsVersion : TOSVERSIONINFOW;
BusReportedDescr_Key : TDEVPROPKEY;
ulPropertyType : DEVPROPTYPE;
begin
GUID_CAM := StringToGUID('
{6bdd1fc6-810f-11d0-bec7-08002be2092f}');
// [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}] > "Class"="Image"
hDevInfo := SetupDiGetClassDevsW (@GUID_CAM,
nil, 0, DIGCF_PRESENT);
if dword(hDevInfo)<>INVALID_HANDLE_VALUE
then
begin
Listbox1.Items.Add('
hDevInfo : '+inttohex(dword(hDevInfo),8));
i:=0;
PDeviceInfoData := @DeviceInfoData;
repeat
DeviceInfoData.cbSize := sizeof(TSP_DEVINFO_DATA);
successful := SetupDiEnumDeviceInfo(hDevInfo, i, @DeviceInfoData);
if successful
then
begin
r := CM_Get_Device_IDW(DeviceInfoData.DevInst,@Buffer , MAX_PATH, 0);
if r = CR_SUCCESS
then
begin
Listbox1.Items.Add('
CM_GET_DEVICE : '+widechartostring(@Buffer));
if (SetupDiGetDeviceRegistryPropertyW (hDevInfo, DeviceInfoData, SPDRP_DEVICEDESC, dwPropertyRegDataType, @szDesc, sizeof(szDesc), dwSize))
then
begin
Listbox1.Items.Add('
SetupDiGetDeviceRegistryPropertyW : '+widechartostring(@szDesc));
OsVersion.dwOSVersionInfoSize := sizeof(TOSVERSIONINFOW);
if (GetVersionExW(@OsVersion))
then
begin
Listbox1.Items.Add('
GetVersionExW : '+widechartostring(@OsVersion.szCSDVersion));
if (OsVersion.dwBuildNumber > 7000)
then
begin // mind. Windows Vista
Listbox1.Items.Add('
GetVersionExW : >= Windows Vista');
if (SetupDiGetDeviceProperty (hDevInfo, @DeviceInfoData, @DEVPKEY_Device_BusReportedDeviceDesc, ulPropertyType, @szDesc, sizeof(szDesc), @dwSize,0))
then
begin
Listbox1.Items.Add('
SetupDiGetDeviceProperty : BusReportedDescription = "'+widechartostring(@szDesc)+'
"');
end else Listbox1.Items.Add('
SetupDiGetDeviceProperty : ERROR ');
end else Listbox1.Items.Add('
GetVersionExW : < Windows Vista ');
end else Listbox1.Items.Add('
GetVersionExW : ERROR ');
end else Listbox1.Items.Add('
SetupDiGetDeviceRegistryPropertyW : ERROR ');
end else Listbox1.Items.Add('
CM_GET_DEVICE : ERROR ('+inttohex(r,8)+'
)');
inc(i);
end ;
until not successful;
end else Listbox1.Items.Add('
hDevInfo : ERROR ('+inttohex(dword(hDevInfo),8)+'
)');
end;