visual studio 2008 - WM_DEVICECHANGE Messages Are Not Sent to WndProc - C++ -


my application creates window purpose of handling wm_devicechange windows message. wndproc called several times, until application calls function poll keyboard events, whatever reason not called when remove or insert usb device.

this guid usb device. i'm sure it's correct:

static const guid _guidforcp210xdevices = {     0xa2a39220, 0x39f4, 0x4b88, 0xae, 0xcb, 0x3d, 0x86, 0xa3, 0x5d, 0xc7, 0x48 }; 

this how window created:

m_hinstance = ::getmodulehandle( null );  if ( m_hinstance == null ) {     trace(_t("cnotifywindow::cnotifywindow : failed retrieve module handle.\r\n\terror: %d\r\n\tfile: %s\r\n\tline: %d\r\n"), ::getlasterror(), __wfile__, __line__);     throw(::getlasterror()); }  m_wcx.cbsize = sizeof(wndclassex);  // size of structure m_wcx.style = cs_hredraw | cs_vredraw; // minimized m_wcx.lpfnwndproc = &wndproc;       // points window procedure m_wcx.cbclsextra = 0;               // no class memory m_wcx.cbwndextra = 0;               // no window memory m_wcx.hinstance = m_hinstance;      // handle instance m_wcx.hicon = ::loadicon( null, idi_application ); // default app icon m_wcx.hcursor = ::loadcursor( null, idc_arrow ); // standard arrow cursor m_wcx.hbrbackground = null;         // no background paint m_wcx.lpszmenuname = null;          // no menu resource m_wcx.lpszclassname = _pwcwindowclass; // name of window class m_wcx.hiconsm = null;               // search system resources sm icon  m_atom = ::registerclassex( &m_wcx );  if ( m_atom == 0 ) {     trace(_t("cnotifywindow::cnotifywindow : failed register window class.\r\n\terror: %d\r\n\tfile: %s\r\n\tline: %d\r\n"), ::getlasterror(), __wfile__, __line__);     throw(::getlasterror()); }  m_hwnd = ::createwindow(     _pwcwindowclass,     _pwcwindowname,     ws_iconic,     0,     0,     cw_usedefault,     0,     null,     null,     m_hinstance,     null     );  if ( m_hwnd == null ) {     trace(_t("cnotifywindow::cnotifywindow : failed create window.\r\n\terror: %d\r\n\tfile: %s\r\n\tline: %d\r\n"), ::getlasterror(), __wfile__, __line__);     throw(::getlasterror()); }  ::showwindow( m_hwnd, sw_hide );    // function not fail  if ( registerfornotification() != error_success ) {     trace(_t("cnotifywindow::cnotifywindow : failed register device notification.\r\n\terror: %d\r\n\tfile: %s\r\n\tline: %d\r\n"), ::getlasterror(), __wfile__, __line__);     throw(::getlasterror()); } 

this how register device notification:

static dev_broadcast_deviceinterface dbt = {0};  assert(m_hwnd != null);  // populate dev_broadcast_deviceinterface structure. dbt.dbcc_size = sizeof(dev_broadcast_deviceinterface); dbt.dbcc_devicetype = dbt_devtyp_deviceinterface; dbt.dbcc_classguid = _guidforcp210xdevices;  // register hid devic notifications m_hnotify = registerdevicenotification( m_hwnd, &dbt, device_notify_window_handle );  if ( m_hnotify == null ) {     trace(_t("cnotifywindow::registerfornotification : failed register device notification.\r\n\terror: %d\r\n\tfile: %s\r\n\tline: %d\r\n"), ::getlasterror(), __wfile__, __line__);     return ::getlasterror(); }  return error_success; 

my wndproc function looks this:

static lresult callback wndproc( hwnd hwnd, uint umsg, wparam wparam, lparam lparam ) {     dev_broadcast_hdr * pheader = reinterpret_cast<dev_broadcast_hdr *>(lparam);      switch ( umsg )     {     case wm_devicechange:         if ( pheader != null )         {             if ( pheader->dbch_devicetype == dbt_devtyp_port )             {                 ondevicechange( wparam );             }         }         break;      default:         // nothing.         break;     }      return ::defwindowproc( hwnd, umsg, wparam, lparam ); } 

does know i'm doing wrong? thanks.

you're missing message pump retrieve notifications queue , dispatch them wndproc. message pump loop checks messages , calls appropriate wndproc synchronously. msdn has information on them. don't know context of code is, i'm not sure if need insert pump after registerfornotification or if larger architectural change necessary.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -