Retreiving instance id in mouse filter driver

I’m writing a mouse filter driver based on the moufiltr sample code in
the ddk and I have a problem. I want to know the instance id of the
different devices. I can get the device id, but the instance id is
always returned as “0000”, why?

The code used to fetch device and instance id:

NTSTATUS IopInitiatePnpIrp(PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK
IoStatusBlock, UCHAR MinorFunction, PIO_STACK_LOCATION Stack)
{
PDEVICE_OBJECT TopDeviceObject;
PIO_STACK_LOCATION IrpSp;
NTSTATUS Status;
KEVENT Event;
PIRP Irp;

TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);

KeInitializeEvent(
&Event,
NotificationEvent,
FALSE);

Irp = IoBuildSynchronousFsdRequest(
IRP_MJ_PNP,
TopDeviceObject,
NULL,
0,
NULL,
&Event,
IoStatusBlock);

Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0;

IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MinorFunction = MinorFunction;

if (Stack)
{
RtlMoveMemory(
&IrpSp->Parameters,
&Stack->Parameters,
sizeof(Stack->Parameters));
}

Status = IoCallDriver(TopDeviceObject, Irp);
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject(
&Event,
Executive,
KernelMode,
FALSE,
NULL);
Status = IoStatusBlock->Status;
}

ObDereferenceObject(TopDeviceObject);

return Status;
}

//This puts a valid device id in IoStatusBlock.Information
Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
Status = IopInitiatePnpIrp(PDO,
&IoStatusBlock,
IRP_MN_QUERY_ID,
&Stack);

//This puts 0000 in IoStatusBlock.Information
Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
Status = IopInitiatePnpIrp(PDO,
&IoStatusBlock,
IRP_MN_QUERY_ID,
&Stack);

Are you expecting something like hid\vidxxxx_pidyyyy<instance id>? If
so, you can’t get this value from the kernel, this decision is by design
and is not exposed to a driver.

If you really want the bus instance ID, this value depends on the bus
your mouse is connected to. This is pretty much an opaque value.

More importantly, what do you want do with this value? What runtime
decision are you going to make based on a particular value?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hans Molin
Sent: Monday, October 24, 2005 12:34 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Retreiving instance id in mouse filter driver

I’m writing a mouse filter driver based on the moufiltr sample code in
the ddk and I have a problem. I want to know the instance id of the
different devices. I can get the device id, but the instance id is
always returned as “0000”, why?

The code used to fetch device and instance id:

NTSTATUS IopInitiatePnpIrp(PDEVICE_OBJECT DeviceObject, PIO_STATUS_BLOCK

IoStatusBlock, UCHAR MinorFunction, PIO_STACK_LOCATION Stack)
{
PDEVICE_OBJECT TopDeviceObject;
PIO_STACK_LOCATION IrpSp;
NTSTATUS Status;
KEVENT Event;
PIRP Irp;

TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);

KeInitializeEvent(
&Event,
NotificationEvent,
FALSE);

Irp = IoBuildSynchronousFsdRequest(
IRP_MJ_PNP,
TopDeviceObject,
NULL,
0,
NULL,
&Event,
IoStatusBlock);

Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0;

IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MinorFunction = MinorFunction;

if (Stack)
{
RtlMoveMemory(
&IrpSp->Parameters,
&Stack->Parameters,
sizeof(Stack->Parameters));
}

Status = IoCallDriver(TopDeviceObject, Irp);
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject(
&Event,
Executive,
KernelMode,
FALSE,
NULL);
Status = IoStatusBlock->Status;
}

ObDereferenceObject(TopDeviceObject);

return Status;
}

//This puts a valid device id in IoStatusBlock.Information
Stack.Parameters.QueryId.IdType = BusQueryDeviceID;
Status = IopInitiatePnpIrp(PDO,
&IoStatusBlock,
IRP_MN_QUERY_ID,
&Stack);

//This puts 0000 in IoStatusBlock.Information
Stack.Parameters.QueryId.IdType = BusQueryInstanceID;
Status = IopInitiatePnpIrp(PDO,
&IoStatusBlock,
IRP_MN_QUERY_ID,
&Stack);


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

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Doron Holan wrote:

Are you expecting something like hid\vidxxxx_pidyyyy<instance id>? If
> so, you can’t get this value from the kernel, this decision is by design
> and is not exposed to a driver.
>
> If you really want the bus instance ID, this value depends on the bus
> your mouse is connected to. This is pretty much an opaque value.
>
> More importantly, what do you want do with this value? What runtime
> decision are you going to make based on a particular value?

