我正在使用此处提供的代码:http://www.microchip.com/forums/tm.aspx?m=278617使用Java通过USB端口传输数据。它在Windows XP 32位操作系统中运行良好。但是当我尝试在Windows 7 32位操作系统环境下调用相同的中断方法发送输出报告时,JNI崩溃了Outsite JVM。崩溃报告可以在这里找到:http://pastebin.com/A9USNFFY
导致JNI崩溃的函数如下:
JNIEXPORT jboolean JNICALL Java_MyHID_IntSendOutputReport(JNIEnv *jEnv, jobject jObj, jbyteArray outputReport)
{
boolean Result = false;
byte *buffer = new byte[Capabilities.OutputReportByteLength];
jboolean isCopy = JNI_TRUE;
buffer = (byte*)jEnv->GetByteArrayElements(outputReport, &isCopy);
/*
API Function: WriteFile
Sends a report to the device.
Returns: success or failure.
Requires:
A device handle returned by CreateFile.
A buffer that holds the report.
The Output Report length returned by HidP_GetCaps,
A variable to hold the number of bytes written.
*/
DWORD BytesWritten = 0;
if (WriteHandle != INVALID_HANDLE_VALUE) Result = WriteFile
(WriteHandle,
buffer,
Capabilities.OutputReportByteLength,
&BytesWritten,
NULL);
delete buffer;
return Result;
}
那么,任何人都可以帮我找到JNI在Windows 7 32位操作系统环境下在JVM外崩溃的原因吗?提前谢谢。
答案 0 :(得分:1)
您的代码完全不正确。很难相信它曾在任何平台上运行。移除new
来电和delete
行。致电buffer
时会分配GetByteArrayElements()
。如果isCopy
设置为TRUE,则必须以ReleaseByteArrayElements()
和buffer
作为参数调用JNI_ABORT
。
您是否意识到有适用于USB的Java包?