Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > why is the device removal message missing with the device file ope

Reply
Thread Tools Display Modes

why is the device removal message missing with the device file ope

 
 
Amanda Lin
Guest
Posts: n/a

 
      06-02-2006
I'm writing and testing a USB device driver on windows 2000.
I hope an application can receive the WM_DEVICECHANGE message of my USB
device.

In my application, I created a window in a thread to receive WM_DEVICECHANGE
message.

With the device file closed, its window procedure can receive such messages
perfectly. Both "DBT_DEVICEARRIVAL" & "DBT_DEVICEREMOVECOMPLETE" can be got.
(------- CASE1)

But the following flow can not work(------- CASE2):
1. I plug-in my usb device

In my application
2. Open the device file via CreateDevice() and get a valid handle
3. Create the window and call RegisterDeviceNotification, do the message
dispatch...

But when I plug-off the usb device, no device change message to reflect the
removal is got. (Neither DBT_DEVICEQUERYREMOVEFAILED nor
DBT_DEVICEREMOVEPENDING).
I only got a WM_DEVICECHANGE message with wParam =7.

Where is the message ??? For a surprise removal, what can I get?

In addition, the wParam value 7 also make me confused. I can't find its
definition in MSDN.

In fact, in CASE1, I got the following device message sequence as I plug-in
and plug-off the usb device:
--on plug-in
device msg param 0x7
device msg param 0x8000 (DBT_DEVICEARRIVAL)
device msg param 0x7

--on plug-off
device msg param 0x7
device msg param 0x8004 (DBT_DEVICEREMOVECOMPLETE)


Would anyone give me some advice? Thanks a lot!

Best Regards
Amanda Lin


This is the value of wParam for different device events (found in MSDN):
DBT_CONFIGCHANGECANCELED 0x19
DBT_CONFIGCHANGED 0x18
DBT_CUSTOMEVENT 0x8006
DBT_DEVICEARRIVAL 0x8000
DBT_DEVICEQUERYREMOVE 0x8001
DBT_DEVICEQUERYREMOVEFAILED 0x8002
DBT_DEVICEREMOVECOMPLETE 0x8004
DBT_DEVICEREMOVEPENDING 0x8003
DBT_DEVICETYPESPECIFIC 0x8005
DBT_QUERYCHANGECONFIG 0x17
DBT_USERDEFINED 0xffff

Best Regards
Amanda Lin
 
Reply With Quote
 
 
 
 
Amanda Lin
Guest
Posts: n/a

 
      06-02-2006
I found the value 7 for WM_DEVICECHANGE wParam means "DBT_DEVNODES_CHANGED".
Need the application judge by itself whether a surprise removal occurs?


"Amanda Lin" wrote:

> I'm writing and testing a USB device driver on windows 2000.
> I hope an application can receive the WM_DEVICECHANGE message of my USB
> device.
>
> In my application, I created a window in a thread to receive WM_DEVICECHANGE
> message.
>
> With the device file closed, its window procedure can receive such messages
> perfectly. Both "DBT_DEVICEARRIVAL" & "DBT_DEVICEREMOVECOMPLETE" can be got.
> (------- CASE1)
>
> But the following flow can not work(------- CASE2):
> 1. I plug-in my usb device
>
> In my application
> 2. Open the device file via CreateDevice() and get a valid handle
> 3. Create the window and call RegisterDeviceNotification, do the message
> dispatch...
>
> But when I plug-off the usb device, no device change message to reflect the
> removal is got. (Neither DBT_DEVICEQUERYREMOVEFAILED nor
> DBT_DEVICEREMOVEPENDING).
> I only got a WM_DEVICECHANGE message with wParam =7.
>
> Where is the message ??? For a surprise removal, what can I get?
>
> In addition, the wParam value 7 also make me confused. I can't find its
> definition in MSDN.
>
> In fact, in CASE1, I got the following device message sequence as I plug-in
> and plug-off the usb device:
> --on plug-in
> device msg param 0x7
> device msg param 0x8000 (DBT_DEVICEARRIVAL)
> device msg param 0x7
>
> --on plug-off
> device msg param 0x7
> device msg param 0x8004 (DBT_DEVICEREMOVECOMPLETE)
>
>
> Would anyone give me some advice? Thanks a lot!
>
> Best Regards
> Amanda Lin
>
>
> This is the value of wParam for different device events (found in MSDN):
> DBT_CONFIGCHANGECANCELED 0x19
> DBT_CONFIGCHANGED 0x18
> DBT_CUSTOMEVENT 0x8006
> DBT_DEVICEARRIVAL 0x8000
> DBT_DEVICEQUERYREMOVE 0x8001
> DBT_DEVICEQUERYREMOVEFAILED 0x8002
> DBT_DEVICEREMOVECOMPLETE 0x8004
> DBT_DEVICEREMOVEPENDING 0x8003
> DBT_DEVICETYPESPECIFIC 0x8005
> DBT_QUERYCHANGECONFIG 0x17
> DBT_USERDEFINED 0xffff
>
> Best Regards
> Amanda Lin

 
Reply With Quote
 