Well, I have a couple of mice connected to the system.
They are going to use the same driver but behave differently, so I want
some kind of unique id that is persistent after system reboots.

You should store the settings in the device’s registry node which is
identified by the underlying PDO. This way you will have device
specific settings and don’t need to query any IDs. See
IoOpenDeviceRegistryKey in the DDK; you will want to open the key type
of PLUGPLAY_REGKEY_DEVICE.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hans Molin
Sent: Monday, October 24, 2005 1:36 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Retreiving instance id in mouse filter driver

Doron Holan wrote:

Are you expecting something like hid\vidxxxx_pidyyyy<instance id>?
If
> so, you can’t get this value from the kernel, this decision is by
design
> and is not exposed to a driver.
>
> If you really want the bus instance ID, this value depends on the bus
> your mouse is connected to. This is pretty much an opaque value.
>
> More importantly, what do you want do with this value? What runtime
> decision are you going to make based on a particular value?

Well, I have a couple of mice connected to the system.
They are going to use the same driver but behave differently, so I want
some kind of unique id that is persistent after system reboots.


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

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Doron Holan wrote:

You should store the settings in the device’s registry node which is
identified by the underlying PDO. This way you will have device
specific settings and don’t need to query any IDs. See
IoOpenDeviceRegistryKey in the DDK; you will want to open the key type
of PLUGPLAY_REGKEY_DEVICE.

Great, exactly what I need, thanks.
By the way, is there an easy way to let the user modify the setting
(without having the user poke in the registry).
Like a dialog attached to the driver properties?

Yes, you have to write that yourself. You can do it 2 wyas

  1. You need to add the EnumPropPages32 value to the right spot in the
    registry and have your DLL implement a well defined entry point. Search
    for “EnumPropPages32” in the DDK, you will find indirect references to
    it. The msports.dll example demonstrates how to do it as well.

  2. you have a device coinstaller and handle
    DIF_ADDPROPERTYPAGE_ADVANCED. There is a specific ddk topic which
    documents how to handle this code.

Method 2) is preferred over method 1).

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hans Molin
Sent: Monday, October 24, 2005 2:13 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Retreiving instance id in mouse filter driver

Doron Holan wrote:

You should store the settings in the device’s registry node which is
identified by the underlying PDO. This way you will have device
specific settings and don’t need to query any IDs. See
IoOpenDeviceRegistryKey in the DDK; you will want to open the key type
of PLUGPLAY_REGKEY_DEVICE.

Great, exactly what I need, thanks.
By the way, is there an easy way to let the user modify the setting
(without having the user poke in the registry).
Like a dialog attached to the driver properties?


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

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The disadvantage of doing either of these, of course, is that the user
will never in 10^6 years find them if you put them on a properties page
in Device Manager.

A more friendly place to put settings that the user will actually be
expected to want to change is to add pages to the mouse control panel.
There are examples of how to do this in MSDN and on the web.

Probably this isn’t the “Microsoft approved” way, but it’s certainly
industry standard. I’d personally only put “emergency fallback” settings
on the devmgr properties page, at least for a mouse or keyboard.

Doron Holan wrote:

Yes, you have to write that yourself. You can do it 2 wyas

  1. You need to add the EnumPropPages32 value to the right spot in the
    registry and have your DLL implement a well defined entry point. Search
    for “EnumPropPages32” in the DDK, you will find indirect references to
    it. The msports.dll example demonstrates how to do it as well.

  2. you have a device coinstaller and handle
    DIF_ADDPROPERTYPAGE_ADVANCED. There is a specific ddk topic which
    documents how to handle this code.

Method 2) is preferred over method 1).

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hans Molin
Sent: Monday, October 24, 2005 2:13 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Retreiving instance id in mouse filter driver

Doron Holan wrote:
> You should store the settings in the device’s registry node which is
> identified by the underlying PDO. This way you will have device
> specific settings and don’t need to query any IDs. See
> IoOpenDeviceRegistryKey in the DDK; you will want to open the key type
> of PLUGPLAY_REGKEY_DEVICE.

Great, exactly what I need, thanks.
By the way, is there an easy way to let the user modify the setting
(without having the user poke in the registry).
Like a dialog attached to the driver properties?


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

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Ray