WM_DEVICECHANGLE message. When nEventType is DBT_DEVICEARRIVAL and dwData = 7, it is a USB flash drive connection event (if it is correct)
I want to set the GUID dbcc_classguid OF THE DEV_BROADCAST_DEVICEINTERFACE struct in RegisterDeviceNotification to the GUID of the device. What are the parameters?
typedef void (__stdcall *FUNC_TYPE_HIDGUID) (OUT LPGUID HidGuid);FUNC_TYPE_HIDGUID _HidD_GetHidGuid = NULL; // USB version GUIDstatic GUID GUID_CLASS_ITOKEN2 = {0x171638f7, 0x1ead, 0x4873, {0xba, 0x98, 0xc9, 0x66, 0xab, 0xcf, 0x1, 0x42}};static GUID GUID_CLASS_ITOKEN2_HID;BOOL bRegisted = FALSE;typedef PVOID HDEVNOTIFY;HDEVNOTIFY hDevNotify1 = NULL;HDEVNOTIFY hDevNotify2 = NULL;void CSample_13Dlg::OnRegister() {// TODO: Add your control notification handler code hereHWND hWnd;//HDEVNOTIFY hDevNotify = NULL; DEV_BROADCAST_DEVICEINTERFACE dbf;BOOL bRes;if (_HidD_GetHidGuid == NULL){HINSTANCE hMod = LoadLibrary("hid.dll");_HidD_GetHidGuid = (FUNC_TYPE_HIDGUID)GetProcAddress(hMod, "HidD_GetHidGuid");ASSERT(_HidD_GetHidGuid != NULL);// Get HID device GUID _HidD_GetHidGuid(&GUID_CLASS_ITOKEN2_HID);FreeLibrary(hMod);}if (!bRegisted) // if not registered{hWnd = this->m_hWnd;// Register ITOKEN2 device notification memset(&dbf, 0x00, sizeof(dbf));dbf.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);dbf.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;dbf.dbcc_classguid = GUID_CLASS_ITOKEN2;hDevNotify2 = RegisterDeviceNotification( hWnd, &dbf,DEVICE_NOTIFY_WINDOW_HANDLE);ASSERT(hDevNotify2 != NULL);// Register ITOKEN2 HID device notificationmemset(&dbf, 0x00, sizeof(dbf));dbf.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);dbf.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;dbf.dbcc_classguid = GUID_CLASS_ITOKEN2_HID;hDevNotify1 = RegisterDeviceNotification( hWnd, &dbf,DEVICE_NOTIFY_WINDOW_HANDLE);ASSERT(hDevNotify1 != NULL);GetDlgItem(IDC_REGISTER)->SetWindowText("Unregister");bRegisted = TRUE;}else {if (hDevNotify1) // Unregister ITOKEN2 device notification {bRes = UnregisterDeviceNotification(hDevNotify1);ASSERT(bRes);}if (hDevNotify2) // Unregister ITOKEN2 HID device notification{bRes = UnregisterDeviceNotification(hDevNotify2);ASSERT(bRes);}GetDlgItem(IDC_REGISTER)->SetWindowText("register");bRegisted = FALSE;}}