Question

I've been struggling with the Setup API for days now and there is still one thing that bugs me: I can load a list of devices, I can use those device handles to retrieve a list of appropriate drivers from the driverstore, but how do I determine which of those is currently loaded? Is it actually as easy as saying the device description matches the driver description? Or is there an API call for that? Why can I read a GUID from the device that is supposed to represent driver info, but the driver information I get from the mentioned enumeration has no such GUID?

Any help is greatly appreciated, thanks!

Was it helpful?

Solution

I can not say this with 100% security, but it seems safe to match driver description and device description (I'd love to know for what reasons this was considered good design...). Even with identical hardware this will match. While the Devicemanager enumerates your devices (Adapter #x), the description is still Adapter only, and therefor can be matched. The enumerated name, on the other hand, can be read from the FriendlyName property.
If anyone can answer this in more detail, I'd love to see that answer!

OTHER TIPS

this is my very first post on Stackoverflow, so please excuse me if my formum manners are off...

I might have some additional ways to achieve what you are after. I used the DeviceProperties of the Unified Device Model to get this information. This can also be achieved using the SetupAPI. Using the SetupAPI you can use the SetupDiCreateDeviceInfoList function to get a handle to a "Device Information Set" containing info about all devices (or the devices belonging to a "Setup Class" of your choice). You can "iterate" through this list using the SetupDiEnumDevicEInfo function by increasing the memberindex variable after each call. Each call to this function will provide you with a SP_DEVINFO_DATA structure (you must allocate the memory for it yourself). This structure uniquely identifies a device. In combination with the handle to your "Device Information Set" it can be passed to the SetupDiGetDevicePropertyW function to get any property (as discussed in the Unified Device Model) that is registered with the device. The propertyKey parameter of the function can be passed a pointer to the DEVPKEY_Device_Service constant (it is a constant instance of DEVPROPKEY and is defined in devpkey.h (if you are using C# you must create this variable yourself since you can't include .h files in C# like you can in C/C++)). The function will fill a buffer (that is allocated by you) with a UTF16 string (normal string in .net (I recommend using a .net StringBuilder instance for simplicity's sake)). This string should now contain the name of the driver (also called a service) that is loaded for this device.

If you wish, you could use the SCManager API's to get more information about the service such as a path to its binary file and other configuration options.

I hope this helps anyone (I see the question was posted a while ago now) who still wonders about a way to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top