From: Sushma on
Hello All,

I got it working now. Unknowingly i was registering the device using
RegisterDeviceNotification() twice which caused Device Change
notification to be called twice. I removed one of the call and it works
fine.

Thanks for all your suggestions and help.

Regards,
Sushma


Nyamagoud wrote:
> Hi,
> You should refer to the lparam member of the WindowProc. It points to
> DEV_BROADCAST_HDR structure, then check its dbch_devicetype member to
> determine the device type. This way you can handle the request which you are
> interested in and ignore the other. r they same in both the case?
>
>
> "Sushma" wrote:
>
> > Hi Philipp,
> >
> > Thanks for your code. It works now but only question i have now is i
> > get the arrival/removal notification for my device and the control
> > enters into DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE statements
> > also, but it happens to enter more than once when i plugin or remove
> > the device.
> >
> > To verify this i put a debug out put message in these statements, the
> > debug message appears more than once.
> >
> > Could you tell me why this is happening? Do i need to handle anything
> > else in my code?
> >
> > Thank You.
> >
> > Regards,
> > Sushma
> >
> > Philipp Ineichen wrote:
> > > Hi
> > >
> > > The following RegisterDeviceNotification function works perfect for me. I
> > > mean I get all Arrival and Removal message for all INPUT devices. I test
> > > it with my Logitech mouse.
> > >
> > > BOOL RegisterForDevChange(HWND hDlg, PVOID *hNotifyDevNode)
> > > {
> > > BOOL bRet;
> > >
> > > DEV_BROADCAST_DEVICEINTERFACE *pFilterData = new
> > > (DEV_BROADCAST_DEVICEINTERFACE);
> > >
> > > ZeroMemory(pFilterData, sizeof(DEV_BROADCAST_DEVICEINTERFACE));
> > >
> > > pFilterData->dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
> > > pFilterData->dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
> > > pFilterData->dbcc_classguid = GUID_CLASS_INPUT;
> > >
> > > *hNotifyDevNode = RegisterDeviceNotification(hDlg, pFilterData,
> > > DEVICE_NOTIFY_WINDOW_HANDLE);
> > >
> > > if(*hNotifyDevNode)
> > > {
> > > bRet = TRUE;
> > > }
> > > else
> > > {
> > > if (pFilterData)
> > > delete (pFilterData);
> > >
> > > bRet = FALSE;
> > > }
> > >
> > > return bRet;
> > > }
> > >
> > >
> > > LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam,
> > > LPARAM lParam)
> > > {
> > >
> > > :
> > > :
> > > :
> > >
> > > case WM_DEVICECHANGE:
> > >
> > > switch ((UINT)wParam)
> > > {
> > > case DBT_DEVICEARRIVAL:
> > > SendMessage(hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Device Arrival");
> > > break;
> > >
> > > case DBT_DEVICEQUERYREMOVE:
> > > SendMessage(hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Device Query
> > > Remove");
> > > break;
> > >
> > > case DBT_DEVICEREMOVECOMPLETE:
> > > SendMessage(hOutputBox, LB_ADDSTRING, 0, (LPARAM)"Device Remove
> > > Complete");
> > > break;
> > > }
> > > break;
> > >
> > > :
> > > :
> > > :
> > > }
> > >
> > > - PI
> > > --------------------
> > > Philipp Ineichen
> > > www.skagitsystems.ch
> >
> >