Open a device with its instance id

Hi guys,

I have an instance id of a device. Is there any way to open a handle to this device? Basically, I do not know the interface GUID of this device since the device type will change from time to time, but I’m pretty sure that it has registered its interface GUID to the system.

I use SetupDiGetClassDevs/SetupDiEnumDeviceInfo/SetupDiGetDeviceInstanceId to find the device. From there, I can not do furthermore.

Any idea? Any suggestions are welcome.

Cheers

Device type/class does not matter. What matters is the device interface GUID that the driver enables. If it is the same GUID in all cases, then just use the GUID and enumerate its instances. If the driver enables a different GUID based on type, then iterate over each different GUID.

Once you get a handle, what are you going to do with it? is the driver going to support your custom IOCTLs no matter what type it is?

d

Well.

My driver is a port driver which can simulate CDs and harddisks. Currently, I can enumerate my controller and CDs/HDs in my application. From here, I have the instance ids for every controler and CDs/HDs. The purpose of my question is, I want to send DeviceIoControl to the CD/HD, which requires a device handle.

Usually we just enumerate the specified interface GUID and open it to get a handle to the device which registers that interface. But in my case, there are some other CDs/HDs which are not created by my driver, which I can also get handles to them. I know the solution for this problem: Just send my custom IOCTLs to the port driver to distinguish which one is created by myself. However, another problem is, when users click on a device to send a custom IOCTL, I need to enumerate all possible interface GUID to open the handle, which looks really stupid.

So, I guess there should be some relations between a device instance id and its registered interface GUID (with index #).

Any idea?

Register 2 device interfaces on your device objects - one the MS’s CD/DVD,
another is your own custom.
Then using SetupDiGetClassDevs on your custom interface will enumerate only
your devices, not usual CD/DVDs.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Well.
>
> My driver is a port driver which can simulate CDs and harddisks. Currently, I
can enumerate my controller and CDs/HDs in my application. From here, I have
the instance ids for every controler and CDs/HDs. The purpose of my question
is, I want to send DeviceIoControl to the CD/HD, which requires a device
handle.
>
> Usually we just enumerate the specified interface GUID and open it to get a
handle to the device which registers that interface. But in my case, there are
some other CDs/HDs which are not created by my driver, which I can also get
handles to them. I know the solution for this problem: Just send my custom
IOCTLs to the port driver to distinguish which one is created by myself.
However, another problem is, when users click on a device to send a custom
IOCTL, I need to enumerate all possible interface GUID to open the handle,
which looks really stupid.
>
> So, I guess there should be some relations between a device instance id and
its registered interface GUID (with index #).
>
> Any idea?
>

You can create a third interface GUID that you always have the PDO report. That way you only need to query for one device interface. Unless the device interfaces have reference strings (and disk and cdrom device interfaces usually don’t) you can use them interchangeably.

So you call SetupDiOpenDeviceInfo to get an SP_DEVINFO_DATA from the instance ID. Then you use SetupDiEnumDeviceInterfaces with your new interface GUID to see if it supports that interface.

SetupDi does not provide a way to find out about all of the interfaces that a particular device exposes at one time.

-p

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Friday, February 09, 2007 11:25 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Open a device with its instance id

Well.

My driver is a port driver which can simulate CDs and harddisks. Currently, I can enumerate my controller and CDs/HDs in my application. From here, I have the instance ids for every controler and CDs/HDs. The purpose of my question is, I want to send DeviceIoControl to the CD/HD, which requires a device handle.

Usually we just enumerate the specified interface GUID and open it to get a handle to the device which registers that interface. But in my case, there are some other CDs/HDs which are not created by my driver, which I can also get handles to them. I know the solution for this problem: Just send my custom IOCTLs to the port driver to distinguish which one is created by myself. However, another problem is, when users click on a device to send a custom IOCTL, I need to enumerate all possible interface GUID to open the handle, which looks really stupid.

So, I guess there should be some relations between a device instance id and its registered interface GUID (with index #).

Any idea?


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Thanks Maxim and Peter. It’s really a good idea. :slight_smile: