Re: USB Device Change Notification

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Re: USB Device Change Notification
    ... get the arrival/removal notification for my device and the control ... BOOL bRet; ... LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, ... LPARAM lParam) ...
    (microsoft.public.development.device.drivers)
  • Re: USB Device Change Notification
    ... mean I get all Arrival and Removal message for all INPUT devices. ... BOOL bRet; ... LRESULT CALLBACK MainDlgProc(HWND hDlg, UINT message, WPARAM wParam, ... LPARAM lParam) ...
    (microsoft.public.development.device.drivers)