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