Problem with driver when at D0 state

Hi everybody,
I am new to driver programming and I followed the OSR for sometimes as well as do the examples of WDK.
I just got a driver sample from my friend, I can compile it and run, install ok. Just one very strange thing happened. When i boot up or restart PC, the driver will not work, but if I manually disable and enable the driver in Device manage, it will run ok. I put the Dbgprint message in the code and using DebugView to capture it from boot process. All load well until it start EvtDeviceD0Entry function, then i got this message on the Debug " Trying to enable physical device already in use." My guess is that the D0Exit function may got problems so it not exit the driver probably.
Below is my Entry and Exit code:

NTSTATUS MBEvtDeviceD0Entry(IN WDFDEVICE Device, IN WDF_POWER_DEVICE_STATE PreviousState)
{
PDEVICE_EXTENSION devExt;
NTSTATUS status = STATUS_SUCCESS;

UNREFERENCED_PARAMETER(PreviousState);

DbgPrint(" Entry D0 %d \n" ,status);
return status;
}
NTSTATUS MBEvtDeviceD0Exit(IN WDFDEVICE Device, IN WDF_POWER_DEVICE_STATE TargetState)
{

NTSTATUS status = STATUS_SUCCESS;

UNREFERENCED_PARAMETER(Device);
UNREFERENCED_PARAMETER(TargetState);
PAGED_CODE();

DbgPrint(" MBEvtDeviceD0Exit with %d",status);
return status;
}

How do you think about this one, should i make the device go into D3 when exit D0 ?

Sorry I pressed the post message and cannot find the edit button.

xxxxx@yahoo.com.vn wrote:

Hi everybody,
I am new to driver programming and I followed the OSR for sometimes as well as do the examples of WDK.
I just got a driver sample from my friend, I can compile it and run, install ok. Just one very strange thing happened. When i boot up or restart PC, the driver will not work, …

What do you mean, exactly by “will not work”? It gets loaded, doesn’t it?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim,
It means it loaded and in the device manager it showed the device, this is a system devices. But the software cannot access data from driver. As well as I mentioned the debug show message: " Trying to enable physical device already in use."

xxxxx@yahoo.com.vn wrote:

It means it loaded and in the device manager it showed the device, this is a system devices. But the software cannot access data from driver. As well as I mentioned the debug show message: " Trying to enable physical device already in use."

Where does that message come from, and when? Your driver doesn’t print
that message.

Is there hardware with this device? How did you install the driver,
exactly?


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.