Doron Holan [MS]
Guest
Posts: n/a

 
      06-04-2006
are you registering for notifications on the device interface or on the
device handle itself?

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Amanda Lin" <> wrote in message
news:50EB8D54-AE46-408A-A9D4-...
>I found the value 7 for WM_DEVICECHANGE wParam means
>"DBT_DEVNODES_CHANGED".
> Need the application judge by itself whether a surprise removal occurs?
>
>
> "Amanda Lin" wrote:
>
>> I'm writing and testing a USB device driver on windows 2000.
>> I hope an application can receive the WM_DEVICECHANGE message of my USB
>> device.
>>
>> In my application, I created a window in a thread to receive
>> WM_DEVICECHANGE
>> message.
>>
>> With the device file closed, its window procedure can receive such
>> messages
>> perfectly. Both "DBT_DEVICEARRIVAL" & "DBT_DEVICEREMOVECOMPLETE" can be
>> got.
>> (------- CASE1)
>>
>> But the following flow can not work(------- CASE2):
>> 1. I plug-in my usb device
>>
>> In my application
>> 2. Open the device file via CreateDevice() and get a valid handle
>> 3. Create the window and call RegisterDeviceNotification, do the
>> message
>> dispatch...
>>
>> But when I plug-off the usb device, no device change message to reflect
>> the
>> removal is got. (Neither DBT_DEVICEQUERYREMOVEFAILED nor
>> DBT_DEVICEREMOVEPENDING).
>> I only got a WM_DEVICECHANGE message with wParam =7.
>>
>> Where is the message ??? For a surprise removal, what can I get?
>>
>> In addition, the wParam value 7 also make me confused. I can't find its
>> definition in MSDN.
>>
>> In fact, in CASE1, I got the following device message sequence as I
>> plug-in
>> and plug-off the usb device:
>> --on plug-in
>> device msg param 0x7
>> device msg param 0x8000 (DBT_DEVICEARRIVAL)
>> device msg param 0x7
>>
>> --on plug-off
>> device msg param 0x7
>> device msg param 0x8004 (DBT_DEVICEREMOVECOMPLETE)
>>
>>
>> Would anyone give me some advice? Thanks a lot!
>>
>> Best Regards
>> Amanda Lin
>>
>>
>> This is the value of wParam for different device events (found in MSDN):
>> DBT_CONFIGCHANGECANCELED 0x19
>> DBT_CONFIGCHANGED 0x18
>> DBT_CUSTOMEVENT 0x8006
>> DBT_DEVICEARRIVAL 0x8000
>> DBT_DEVICEQUERYREMOVE 0x8001
>> DBT_DEVICEQUERYREMOVEFAILED 0x8002
>> DBT_DEVICEREMOVECOMPLETE 0x8004
>> DBT_DEVICEREMOVEPENDING 0x8003
>> DBT_DEVICETYPESPECIFIC 0x8005
>> DBT_QUERYCHANGECONFIG 0x17
>> DBT_USERDEFINED 0xffff
>>
>> Best Regards
>> Amanda Lin



 
Reply With Quote
 
Amanda Lin
Guest
Posts: n/a

 
      06-05-2006
Thank you very much, Doron.

You are right. I registered only the device interface notification but no
device handle notification.

So when the usb device is hot-plug-off, my application doesn't recevice any
device handle notification on "DBT_DEVICEREMOVECOMPLETE", nor does it close
the device handle. And therefore my device object is in a delete-pending
state and my application can NOT get the interface notification on
"DBT_DEVICEREMOVECOMPLETE" as a result.

Now I also register the device handle notification after the device file is
opened. (I also must thank fat-boy and Eliyas :-)
....
filter.dbch_devicetype = DBT_DEVTYP_HANDLE;
filter.dbch_handle = my_global.hDevice;
my_global.hHandleNotification = RegisterDeviceNotification(hWnd,
&filter, 0);
....

It can work.
The device handle notification on "DBT_DEVICEREMOVECOMPLETE" comes at
first. I close the device file handle. And then the the device interface
notication on "DBT_DEVICEREMOVECOMPLETE" also comes.


Best Regards
Amanda

"Doron Holan [MS]" wrote:

> are you registering for notifications on the device interface or on the
> device handle itself?
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "Amanda Lin" <> wrote in message
> news:50EB8D54-AE46-408A-A9D4-...
> >I found the value 7 for WM_DEVICECHANGE wParam means
> >"DBT_DEVNODES_CHANGED".
> > Need the application judge by itself whether a surprise removal occurs?
> >
> >
> > "Amanda Lin" wrote:
> >
> >> I'm writing and testing a USB device driver on windows 2000.
> >> I hope an application can receive the WM_DEVICECHANGE message of my USB
> >> device.
> >>
> >> In my application, I created a window in a thread to receive
> >> WM_DEVICECHANGE
> >> message.
> >>
> >> With the device file closed, its window procedure can receive such
> >> messages
> >> perfectly. Both "DBT_DEVICEARRIVAL" & "DBT_DEVICEREMOVECOMPLETE" can be
> >> got.
> >> (------- CASE1)
> >>
> >> But the following flow can not work(------- CASE2):
> >> 1. I plug-in my usb device
> >>
> >> In my application
> >> 2. Open the device file via CreateDevice() and get a valid handle
> >> 3. Create the window and call RegisterDeviceNotification, do the
> >> message
> >> dispatch...
> >>
> >> But when I plug-off the usb device, no device change message to reflect
> >> the
> >> removal is got. (Neither DBT_DEVICEQUERYREMOVEFAILED nor
> >> DBT_DEVICEREMOVEPENDING).
> >> I only got a WM_DEVICECHANGE message with wParam =7.
> >>
> >> Where is the message ??? For a surprise removal, what can I get?
> >>
> >> In addition, the wParam value 7 also make me confused. I can't find its
> >> definition in MSDN.
> >>
> >> In fact, in CASE1, I got the following device message sequence as I
> >> plug-in
> >> and plug-off the usb device:
> >> --on plug-in
> >> device msg param 0x7
> >> device msg param 0x8000 (DBT_DEVICEARRIVAL)
> >> device msg param 0x7
> >>
> >> --on plug-off
> >> device msg param 0x7
> >> device msg param 0x8004 (DBT_DEVICEREMOVECOMPLETE)
> >>
> >>
> >> Would anyone give me some advice? Thanks a lot!
> >>
> >> Best Regards
> >> Amanda Lin
> >>
> >>
> >> This is the value of wParam for different device events (found in MSDN):
> >> DBT_CONFIGCHANGECANCELED 0x19
> >> DBT_CONFIGCHANGED 0x18
> >> DBT_CUSTOMEVENT 0x8006
> >> DBT_DEVICEARRIVAL 0x8000
> >> DBT_DEVICEQUERYREMOVE 0x8001
> >> DBT_DEVICEQUERYREMOVEFAILED 0x8002
> >> DBT_DEVICEREMOVECOMPLETE 0x8004
> >> DBT_DEVICEREMOVEPENDING 0x8003
> >> DBT_DEVICETYPESPECIFIC 0x8005
> >> DBT_QUERYCHANGECONFIG 0x17
> >> DBT_USERDEFINED 0xffff
> >>
> >> Best Regards
> >> Amanda Lin

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
usb device removal minimus Windows Vista General Discussion 5 10-07-2008 12:47 PM
Device Type missing from Device Manager rjk42 Windows Vista Hardware 9 07-01-2007 11:52 AM
How to disable USB device removal ? adamp Windows Vista Drivers 2 08-25-2005 06:38 AM
surprise removal sent to non-removable PCI device Ivan Bublikov Windows Vista Drivers 1 11-20-2004 09:35 PM
Win2K device driver wizard doesn't find the device names in my INF file Kirby Windows Vista Drivers 0 08-31-2003 10:25 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59