Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2. void displayHIDDevices(HWND hWnd) {
  3. // 1.
  4. struct _GUID GUID;
  5. HidD_GetHidGuid(&GUID);
  6.  
  7. // 2.
  8. HANDLE PnPHandle;
  9. PnPHandle = SetupDiGetClassDevs(&GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
  10. if (PnPHandle == INVALID_HANDLE_VALUE) {
  11. wsprintf(szBuffer[cLine++], "Error connecting to the device");
  12. }
  13.  
  14. // 3.
  15. int iterationCount = 20;
  16. SP_DEVICE_INTERFACE_DATA devInterfaceData;
  17. devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
  18.  
  19. for (int i = 0; i < iterationCount; i++) {
  20. SetupDiEnumDeviceInterfaces(PnPHandle, NULL, &GUID, i, &devInterfaceData);
  21. if (GetLastError() == ERROR_NO_MORE_ITEMS) {
  22. break;
  23. }
  24.  
  25. // 4.
  26. DWORD requiredSize;
  27. SetupDiGetDeviceInterfaceDetail(PnPHandle, &devInterfaceData, NULL, 0, &requiredSize, NULL);
  28. PSP_DEVICE_INTERFACE_DETAIL_DATA detailData;
  29. detailData = (SP_DEVICE_INTERFACE_DETAIL_DATA*)malloc(requiredSize);
  30. detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
  31.  
  32. if (SetupDiGetDeviceInterfaceDetail(PnPHandle, &devInterfaceData, detailData, requiredSize, &requiredSize, NULL) == false) {
  33. free(&detailData);
  34. wsprintf(szBuffer[cLine++], "Error with device interface detail");
  35. }
  36. else {
  37. // 5.
  38. HANDLE handler = CreateFile(detailData->DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
  39.  
  40. // 6.
  41. if (handler == INVALID_HANDLE_VALUE){
  42. free(detailData);
  43. wsprintf(szBuffer[cLine++], "Error in handling");
  44. }
  45. else {
  46. char cBuffer[256];
  47. HidD_GetProductString(handler, cBuffer, sizeof(cBuffer));
  48.  
  49. // 7.
  50. free(detailData);
  51.  
  52. // 8.
  53. wsprintf(szBuffer[cLine++], "%ls", cBuffer);
  54.  
  55. CloseHandle(handler);
  56.  
  57. }
  58. }
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement