A issue about DriverUnload

Hi, there,

I think I fall in trouble. I’m going to create serial mouse device. My code as below:

DriverEntry(…)
{

DriverObject->DriverExtension->AddDevice = MyDriverAddDevice;
DriverObject->MajorFunction[IRP_MJ_PNP] = MyDriverPnP;
DriverObject->MajorFunction[IRP_MJ_CREATE] = MyDriverCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = MyDriverClose;
DriverObject->DriverUnload = MyDriverUnload;

}

MyDriverAddDevice(…)
{

status = IoCreateDevice(
Driver,
sizeof(DEVICE_EXTENSION),
&Globals.DeviceName,
FILE_DEVICE_SERIAL_MOUSE_PORT,
0,
FALSE,
&portDeviceObject
);

deviceExtension->TopOfStack = IoAttachDeviceToDeviceStack(portDeviceObject, PDO);

// IoCreateUnprotectedSymbolicLink can be used by drivers if the user needs to be
// able to manipulate the symbolic link. For example, the parallel and serial drivers
// create unprotected symbolic links for LPTx and COMx, so that users can manipulate
// and reassign them by using the MODE command.
status = IoCreateUnprotectedSymbolicLink(
&Globals.SymbolicLinkName,

&Globals.DeviceName);

}

My question is:

  1. When I use IoAttachDeviceToDeviceStack function to attach my driver to the device chain. I could not get

the handle by CreateFile in APP program (GetLastError code is 5, means Access is denied.). Because Mouse &

Keyboard are exclusive device in OS.

  1. On the other hand, I didn’t call
    IoAttachDeviceToDeviceStack and as a result, I never receive any PnP
    request. Even the DriverUnload function will be never called.

So the reinstall operation will have an error in Device Manager ---- “Code 31”. No Unload be called, I can’t

Release Driver-Allocated Resources.

I’ve found some information about PNP or Non-PNP driver. DriverEntry and MyDriverAddDevice both return

STATUS_SUCCESS value. Do I miss something?

My Test Platform:
Windows XP Pro SP3

Thanks for any help.

Daniel