Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is

Hello All,

My driver is ACPI driver and I have a service running in user mode which is actually having handle to it and PnpdSurpriseRemoval Test is getting failed and error seems to be :- There is still an open handle of driver under test.

In my service I have registered for the Device notification and I am getting it (SERVICE_CONTROL_DEVICEEVENT )also but only for the device arrival (i.e. DBT_DEVICEARRIVAL). I am closing the handle in the DBT_DEVICEREMOVECOMPLETE or DBT_DEVICEQUERYREMOVE but none of the them is getting called during the Plug and Play test.

In driver I have set the PNP capabilities as:

WDF_DEVICE_PNP_CAPABILITIES_INIT(&PnpCapabilities);
PnpCapabilities.SurpriseRemovalOK = WdfFalse;
PnpCapabilities.Removable = WdfFalse;
WdfDeviceSetPnpCapabilities(wdfDevice, &PnpCapabilities);

SurpriseRemovalOK is set to false , It that test case still valid ? if not then who will notify about SERVICE_CONTROL_DEVICEEVENT and what type I mean is it DBT_DEVICEQUERYREMOVEFAILED ?

Thanks & Regards
Ravi Rathore

You need to register for DBT_DEVTYP_HANDLE when you open the device. You’ll get DBT_DEVICEQUERYREMOVE for it; close the handle at that time. You won’t get REMOVECOMPLETE while there is an open handle.

Do I get DBT_DEVICEQUERYREMOVE in Surprise Removal ? or is it for graceful scenario ?

When I run with Surprise removal plug and play test , I didn’t get the DBT_DEVICEQUERYREMOVE , while if I do uninstall my driver from device manager it does.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Monday, May 14, 2012 7:02 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

You need to register for DBT_DEVTYP_HANDLE when you open the device. You’ll get DBT_DEVICEQUERYREMOVE for it; close the handle at that time. You won’t get REMOVECOMPLETE while there is an open handle.


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

I think you’ll get DBT_DEVICEREMOVEPENDING

Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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

Yed, although iirc surprise remove come directly as remove complete, not a graceful remove. You can easily ser what happens by a quick experiment though

d

debt from my phone


From: Rathore, Ravi
Sent: 5/16/2012 6:23 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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


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

IT works well if I run the plug and play surprise removal with WDK supplied exe, but when I did run with WHQL , I didn’t get any events only for this Test.

Is it possible that during WHQL - surprise removal test, Windows service will not be notified to close handle even I have register for RegisterDeviceNotificaion in service ? It could be WHQL issue also for windows 8.

Other way could be register pnpPowerCallbacks.EvtDeviceSurpriseRemoval in driver and then notify the user mode app to close handle.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Wednesday, May 16, 2012 7:13 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Yed, although iirc surprise remove come directly as remove complete, not a graceful remove. You can easily ser what happens by a quick experiment though

d

debt from my phone


From: Rathore, Ravi
Sent: 5/16/2012 6:23 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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


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


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

Whql, and i think you mean the wlk, doesn’t make the notification system work differently. It just makes sure you are doing the right thing. Registering pnpPowerCallbacks.EvtDeviceSurpriseRemoval and notifying the app out of band is NOT the right fix. Are you registering for notifications on the file handle you open or just the device interface guid?

d

debt from my phone


From: Rathore, Ravi
Sent: 5/17/2012 4:53 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

IT works well if I run the plug and play surprise removal with WDK supplied exe, but when I did run with WHQL , I didn?t get any events only for this Test.

Is it possible that during WHQL - surprise removal test, Windows service will not be notified to close handle even I have register for RegisterDeviceNotificaion in service ? It could be WHQL issue also for windows 8.

Other way could be register pnpPowerCallbacks.EvtDeviceSurpriseRemoval in driver and then notify the user mode app to close handle.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Wednesday, May 16, 2012 7:13 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Yed, although iirc surprise remove come directly as remove complete, not a graceful remove. You can easily ser what happens by a quick experiment though

d

debt from my phone


From: Rathore, Ravi
Sent: 5/16/2012 6:23 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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


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


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


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

*. Yup Wlk 8319:

*. I have register for both interface guid for device arrival and after that register with file handle as below:

  1. My service handle is register for dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT.

  2. When service starts, I have register for inteface GUID, for device arrival as

DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = InterfaceClassGuid;

hInterfaceNotify = RegisterDeviceNotification(
hWnd, // events recipient this is service handle
&NotificationFilter, // type of device
DEVICE_NOTIFY_SERVICE_HANDLE|
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES // type of recipient handle
);

  1. In Device Arrival: I am registering the file handle for device remove events as:

memset (&filter, 0, sizeof(filter)); //zero the structure
filter.dbch_size = sizeof(filter);
filter.dbch_devicetype = DBT_DEVTYP_HANDLE;
filter.dbch_handle = *p_handle;

hDeviceNotify = RegisterDeviceNotification(g_serviceStatusHandle, &filter, DEVICE_NOTIFY_SERVICE_HANDLE|

DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);

One thing I forgot to unregister for the GUID interface at the end of the service. It might be the problem.

~ Ravi

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, May 17, 2012 7:37 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Whql, and i think you mean the wlk, doesn’t make the notification system work differently. It just makes sure you are doing the right thing. Registering pnpPowerCallbacks.EvtDeviceSurpriseRemoval and notifying the app out of band is NOT the right fix. Are you registering for notifications on the file handle you open or just the device interface guid?

d

debt from my phone


From: Rathore, Ravi
Sent: 5/17/2012 4:53 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
IT works well if I run the plug and play surprise removal with WDK supplied exe, but when I did run with WHQL , I didn’t get any events only for this Test.

Is it possible that during WHQL - surprise removal test, Windows service will not be notified to close handle even I have register for RegisterDeviceNotificaion in service ? It could be WHQL issue also for windows 8.

Other way could be register pnpPowerCallbacks.EvtDeviceSurpriseRemoval in driver and then notify the user mode app to close handle.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Wednesday, May 16, 2012 7:13 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Yed, although iirc surprise remove come directly as remove complete, not a graceful remove. You can easily ser what happens by a quick experiment though

d

debt from my phone


From: Rathore, Ravi
Sent: 5/16/2012 6:23 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.com
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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


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


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


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


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

Why are you specifying DEVICE_NOTIFY_ALL_INTERFACE_CLASSES in both registrations? It isn’t needed, you are asking for a specific dev interface GUID and a specific handle, not a generic broadcast of changes.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Rathore, Ravi
Sent: Thursday, May 17, 2012 9:25 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

*. Yup Wlk 8319:

*. I have register for both interface guid for device arrival and after that register with file handle as below:

  1. My service handle is register for dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT.

  2. When service starts, I have register for inteface GUID, for device arrival as

DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = InterfaceClassGuid;

hInterfaceNotify = RegisterDeviceNotification(
hWnd, // events recipient this is service handle
&NotificationFilter, // type of device
DEVICE_NOTIFY_SERVICE_HANDLE|
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES // type of recipient handle
);

  1. In Device Arrival: I am registering the file handle for device remove events as:

memset (&filter, 0, sizeof(filter)); //zero the structure
filter.dbch_size = sizeof(filter);
filter.dbch_devicetype = DBT_DEVTYP_HANDLE;
filter.dbch_handle = *p_handle;

hDeviceNotify = RegisterDeviceNotification(g_serviceStatusHandle, &filter, DEVICE_NOTIFY_SERVICE_HANDLE|

DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);

One thing I forgot to unregister for the GUID interface at the end of the service. It might be the problem.

~ Ravi

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.com]mailto: On Behalf Of Doron Holan
Sent: Thursday, May 17, 2012 7:37 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Whql, and i think you mean the wlk, doesn’t make the notification system work differently. It just makes sure you are doing the right thing. Registering pnpPowerCallbacks.EvtDeviceSurpriseRemoval and notifying the app out of band is NOT the right fix. Are you registering for notifications on the file handle you open or just the device interface guid?

d

debt from my phone

From: Rathore, Ravi
Sent: 5/17/2012 4:53 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
IT works well if I run the plug and play surprise removal with WDK supplied exe, but when I did run with WHQL , I didn’t get any events only for this Test.

Is it possible that during WHQL - surprise removal test, Windows service will not be notified to close handle even I have register for RegisterDeviceNotificaion in service ? It could be WHQL issue also for windows 8.

