Interface query failure

Dear Experts,

I would like to ask your help about the code below. This is my function
driver’s QueryFunction in which I would like to obtain the interface of a
Bus driver. It runs without errors, however the result structure is not
touched by the bus driver. I used WinDbg to go on the lines step by step
and seems to be all OK. I think there must be a sort of fundamental problem
with it.

I’d very much appreciate any comments or suggestions.

Thank you,
kig


QueryFunction(PDEVICE_EXTENSION pDevExt)
{
PIRP pIrp = IoAllocateIrp( pDevExt->DeviceObject->StackSize, FALSE);
if( pIrp == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
PIO_STACK_LOCATION irpStack = IoGetNextIrpStackLocation( pIrp);
if( irpStack == NULL)
{
IoFreeIrp( pIrp);
return STATUS_INSUFFICIENT_RESOURCES;
}
irpStack->MajorFunction = IRP_MJ_PNP;
irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
irpStack->Parameters.QueryInterface.InterfaceType =
(LPGUID)&GUID_XXX_BUS_INTERFACE;
irpStack->Parameters.QueryInterface.Size = sizeof(XXX_BUS_INTERFACE);
irpStack->Parameters.QueryInterface.Version = 0x0100;
irpStack->Parameters.QueryInterface.Interface = (PINTERFACE)pDevExt->BusInt;
irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
KEVENT Event;
KeInitializeEvent( &Event, NotificationEvent, FALSE);
IoSetCompletionRoutine( pIrp, QueryCompletionRoutine, &Event, TRUE, TRUE,
TRUE);
NTSTATUS status = IoCallDriver( pDevExt->DeviceObject, pIrp);
if( status == STATUS_PENDING )
KeWaitForSingleObject( &Event, Suspended, KernelMode, FALSE, NULL);
if( pDevExt->BusInt.GetDeviceInf == NULL )
status = STATUS_FAIL_CHECK;
IoFreeIrp( pIrp);
return( status);
}

NTSTATUS QueryCompletionRoutine( IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp,
IN PVOID Event)
{
KeSetEvent(( PKEVENT)Event, 0, FALSE);
return( STATUS_MORE_PROCESSING_REQUIRED);
}

You are sending the irp to yourself. Are you sure you are passing down
this particular QI and not completing it w/in your own dispatch routine?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of jon
Sent: Thursday, March 03, 2005 5:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Interface query failure

Dear Experts,

I would like to ask your help about the code below. This is my function
driver’s QueryFunction in which I would like to obtain the interface of
a
Bus driver. It runs without errors, however the result structure is not
touched by the bus driver. I used WinDbg to go on the lines step by
step
and seems to be all OK. I think there must be a sort of fundamental
problem
with it.

I’d very much appreciate any comments or suggestions.

Thank you,
kig



QueryFunction(PDEVICE_EXTENSION pDevExt)
{
PIRP pIrp = IoAllocateIrp( pDevExt->DeviceObject->StackSize, FALSE);
if( pIrp == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
PIO_STACK_LOCATION irpStack = IoGetNextIrpStackLocation( pIrp);
if( irpStack == NULL)
{
IoFreeIrp( pIrp);
return STATUS_INSUFFICIENT_RESOURCES;
}
irpStack->MajorFunction = IRP_MJ_PNP;
irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
irpStack->Parameters.QueryInterface.InterfaceType =
(LPGUID)&GUID_XXX_BUS_INTERFACE;
irpStack->Parameters.QueryInterface.Size = sizeof(XXX_BUS_INTERFACE);
irpStack->Parameters.QueryInterface.Version = 0x0100;
irpStack->Parameters.QueryInterface.Interface =
(PINTERFACE)pDevExt->BusInt;
irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
KEVENT Event;
KeInitializeEvent( &Event, NotificationEvent, FALSE);
IoSetCompletionRoutine( pIrp, QueryCompletionRoutine, &Event, TRUE,
TRUE,
TRUE);
NTSTATUS status = IoCallDriver( pDevExt->DeviceObject, pIrp);
if( status == STATUS_PENDING )
KeWaitForSingleObject( &Event, Suspended, KernelMode, FALSE, NULL);
if( pDevExt->BusInt.GetDeviceInf == NULL )
status = STATUS_FAIL_CHECK;
IoFreeIrp( pIrp);
return( status);
}

NTSTATUS QueryCompletionRoutine( IN PDEVICE_OBJECT pDeviceObject,
IN PIRP pIrp,
IN PVOID Event)
{
KeSetEvent(( PKEVENT)Event, 0, FALSE);
return( STATUS_MORE_PROCESSING_REQUIRED);
}


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

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