Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows RegisterDeviceNotificationon,OndeviceChange被调用多次_Windows_Visual C++_Mfc - Fatal编程技术网

Windows RegisterDeviceNotificationon,OndeviceChange被调用多次

Windows RegisterDeviceNotificationon,OndeviceChange被调用多次,windows,visual-c++,mfc,Windows,Visual C++,Mfc,我正在使用RegisterDeviceNotification在添加设备时获取通知。 我收到的通知是正确的,但是对于任何连接的设备,我都会多次收到OnDeviceChange呼叫(大约5-6次)。 代码如下: RegisterNotificaiton() { DEV_BROADCAST_DEVICEINTERFACE *pDev; pDev = new DEV_BROADCAST_DEVICEINTERFACE(); if(NULL != pD

我正在使用RegisterDeviceNotification在添加设备时获取通知。 我收到的通知是正确的,但是对于任何连接的设备,我都会多次收到OnDeviceChange呼叫(大约5-6次)。 代码如下:

     RegisterNotificaiton()
     {
        DEV_BROADCAST_DEVICEINTERFACE *pDev;
    pDev = new DEV_BROADCAST_DEVICEINTERFACE();
    if(NULL != pDev)
    {
    memset( pDev, 0, sizeof(DEV_BROADCAST_DEVICEINTERFACE) );
    pDev->dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
    pDev->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;

    pDev->dbcc_classguid = GUID_USB;
    m_hNotifyDevNode = RegisterDeviceNotification( this->GetSafeHwnd(), pDev,                                       DEVICE_NOTIFY_WINDOW_HANDLE | 4);
    if(NULL != pDev)
    {
        delete pDev;
        pDev = NULL;
    }
   }
    }

    BOOL CMainFrame::OnDeviceChange(UINT wParam, DWORD_PTR lParam)
    {
 switch ( wParam )
      {
    case DBT_DEVICEARRIVAL:
    {
       ; // Do something 
    }
    break;
    case DBT_DEVICEREMOVECOMPLETE:
    {
                ; // Do something
    }
           default:
               break;
          }
return true;

     }