Other way could be register pnpPowerCallbacks.EvtDeviceSurpriseRemoval in driver and then notify the user mode app to close handle.

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.com]mailto: On Behalf Of Doron Holan
Sent: Wednesday, May 16, 2012 7:13 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Yed, although iirc surprise remove come directly as remove complete, not a graceful remove. You can easily ser what happens by a quick experiment though

d

debt from my phone

From: Rathore, Ravi
Sent: 5/16/2012 6:23 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.commailto:xxxxx
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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


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


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


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


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


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</mailto:xxxxx></mailto:xxxxx></mailto:></mailto:xxxxx></mailto:></mailto:xxxxx>

Thanks Doron for help.

I was trying with that option also to get at least some events.

I made a stupid error of not installing the service properly on the target . I was just copy the service.exe in system32 and restart the service which works but until reboot. When I did the clean uninstall and install it works.

~ Ravi Rathore

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Thursday, May 17, 2012 10:11 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Why are you specifying DEVICE_NOTIFY_ALL_INTERFACE_CLASSES in both registrations? It isn’t needed, you are asking for a specific dev interface GUID and a specific handle, not a generic broadcast of changes.

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Rathore, Ravi
Sent: Thursday, May 17, 2012 9:25 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

*. Yup Wlk 8319:

*. I have register for both interface guid for device arrival and after that register with file handle as below:

  1. My service handle is register for dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_POWEREVENT.

  2. When service starts, I have register for inteface GUID, for device arrival as

DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = InterfaceClassGuid;

hInterfaceNotify = RegisterDeviceNotification(
hWnd, // events recipient this is service handle
&NotificationFilter, // type of device
DEVICE_NOTIFY_SERVICE_HANDLE|
DEVICE_NOTIFY_ALL_INTERFACE_CLASSES // type of recipient handle
);

  1. In Device Arrival: I am registering the file handle for device remove events as:

memset (&filter, 0, sizeof(filter)); //zero the structure
filter.dbch_size = sizeof(filter);
filter.dbch_devicetype = DBT_DEVTYP_HANDLE;
filter.dbch_handle = *p_handle;

hDeviceNotify = RegisterDeviceNotification(g_serviceStatusHandle, &filter, DEVICE_NOTIFY_SERVICE_HANDLE|

DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);

One thing I forgot to unregister for the GUID interface at the end of the service. It might be the problem.

~ Ravi

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.com]mailto: On Behalf Of Doron Holan
Sent: Thursday, May 17, 2012 7:37 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Whql, and i think you mean the wlk, doesn’t make the notification system work differently. It just makes sure you are doing the right thing. Registering pnpPowerCallbacks.EvtDeviceSurpriseRemoval and notifying the app out of band is NOT the right fix. Are you registering for notifications on the file handle you open or just the device interface guid?

d

debt from my phone

From: Rathore, Ravi
Sent: 5/17/2012 4:53 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
IT works well if I run the plug and play surprise removal with WDK supplied exe, but when I did run with WHQL , I didn’t get any events only for this Test.

Is it possible that during WHQL - surprise removal test, Windows service will not be notified to close handle even I have register for RegisterDeviceNotificaion in service ? It could be WHQL issue also for windows 8.

Other way could be register pnpPowerCallbacks.EvtDeviceSurpriseRemoval in driver and then notify the user mode app to close handle.

From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.com]mailto: On Behalf Of Doron Holan
Sent: Wednesday, May 16, 2012 7:13 PM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

Yed, although iirc surprise remove come directly as remove complete, not a graceful remove. You can easily ser what happens by a quick experiment though

d

debt from my phone

From: Rathore, Ravi
Sent: 5/16/2012 6:23 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)
Is it good to close user mode handle there DBT_DEVICEREMOVEPENDING ?

-----Original Message-----
From: xxxxx@lists.osr.commailto:xxxxx [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@broadcom.commailto:xxxxx
Sent: Wednesday, May 16, 2012 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Plug and Play Surprise Removal Failed :- User Mode Open handle Problem: (DBT_DEVICEREMOVECOMPLETE is not getting called)

I think you’ll get DBT_DEVICEREMOVEPENDING


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


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


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


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


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


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


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</mailto:xxxxx></mailto:xxxxx></mailto:></mailto:xxxxx></mailto:></mailto:xxxxx>