Thank you very much. I have one problem too. I wrote the library successfully. When I use this library on Windows 10 32 bit system I can read and write. But when I run on window 7 32 bit system i can write only. when i try to read always return 0 bytes. I check the code and found that on windows 7 32 bit sytem HidD_GetInputReport return false. How can I solve this problem? why library work on windows 10 and not windows 7.
UPDATE
When I run my program on windows 7(32 bit system) GetInputReport return error code 23. But when I run on windows 10(32 bit) system it works correctly without any problem
23: Data error (cyclic redundancy check) I don't know how is possible.
here is my code which i used to reading data from my device:
JNIEXPORT jbyteArray JNICALL Java_RatingTerminal_CtrlReadInputReport(JNIEnv *jEnv, jobject jObj)
{
byte *buffer;
printf("report length %d",Capabilities.InputReportByteLength);
if (DeviceHandle == INVALID_HANDLE_VALUE) {
printf("DeviceHandle is invalid handle value\n");
return jEnv->NewByteArray(0);
}
buffer = new byte[Capabilities.InputReportByteLength];
//Read a report from the device using a control transfer.
/*
HidD_GetInputReport
Returns:
True on success
Requires:
A device handle returned by CreateFile.
A buffer to hold the report.
The report length returned by HidP_GetCaps in Capabilities.InputReportByteLength.
*/
if (!HidD_GetInputReport(DeviceHandle, buffer, Capabilities.InputReportByteLength))
{
DWORD lastError = GetLastError();
//You have to cache the value of the last error here, because the call to
//operator<<(std::ostream&, const char *) may cause the last error to be set
//to something else.
std::cout << "Reading failure. GetLastError returned "
<< lastError << ".";
delete buffer;
return jEnv->NewByteArray(0);
}
jbyteArray inputReport = jEnv->NewByteArray(Capabilities.InputReportByteLength);
jEnv->SetByteArrayRegion(inputReport, 0, Capabilities.InputReportByteLength, (jbyte*)buffer);
delete buffer;
return inputReport;
}