HomeBlogMagic

Fix: WdfTimerCreate erzeugt ErrorCode: 0xC0000004L (STATUS_INFO_LENGTH_MISMATCH)

In einem Treiber habe ich beim anlegen eines Timers mit WdfTimerCreate den Fehlercode 0xC0000004L alias STATUS_INFO_LENGTH_MISMATCH erhalten.

Da ich den Fehler eine Zeit lang gesucht hatte bis er mir auffiel, dacht ich mir, ich speichere mir das hier einmal ab.

Aufgetreten ist er bei folgendem Code:

WDFTIMER oWdfTimer;

// Setup timer configuration
WDF_TIMER_CONFIG oTimerConfig;
WDF_TIMER_CONFIG_INIT(&oTimerConfig, TimeoutEvent);
oTimerConfig.Period = 0;
oTimerConfig.AutomaticSerialization = FALSE;
oTimerConfig.TolerableDelay = 10;

// Object attributes for timer
WDF_OBJECT_ATTRIBUTES oTimerAttributes;
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&oTimerAttributes, STimeoutDeviceContext);
oTimerAttributes.ParentObject = hDevice;

// Create timer object
uStatus = WdfTimerCreate(&oTimerConfig, &oTimerAttributes, &oWdfTimer);
if (NT_SUCCESS(uStatus))
{
  TraceMsg("Error on WdfTimerCreate: 0x%08x", uStatus);
}

Der Fehler resultiert aus dem falschen initialisieren der oTimerAttributes.
Diese benötigen noch den Aufruf WDF_OBJECT_ATTRIBUTES_INIT(&oTimerAttributes);.

Fixed:

WDFTIMER oWdfTimer;

// Setup timer configuration
WDF_TIMER_CONFIG oTimerConfig;
WDF_TIMER_CONFIG_INIT(&oTimerConfig, TimeoutEvent);
oTimerConfig.Period = 0;
oTimerConfig.AutomaticSerialization = FALSE;
oTimerConfig.TolerableDelay = 10;

// Object attributes for timer
WDF_OBJECT_ATTRIBUTES oTimerAttributes;
WDF_OBJECT_ATTRIBUTES_INIT(&oTimerAttributes);
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&oTimerAttributes, STimeoutDeviceContext);
oTimerAttributes.ParentObject = hDevice;

// Create timer object
uStatus = WdfTimerCreate(&oTimerConfig, &oTimerAttributes, &oWdfTimer);
if (NT_SUCCESS(uStatus))
{
  TraceMsg("Error on WdfTimerCreate: 0x%08x", uStatus);
}
Permalink: https://adirmeier.de/Blog/ID_247
Tags: Blog, , Bugfix, Driver, WDF, Windowsvon am 2019-02-06