JNative调用MFC的dll

amath321 发布于 2011/08/05 10:50
阅读 1K+
收藏 1

public class TestCallBack implements Callback{
	Shell shell;
	public static void main(String[] args) {
		new TestCallBack().test();
	}
	public void test(){
		Display display = new Display();// Display.getDefault();
		shell = new Shell(display);

		shell.open();
		
		String dll = "MfcDialogCallback.dll";
		String callFunc = "SetMyCallbackFunc";
		String showFunc = "InitDlg";
		String hwndFunc = "SetMyHwnd";
		
		TestCallBack callback = new TestCallBack();
		try {
			JNative open = new JNative(dll, showFunc);
			open.invoke();
			
//			JNative setHwnd = new JNative(dll, hwndFunc);
//			setHwnd.setParameter(0, shell.handle);
//			setHwnd.invoke();

			JNative regCall = new JNative(dll, callFunc);
			regCall.setRetVal(Type.VOID);
			regCall.setParameter(0, callback.getCallbackAddress());
			JNative.releaseCallback(callback);
			regCall.invoke();
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()){
				display.sleep();
			}
		}
		display.dispose();
	}
	
	public int callback(long[] arg0) {
		
		System.out.println("callback!");
		return 100000;
	}

	public int getCallbackAddress() throws NativeException {
		System.out.println("getCallbackAddress");
		return JNative.createCallback(1, this);
	}

}
程序运行时,在调用一次回调函数后,会出现下图,程序自动关闭了。哪有错误么。。

加载中
返回顶部
顶部