Click here to Skip to main content
13,199,318 members (63,935 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

32.4K views
8 bookmarked
Posted 8 Apr 2009

WM_DEVICECHANGE Problem

, 8 Apr 2009
Rate this:
Please Sign up or sign in to vote.
WM_DEVICECHANGE problem

In one of our projects in the company, we used WM_DEVICECHANGE message to detect the arrival and removal of USB devices. The application was supposed to run on a machine in which will be running along with several other utility applications. Some months after the project delivery, client reported that, sometimes even if a USB device is plugged in, it is not detected. Problem problem.....

After some investigation, we found that if we make the window a top-level window (HWND_TOPMOST), there is no such problem. But what’s the relation between the z-order and the above problem. Later, we got few more points to identify the relation.

  1. The WM_DEVICECHANGE is sent to all the top-level windows according to their z-order. That is, the window at the top most position receives the message first, then only the window below it and so one.
  2. If a window got a WM_DEVICECHANGE and if it didn’t process the message within a period (in my machine, I think it was 20 secs), the message will not reach the subsequent windows under it.

Now everything became clear to us, some window whose z-order is greater than our application window might have hung or didn’t process the message within 20 seconds. Thus our window didn’t get a chance. Also, when we made our window top level, it would be one of the first windows to get WM_DEVICECHANGE message so reducing the number of windows above it to get hung. However, we didn't find a proper solution for this and moved to an alternative method to detect device arrival and removal.

I think windows might not be using the BroadcastSystemMessage() function with the BSF_FORCEIFHUNG flag, while sending the WM_DEVICECHANGE message.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Naveen
Software Developer (Senior)
Singapore Singapore
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
GeneralMy vote of 2 Pin
maxMESA13-Jan-12 2:36
membermaxMESA13-Jan-12 2:36 
QuestionHave you checked your Message pump loop? And isn't annoying to have some window always topmost to user? Pin
AnandChavali8-Apr-09 19:30
memberAnandChavali8-Apr-09 19:30 
AnswerRe: Have you checked your Message pump loop? And isn't annoying to have some window always topmost to user? Pin
Naveen9-Apr-09 2:33
mvpNaveen9-Apr-09 2:33 
GeneralRe: Have you checked your Message pump loop? And isn't annoying to have some window always topmost to user? Pin
hvtin20-Apr-09 0:19
memberhvtin20-Apr-09 0:19 
GeneralRe: Have you checked your Message pump loop? And isn't annoying to have some window always topmost to user? Pin
Dominque Douglas7-Jan-15 12:08
memberDominque Douglas7-Jan-15 12:08 
QuestionSo what's the solution? Pin
HightechRider8-Apr-09 14:04
memberHightechRider8-Apr-09 14:04 
RantRe: So what's the solution? Pin
adesawed2-Feb-11 0:31
memberadesawed2-Feb-11 0:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid