Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void displayHIDDevices(HWND hWnd) {
- // 1.
- struct _GUID GUID;
- HidD_GetHidGuid(&GUID);
- // 2.
- HANDLE PnPHandle;
- PnPHandle = SetupDiGetClassDevs(&GUID, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
- if (PnPHandle == INVALID_HANDLE_VALUE) {
- wsprintf(szBuffer[cLine++], "Error connecting to the device");
- }
- // 3.
- int iterationCount = 20;
- SP_DEVICE_INTERFACE_DATA devInterfaceData;
- devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
- for (int i = 0; i < iterationCount; i++) {
- SetupDiEnumDeviceInterfaces(PnPHandle, NULL, &GUID, i, &devInterfaceData);
- if (GetLastError() == ERROR_NO_MORE_ITEMS) {
- break;
- }
- // 4.
- DWORD requiredSize;
- SetupDiGetDeviceInterfaceDetail(PnPHandle, &devInterfaceData, NULL, 0, &requiredSize, NULL);
- PSP_DEVICE_INTERFACE_DETAIL_DATA detailData;
- detailData = (SP_DEVICE_INTERFACE_DETAIL_DATA*)malloc(requiredSize);
- detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
- if (SetupDiGetDeviceInterfaceDetail(PnPHandle, &devInterfaceData, detailData, requiredSize, &requiredSize, NULL) == false) {
- free(&detailData);
- wsprintf(szBuffer[cLine++], "Error with device interface detail");
- }
- else {
- // 5.
- HANDLE handler = CreateFile(detailData->DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- // 6.
- if (handler == INVALID_HANDLE_VALUE){
- free(detailData);
- wsprintf(szBuffer[cLine++], "Error in handling");
- }
- else {
- char cBuffer[256];
- HidD_GetProductString(handler, cBuffer, sizeof(cBuffer));
- // 7.
- free(detailData);
- // 8.
- wsprintf(szBuffer[cLine++], "%ls", cBuffer);
- CloseHandle(handler);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement