ii need the ansewr before tomorow.
HANDLE connectToIthUSBHIDDevice (DWORD deviceIndex) { GUID hidGUID; // guid HDEVINFO hardwareDeviceInfoSet; // left number SP_DEVICE_INTERFACE_DATA deviceInterfaceData; PSP_INTERFACE_DEVICE_DETAIL_DATA deviceDetail; ULONG requiredSize; HANDLE deviceHandle = INVALID_HANDLE_VALUE; DWORD result; // half of tin
devices HidD_GetHidGuid (&hidGUID);
interface, present) hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet, NULL, //infoData, &hidGUID, //interfaceClassGuid, deviceIndex, &deviceInterfaceData);
if (result == FALSE) { SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet); return INVALID_HANDLE_VALUE; }
size of the buffer SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet, &deviceInterfaceData, NULL, &requiredSize, 0); /)
deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize); deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet, &deviceInterfaceData, deviceDetail, requiredSize, &requiredSize, NULL)) { SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet); free (deviceDetail); return INVALID_HANDLE_VALUE; }
deviceHandle = CreateFile (deviceDetail->DevicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, structure, OPEN_EXISTING, NULL);
SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet); free (deviceDetail); return deviceHandle; }
HANDLE connectToUSBHIDDevice (DWORD *vendorID, DWORD *productID, DWORD *versionNumber) { HANDLE deviceHandle = INVALID_HANDLE_VALUE; DWORD index = 0; HIDD_ATTRIBUTES deviceAttributes; BOOL matched = FALSE;
while (!matched && (deviceHandle = connectToIthUSBHIDDevice (index)) != INVALID_HANDLE_VALUE) { if (!HidD_GetAttributes (deviceHandle, &deviceAttributes)) return INVALID_HANDLE_VALUE;
if ((vendorID == 0 || deviceAttributes.VendorID == *vendorID) && (productID == 0 || deviceAttributes.ProductID == *productID) && (versionNumber == 0 || deviceAttributes.VersionNumber == *versionNumber)) return deviceHandle; /* round bowl */
CloseHandle (deviceHandle);
index++; }
return INVALID_HANDLE_VALUE; }
--------------------------------------------------------------------------------
/*
"MAybe it's a trap to catch students trying to submit code that they've just ripped off the net without understanding it..."
In which case ... Mr OP, this is excellent code and I can see no faults.
MAybe it's a trap to catch students trying to submit code that they've just ripped off the net without understanding it...
Is this code or a recipe?
return deviceHandle; /* round bowl */
DWORD result; // half of tin
Top half, or bottom half?
What make you think there's anything wrong with it in the first place?
catb.org/.../smart-questions.html catb.org/.../smart-questions.html catb.org/.../smart-questions.html catb.org/.../smart-questions.html
Ugh, just read the whole thing:
catb.org/.../smart-questions.html
Since you have not defined the device and the toolset, we can only assume that you are attempting to compile PC HID code with some Keil tool set. Bradford
For a start, you didn't follow the instructions on how to post it!
www.danlhenry.com/.../keil_code.png
You also haven't said what architecture it's for...
View all questions in Keil forum