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
>
>
>
|