I’m trying to get the device name of one of my devices. I call
WdfDeviceRetrieveDeviceName and always get 0xC000000D
STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
device call back on the PDO, from the Add device call back for the
function device and from the EvtDevicePrepareHardware call back for both
the PDO of the bus device and the FDO of the function device.
This driver is software only and is both its bus driver and the function
driver. The name is assigned automatically to the PDO by the kernel.
The frustrating thing is that DeviceTree show the device with its name.
In fact, I tell the bus driver to add a device, it adds the PDO and
then the Add Hardware wizard comes up. If I then run DeviceTree at this
point (before the function driver for the PDO has even been identified),
the device already shows its name.
Because it has a name in DeviceTree and because I get back
STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
searched the KMDF samples in the WDK and I can’t see anything different
between their code and mine.
I first tried this code:
fdoDevice is a WDFDEVICE.
WDF_OBJECT_ATTRIBUTES stringAttributes;
WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
stringAttributes.ParentObject = fdoDevice;
WDFSTRING deviceName;
NTSTATUS status = WdfStringCreate(NULL, &stringAttributes,
&deviceName);
if (!NT_SUCCESS(status))
{
return status;
}
status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
if (!NT_SUCCESS(status))
{
return status;
}
I then tried it without the object attributes like this:
fdoDevice is a WDFDEVICE.
WDFSTRING deviceName;
NTSTATUS status = WdfStringCreate(NULL,
WDF_NO_OBJECT_ATTRIBUTES,
&deviceName);
if (!NT_SUCCESS(status))
{
return status;
}
status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
if (!NT_SUCCESS(status))
{
return status;
}
No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
why this is happening?
Thanks,
Jonathan
BTW, the WDK docs seem to be incorrect for the sample code for this call:
NTSTATUS status;
WDFSTRING string;
status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NULL,
&string
);
if (NT_SUCCESS(status)) {
status = WdfDeviceRetrieveDeviceName(
Device,
string
);
if (!NT_SUCCESS(status)) {
return status;
}
}
I think
status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NULL,
&string
);
should be
status = WdfStringCreate(
NULL,
WDF_NO_OBJECT_ATTRIBUTES,
&string
);
Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
work. It may however lead someone to do this:
status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
&unicodeString,
&string
);