CustomThreadedDpc routine

The CustomThreadedDpc routine performs the action of a threaded DPC. The system executes this routine when the threaded DPC runs.



VOID CustomThreadedDpc(
  _In_     struct _KDPC *Dpc,
  _In_opt_ PVOID        DeferredContext,
  _In_opt_ PVOID        SystemArgument1,
  _In_opt_ PVOID        SystemArgument2
{ ... }


Dpc [in]

Pointer to the DPC object that registered this CustomThreadedDpc routine.

DeferredContext [in, optional]

Specifies driver-defined context information. When it initialized the DPC object, the driver supplied this value as the DeferredContext parameter to KeInitializeThreadedDpc.

SystemArgument1 [in, optional]

Specifies driver-defined context information. When it added the DPC to the DPC queue, the driver supplied this value as the SystemArgument1 parameter to KeInsertQueueDpc.

SystemArgument2 [in, optional]

Specifies driver-defined context information. When it added the DPC to the DPC queue, the driver supplied this value as the SystemArgument2 parameter to KeInsertQueueDpc.

Return value



A driver registers a CustomThreadedDpc for a DPC object by calling KeInitializeThreadedDpc. To actually add the DPC to the DPC queue so that the CustomThreadedDpc routine will be executed, call KeInsertQueueDpc.

For more information about using CustomThreadedDpc routines, see Threaded DPCs.

A CustomThreadedDpc routine can run at IRQL = DISPATCH_LEVEL, or it can run at IRQL = PASSIVE_LEVEL in a real-time thread.


To define a CustomThreadedDpc callback routine, you must first provide a function declaration that identifies the type of callback routine you're defining. Windows provides a set of callback function types for drivers. Declaring a function using the callback function types helps Code Analysis for Drivers, Static Driver Verifier (SDV), and other verification tools find errors, and it's a requirement for writing drivers for the Windows operating system.

For example, to define a CustomThreadedDpc callback routine that is named MyCustomThreadedDpc, use the KDEFERRED_ROUTINE type as shown in this code example:


Then, implement your callback routine as follows:

    struct _KDPC  *Dpc,
    PVOID  DeferredContext,
    PVOID  SystemArgument1,
    PVOID  SystemArgument2
      // Function body

The KDEFERRED_ROUTINE function type is defined in the Wdm.h header file. To more accurately identify errors when you run the code analysis tools, be sure to add the _Use_decl_annotations_ annotation to your function definition. The _Use_decl_annotations_ annotation ensures that the annotations that are applied to the KDEFERRED_ROUTINE function type in the header file are used. For more information about the requirements for function declarations, see Declaring Functions by Using Function Role Types for WDM Drivers. For information about _Use_decl_annotations_, see Annotating Function Behavior.


Target platform



Supported in Windows 2000 and later versions of Windows.


Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h)


See Remarks section.

See also




Send comments about this topic to Microsoft