I have some code that searches for a particular device on the PCI bus, by VEN_abcd&DEV_wxyz
This is what interrogates the registry:-
uses registry
var
Registry: TRegistry;
Key: String;
strl1: TStringList;
begin
Registry := TRegistry.Create;
Key:='\SYSTEM\CurrentControlSet\Enum\PCI';
strl1:=TStringList.Create;
strl1.Clear;
try
Registry.RootKey := HKEY_LOCAL_MACHINE;
if Registry.OpenKeyReadOnly(Key) then
begin
Registry.GetKeyNames(strl1);
end;
finally
Registry.Free;
end;
after this you have a stringlist full of PCI identifiers with the VEN and DEV characters etc in a fixed place on each line.
I am getting a 1/2 % failure rate (as in 1 in 200) because when you put a device into a Windows PC it generates an entry in the above list, but if you then remove the device, the entry remains.
In other words this becomes the list of PCI devices that have ever been in the computer, not the one that are there right now.
Windows Device Manager can tell the difference because you only see the list of currently installed stuff but if you do View then Show Hidden Devices then you get all of them.
Is there a simple way if I can tell from within an FPC program whether a PCI device is actually there, right now?