Reputation: 63
I have an Eclipse RCP product working well with keyboard and mouse. I want to support a custom hardware in my product. To enable the device in the Eclipse RCP product, I have written JNI code. This JNI code initializes the device & driver (which is working correctly). After calling this JNI method the RCP application code starts receiving the events in Display.readAndDispatch() method. What I don't understand is, how to get this events to my widget class. All SWT widgets have windowProc methods which handles the events. These methods only handles predefined events and they are private (package private) methods, so I can't event override them.
At http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm page, in native widget section, they explained about adding a hook to windowProc method in the C++ code. I tried doing that in following way:
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 );
}
When I run above code, the JVM crashes with access violation code. Can you please help me with solving the issue?
Upvotes: 0
Views: 88
Reputation: 63
Ok, I finally did this by adding the WindowProc handler in Java code as below:
Callback winprocCallback = new Callback( MyEventProcessingClass.class, "windowProc", 4 );
MyEventProcessingClass.oldWinProc = OS.SetWindowLongPtr( shellHandle, OS.GWLP_WNDPROC,
winprocCallback.getAddress() );
And the windowProc method is implemented as:
public static long windowProc( long hwnd, long msg, long wparam, long lParam )
{
if( msg == 'My device event id' )
{
//process it & return 1;
}
return OS.CallWindowProc( SpaceMouseServiceImpl.oldWinProc, hwnd, (int) msg, wparam, lParam );
}
This way I was able to process the custom event in my code.
Upvotes: 0