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);