Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WM_DEVICECHANGE confusion

12 views
Skip to first unread message

SatB

unread,
Dec 29, 2003, 7:28:07 PM12/29/03
to
Hi,
I have a plain vanilla windows application with a WinMain
& WndProc.
My requirement is to be notified if a device (such as a
RAID controller) is unplugged from a Hot Plug slot or
forcibly removed from the PCI Slot.
I am using WM_DEVICECHANGE in my WndProc for this purpose.
I have registered with PNP manager. And I do get notified
if the controller is removed from the PCI Slot (I get
WM_DEVICECHANGE with wparam as DBT_DEVICEREMOVECOMPLETE)
Here is my problem. If any application has a handle open
to the controller (using CreateFile()), then PNP Manager
pops up a message (when an attempt is made to remove the
controller) saying that the controller cannot be removed
since it is in use. But my application does NOT receive
any WM_DEVICECHANGE notification!! So I cannot close the
handle to the controller. The MS documentation says
that "all applications with top level window should get
WM_DEVICECHANGE message with wparam as either
DBT_DEVICEQUERYREMOVE or DBT_DEVICEREMOVECOMPLETE".
Did anybody else face this problem. I tried both in
Windows 2000 Professional and in Windows 2003 Server. Same
results. Please let me know if anyone of you have any
inputs on this.
Thanks a lot,
SatB

Jim Cavalaris [MS]

unread,
Jan 2, 2004, 3:20:04 PM1/2/04
to
since you are only receiving DBT_DEVICEREMOVECOMPLETE, it seems as
if you have only registered for DBT_DEVTYP_DEVICEINTERFACE
notification, not the handle-based device usage notifications.

DBT_DEVICEQUERYREMOVE mesgs are not automatically broadcast
to all windows. they are only sent to applications that have
registered for DBT_DEVTYP_HANDLE type notifications.

to register for notification of query-removal, etc. events for a
device that you have a handle to, also use RegisterDeviceNotification,
but with a DBT_DEVTYP_HANDLE type NotificationFilter. specify the
handle to the device in the dbch_handle member of the
DEV_BROADCAST_HANDLE structure.

RegisterDeviceNotification:
http://msdn.microsoft.com/library/en-us/devio/base/registerdevicenotification.asp

both device interface and target device change notifications are
sent as WM_DEVICECHANGE mesgs, and both types use some of the
same DBT_* event types, so it is important to know which type
of event you have received.

Processing a Request to Remove a Device:
http://msdn.microsoft.com/library/en-us/devio/base/processing_a_request_to_remove_a_device.asp

hope this helps,
jim.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


"SatB" <anon...@discussions.microsoft.com> wrote in message
news:052101c3ce6b$cbd87910$a101...@phx.gbl...

SatB

unread,
Jan 5, 2004, 2:16:54 PM1/5/04
to
Thanks a lot Jim. That was really helpful.
Happy New Year 2004.
Regards,
SatB
>.
>
0 new messages