【发布时间】:2016-05-04 01:45:02
【问题描述】:
我有一个 Eclipse RCP 产品可以很好地与键盘和鼠标配合使用。我想在我的产品中支持自定义硬件。 为了在 Eclipse RCP 产品中启用该设备,我编写了 JNI 代码。此 JNI 代码初始化设备和驱动程序(正常工作)。调用此 JNI 方法后,RCP 应用程序代码开始接收 Display.readAndDispatch() 方法中的事件。我不明白的是,如何将此事件传递给我的小部件类。所有 SWT 小部件都有处理事件的 windowProc 方法。这些方法只处理预定义的事件,它们是私有(包私有)方法,所以我不能事件覆盖它们。
在http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm 页面的原生小部件部分,他们解释了如何在 C++ 代码中向 windowProc 方法添加挂钩。我尝试通过以下方式做到这一点:
JNIEXPORT jint JNICALL Java_com_aiit_iadss_framework_event_SpaceMouseEventManager_initInternal
(JNIEnv *env, jobject obj, jlong hwnd )
{
fprintf(stderr, "Initializing the space mouse module!");
//code to init the device & driver
if( res > 0 )
{
//the initialization was successful. Setup the 3D mouse event listener
WM_3DMOUSE = RegisterWindowMessage (_T("SpaceWareMessage00"));
//adding hook on RCP application window for WindowProc
oldProc = (WNDPROC) SetWindowLongPtr((HWND) hwnd, GWLP_WNDPROC, (long) WindowProc);
}
return res;
}
LRESULT CALLBACK WindowProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
int num; /* number of button returned */
//SiSpwEvent Event; /* 3DxWare Event */
//SiGetEventData EData; /* 3DxWare Event Data */
if( msg == WM_3DMOUSE )
{
fprintf( stderr, "Space mouse event caught!");
return (TRUE);
}
//call windowproc to handle other events
return CallWindowProc( oldProc, hwnd, msg, wParam, lParam );
}
当我运行上面的代码时,JVM 崩溃并出现访问冲突代码。 你能帮我解决这个问题吗?
【问题讨论】:
标签: java c++ eclipse java-native-interface eclipse-rcp