var
GUID_CAM : TGUID;
hDevInfo : THDEVINFO;
DeviceInfoData : TSP_DEVINFO_DATA;
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
Listbox1.Items.Clear;
OsVersion.dwOSVersionInfoSize := sizeof(TOSVERSIONINFOW);
if not GetVersionExW(@OsVersion)
or (OsVersion.dwBuildNumber <= 7000)
then
raise Exception.Create('
minimum Windows Vista');
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
RaiseLastOSError;
i := -1;
while True
do begin
Inc(i);
DeviceInfoData.cbSize := sizeof(TSP_DEVINFO_DATA);
if not SetupDiEnumDeviceInfo(hDevInfo, i, @DeviceInfoData)
then
if GetLastError = ERROR_NO_MORE_ITEMS
then
Break
else
GetLastOSError;
R := CM_Get_Device_IDW(DeviceInfoData.DevInst, @Buffer, MAX_PATH, 0);
if R <> CR_SUCCESS
then
raise Exception.CreateFmt('
CR-ERROR %d (cfgmgr32.h)', [R]);
// see https://docs.microsoft.com/en-us/windows/win32/api/cfgmgr32/
if not SetupDiGetDeviceRegistryPropertyW(hDevInfo, DeviceInfoData, SPDRP_DEVICEDESC, dwPropertyRegDataType, @szDesc, sizeof(szDesc), dwSize)
then
RaiseLastOSError;
if not SetupDiGetDeviceProperty(hDevInfo, @DeviceInfoData, @DEVPKEY_Device_BusReportedDeviceDesc, ulPropertyType, @szDesc, sizeof(szDesc), @dwSize,0)
then
RaiseLastOSError;
Listbox1.Items.Add('
SetupDiGetDeviceProperty : BusReportedDescription = "'+widechartostring(@szDesc)+'
"');
end;
end;