Windows Driver Kit: Kernel-Mode Driver Framework
WdfDeviceInitAssignWdmIrpPreprocessCallback
The WdfDeviceInitAssignWdmIrpPreprocessCallback method registers a callback function to handle an IRP major function code and, optionally, one or more minor function codes that are associated with the major function code.
NTSTATUS
WdfDeviceInitAssignWdmIrpPreprocessCallback(
IN PWDFDEVICE_INIT DeviceInit,
IN PFN_WDFDEVICE_WDM_IRP_PREPROCESS EvtDeviceWdmIrpPreprocess,
UCHAR MajorFunction,
IN OPTIONAL PUCHAR MinorFunctions,
ULONG NumMinorFunctions
);
Parameters
- DeviceInit
- A pointer to a WDFDEVICE_INIT structure.
- EvtDeviceWdmIrpPreprocess
- A pointer to the driver's EvtDeviceWdmIrpPreprocess callback function.
- MajorFunction
- One of the IRP major function codes that are defined in wdm.h.
- MinorFunctions
- A pointer to an array of one or more IRP minor function codes that are associated with the specified major function code. This parameter is optional and can be NULL. For more information, see the following Comments section.
- NumMinorFunctions
- The number of minor function codes that are contained in the MinorFunctions array.
Return Value
If the operation succeeds, the method returns STATUS_SUCCESS. Additional return values include:
STATUS_INVALID_PARAMETER, if the MajorFunction value is invalid.
STATUS_INSUFFICIENT_RESOURCES, if there is insufficient memory.
STATUS_INVALID_DEVICE_REQUEST, if the driver is attempting to register a duplicate MinorFunction array for the specified MajorFunction value.
The method might return other NTSTATUS values.
Comments
Drivers can call the WdfDeviceInitAssignWdmIrpPreprocessCallback method for either of two reasons:
- To handle an IRP major or minor function code that the framework does not support.
For example, the framework does not support IRP_MJ_FLUSH_BUFFERS. If your driver must support this IRP, it must register an EvtDeviceWdmIrpPreprocess callback function that handles the IRP. The driver must follow WDM rules for processing IRPs.
- To preprocess an IRP before the framework handles it.
In rare cases, it might be necessary for a driver to process an IRP before the framework processes it. In such cases, the driver's EvtDeviceWdmIrpPreprocess callback function can process the IRP and then call WdfDeviceWdmDispatchPreprocessedIrp to return the IRP to the framework. Depending on the IRP's function code, the framework might process the IRP itself or it might deliver the IRP to the driver again in a framework request object.
The framework calls the EvtDeviceWdmIrpPreprocess callback function whenever it receives an I/O request packet (IRP) that contains an IRP major function code that matches the MajorFunction parameter and a minor function code that matches one of the minor function codes that are in the MinorFunctions array.
If the MinorFunctions array pointer is NULL, the framework calls the callback function for all minor function codes that are associated with the specified major function code. If the MinorFunctions array pointer is not NULL, the framework makes a copy of the array so that the driver does not have to permanently keep its array.
If the driver received DeviceInit pointer from WdfPdoInitAllocate or an EvtChildListCreateDevice event callback function, the driver's EvtDeviceWdmIrpPreprocess callback function cannot set a completion routine for IRPs that contain a major function code of IRP_MJ_PNP. Otherwise, Driver Verifier will report an error.
For more information about the WdfDeviceInitAssignWdmIrpPreprocessCallback method, see Handling WDM IRPs Outside of the Framework.
Example
The following code example registers a callback function to handle IRP_MJ_QUERY_INFORMATION IRPs.
status = WdfDeviceInitAssignWdmIrpPreprocessCallback(
DeviceInit,
SerialQueryInformationFile,
IRP_MJ_QUERY_INFORMATION,
NULL, // Pointer to the minor function table
0 // Number of entries in the table
);
if (!NT_SUCCESS(status)) {
return status;
}
Requirements
Versions: The WdfDeviceInitAssignWdmIrpPreprocessCallback method is available in version 1.0 and later versions of KMDF.
IRQL: <= DISPATCH_LEVEL
Headers: Declared in wdfdevice.h. Include wdf.h.
Library: See Framework Library Versions.
See Also
WdfDeviceWdmDispatchPreprocessedIrp