!wdflogdump should give more context as to exact reasons why this call failed.
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@cox.net
Sent: Friday, August 28, 2009 12:53 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Why does WdfUsbTargetDeviceCreate fail in non-WDF driver?
Here is the relevant source code based on msvad
#define MAX_MINIPORTS 3 // Number of maximum miniports.
#pragma code_seg(“INIT”)
extern “C” NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPathName)
{
WDF_DRIVER_CONFIG config;
WDFDRIVER hDriver;
NTSTATUS ntStatus;
usbtDebugPrintEnter();
WDF_DRIVER_CONFIG_INIT(&config, WDF_NO_EVENT_CALLBACK);
config.DriverInitFlags |= WdfDriverInitNoDispatchOverride;
ntStatus = WdfDriverCreate(DriverObject,
RegistryPathName,
WDF_NO_OBJECT_ATTRIBUTES,
&config,
&hDriver);
if (!NT_SUCCESS(ntStatus))
{
usbtDebugPrint((DBGERROR, “WdfDriverCreate failed\n”));
return ntStatus;
}
// Tell the class driver to initialize the driver.
//
ntStatus = PcInitializeAdapterDriver(DriverObject, RegistryPathName, (PDRIVER_ADD_DEVICE)AddDevice);
usbtDebugPrintExit();
return ntStatus;
} // DriverEntry
#pragma code_seg()
#pragma code_seg(“PAGE”)
NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
{
PAGED_CODE();
NTSTATUS ntStatus;
usbtDebugPrintEnter();
// disable prefast warning 28152 because
// DO_DEVICE_INITIALIZING is cleared in PcAddAdapterDevice
#pragma warning(disable:28152)
FunctionalDeviceObject = IoGetAttachedDevice(PhysicalDeviceObject);
// Tell the class driver to add the device.
ntStatus = PcAddAdapterDevice(DriverObject, PhysicalDeviceObject, PCPFNSTARTDEVICE(StartDevice),
MAX_MINIPORTS, 128 + MY_EXTENSION_SIZE + PORT_CLASS_DEVICE_EXTENSION_SIZE);
if (!NT_SUCCESS (ntStatus))
{
usbtDebugPrint((DBGERROR, “PcAddAdapterDevice failed (0x%x)\n”, ntStatus));
return ntStatus;
}
FunctionalDeviceObject = PhysicalDeviceObject->AttachedDevice;
FunctionalDeviceObject = IoGetAttachedDevice(PhysicalDeviceObject);
GetMyExtension()->WdfDriver = WdfGetDriver();
GetMyExtension()->WdfDevice = 0;
GetMyExtension()->UsbDevice = 0;
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, WDF_DEVICE_INFO);
ntStatus = WdfDeviceMiniportCreate(GetMyExtension()->WdfDriver,
&attributes,
FunctionalDeviceObject,
PhysicalDeviceObject->AttachedDevice,
PhysicalDeviceObject,
&(GetMyExtension()->WdfDevice));
if (!NT_SUCCESS (ntStatus))
usbtDebugPrint((DBGERROR, “WdfDeviceMiniportCreate failed (0x%x)\n”, ntStatus));
usbtDebugPrint((DBGERROR, “WdfDeviceMiniportCreate WdfDriver: 0x%x WdfDevice: 0x%x UsbDevice: 0x%x\n”,
GetMyExtension()->WdfDriver, GetMyExtension()->WdfDevice, GetMyExtension()->UsbDevice));
usbtDebugPrintExit();
return ntStatus;
} // AddDevice
//=============================================================================
NTSTATUS InstallSubdevice(__in PDEVICE_OBJECT DeviceObject, __in PIRP Irp, __in PWSTR Name, __in REFGUID PortClassId, __in REFGUID MiniportClassId,
__in_opt PFNCREATEINSTANCE MiniportCreate, __in_opt PUNKNOWN UnknownAdapter, __in_opt PRESOURCELIST ResourceList, __in REFGUID PortInterfaceId,
__out_opt PUNKNOWN *OutPortInterface, __out_opt PUNKNOWN *OutPortUnknown)
{
**** same as msvad
} // InstallSubDevice
//=============================================================================
NTSTATUS StartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PRESOURCELIST ResourceList)
{
**** this part same as msvad
// Release the adapter common object. It either has other references,
// or we need to delete it anyway.
//
if (pAdapterCommon)
pAdapterCommon->Release();
if (pUnknownCommon)
pUnknownCommon->Release();
if (unknownTopology)
unknownTopology->Release();
if (unknownWave)
unknownWave->Release();
usbtDebugPrint((DBGERROR, “StartDevice1 WdfDriver: 0x%x WdfDevice: 0x%x UsbDevice: 0x%x\n”
, GetMyExtension()->WdfDriver, GetMyExtension()->WdfDevice, GetMyExtension()->UsbDevice));
// allocate Usb device
WDF_OBJECT_ATTRIBUTES attributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, USB_DEVICE_CONTEXT);
ntStatus = WdfUsbTargetDeviceCreate(GetMyExtension()->WdfDevice,
WDF_NO_OBJECT_ATTRIBUTES,//&attributes,
&GetMyExtension()->UsbDevice);
usbtDebugPrint((DBGERROR, “StartDevice2 WdfDriver: 0x%x WdfDevice: 0x%x UsbDevice: 0x%x\n”,
GetMyExtension()->WdfDriver, GetMyExtension()->WdfDevice, GetMyExtension()->UsbDevice));
if (!NT_SUCCESS(ntStatus))
{
usbtDebugPrint((DBGERROR, “*********WdfUsbTargetDeviceCreate failed %x!\n”, ntStatus));
return ntStatus;
}
usbtDebugPrintExit();
return ntStatus;
} // StartDevice
#pragma code_seg()
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer