Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Jul : Enumerating devices in the computer
| Subject: | Enumerating devices in the computer |
| Posted by: | "Alexandre Rosenfeld" (alerosenfe..@ig.com.br) |
| Date: | Fri, 8 Jul 2005 11:36:14 |
Hi,
For some time I've tried to enumerated the devices in the computer with
Delphi, and only know I've found a way looking at the Platform SDK, but I'm
having a few problems. First what I would like to do is something similar to
the Device Manager in XP or the devices list in the System applet in Win 9x.
After looking at all the APIs in platform SDK I was able to build the
routine below, but SetupDiEnumDeviceInterfaces always return False, so i get
the list of the devices I got in my computer but I would like to get their
friendly name (that I should get with PSPDeviceInterfaceDetailDataA). Maybe
the problem is with the TGUID, which whould be a pointer in the function,
but it isnt in the Delphi translation.
var
devs: HDEVINFO;
i, i2:Integer;
RequiredSize: Cardinal;
DevInfoData: TSPDevInfoData;
DevIntfData: TSPDeviceInterfaceData;
DevIntfDetail: PSPDeviceInterfaceDetailDataA;
begin
LoadSetupApi;
devs := SetupDiGetClassDevs(nil, nil, Handle, DIGCF_ALLCLASSES);
Memo1.Lines.Add('Enum devices');
i:=0;
fillchar(devinfodata, SizeOf(devinfodata), 0);
DevInfoData.cbSize := SizeOf(DevInfoData);
while SetupDiEnumDeviceInfo(devs, I, DevInfoData) do
begin
Memo1.Lines.Add(format(' %d: Device found: %d', [I,
devinfodata.DevInst]));
i2:=0;
while SetupDiEnumDeviceInterfaces(devs, @DevInfoData, PGUID(nil)^, i2,
DevIntfData) do
begin
Memo1.Lines.Add(format(' >Interface: %s',
[GUIDToString(devintfdata.InterfaceClassGuid)]));
SetupDiGetDeviceInterfaceDetail(devs, @DevIntfData, nil, 0,
RequiredSize, nil);
DevIntfDetail := AllocMem(RequiredSize);
DevIntfDetail.cbSize := RequiredSize;
SetupDiGetDeviceInterfaceDetail(devs, @DevIntfData, DevIntfDetail,
RequiredSize, RequiredSize, nil);
Memo1.Lines.Add(' > '+DevIntfDetail.DevicePath);
FreeMem(DevIntfDetail);
fillchar(DevIntfData, SizeOf(DevIntfData), 0);
DevInfoData.cbSize := SizeOf(DevIntfData);
Inc(I2);
end;
fillchar(devinfodata, SizeOf(devinfodata), 0);
DevInfoData.cbSize := SizeOf(DevInfoData);
Inc(I);
end;
SetupDiDestroyDeviceInfoList(devs);
end;
--
Alexandre Rosenfeld