WdfTimerCreate - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// wdftimer.h

NTSTATUS WdfTimerCreate(
  [in]  PWDF_TIMER_CONFIG      Config,
  [in]  PWDF_OBJECT_ATTRIBUTES Attributes,
  [out] WDFTIMER               *Timer
);

View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (nf-wdftimer-wdftimercreate)

WdfTimerCreate function

Description

[Applies to KMDF and UMDF]

The WdfTimerCreate method creates a framework timer object.

Parameters

Config [in]

A pointer to a WDF_TIMER_CONFIG structure.

Attributes [in]

A pointer to a WDF_OBJECT_ATTRIBUTES structure that contains object attributes for the new timer object.

Timer [out]

A pointer to a location that receives a handle to the new framework timer object.

Return value

WdfTimerCreate returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method might return one of the following values:

Return code Description
STATUS_WDF_PARENT_NOT_SPECIFIED The Attributes parameter was NULL, or the ParentObject member of the WDF_OBJECT_ATTRIBUTES structure that Attributes specifies was NULL.
STATUS_INVALID_PARAMETER An invalid parameter was specified.
STATUS_INVALID_DEVICE_REQUEST The ParentObject member of the WDF_OBJECT_ATTRIBUTES structure did not reference a framework device object or an object whose chain of parents leads to a framework device object.
STATUS_INSUFFICIENT_RESOURCES There was insufficient memory.
STATUS_WDF_INCOMPATIBLE_EXECUTION_LEVEL The AutomaticSerialization member of the WDF_TIMER_CONFIG structure was set to TRUE, but the parent device object's execution level was set to WdfExecutionLevelPassive.

For a list of other return values that the WdfTimerCreate method might return, see Framework Object Creation Errors.

This method might also return other NTSTATUS values.

Remarks

When your driver calls WdfTimerCreate, it must supply a WDF_OBJECT_ATTRIBUTES structure and must specify a parent object in the structure's ParentObject member. The parent object can be a framework device object or any object whose chain of parents leads to a framework device object. The framework will delete the timer object when it deletes the device object.

After creating a timer object, the driver must call WdfTimerStart to start the timer's clock regardless of whether the timer is periodic or not.

If your driver provides EvtCleanupCallback or EvtDestroyCallback callback functions for the framework timer object, note that the framework calls these callback functions at IRQL = PASSIVE_LEVEL.

For more information about framework timer objects, see Using Timers.

Examples

The following code example initializes a WDF_TIMER_CONFIG structure and a WDF_OBJECT_ATTRIBUTES structure and then calls WdfTimerCreate.

WDF_TIMER_CONFIG  timerConfig;
WDF_OBJECT_ATTRIBUTES  timerAttributes;
WDFTIMER  timerHandle;
NTSTATUS  status;

WDF_TIMER_CONFIG_INIT(
                      &timerConfig,
                      MyEvtTimerFunc
                      );

// Consider allowing a tolerance for the due time and period.
// For more information on no-wake timers and timer coalescing, see:
// https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/no-wake-timers
timerConfig.TolerableDelay = 10;

WDF_OBJECT_ATTRIBUTES_INIT(&timerAttributes);
timerAttributes.ParentObject = DeviceHandle;

status = WdfTimerCreate(
                        &timerConfig,
                        &timerAttributes,
                        &timerHandle
                        );

if (!NT_SUCCESS(status)) {
    return status;
}

See also