Integrated Windows local application to eclipse RCP program

Source: Internet
Author: User
Tags header

Windows applications are very rich, and sometimes some of the features required by our Eclipse RCP programs already have implementations of existing Windows local applications that we want to be able to reuse in our RCP programs. One of the easiest ways to reuse it is to embed the local application window directly in our RCP window. To enable a Windows local application to run in our RCP program, we can use the reparent mechanism provided by Windows. The main process for window embedding using this mechanism is to start the Windows program embedded in our program first, then try to get the main window handle after the program starts, and then set our RCP program's window to the parent window of the Windows Program's main window.

Since we need to start the Windows local program and get its main window handle, these can only be implemented using a Windows local call, so we first use Windows Local invocation to implement the corresponding functionality, and then we invoke it in JNI.

Introduction to JNI

The full name of JNI is the Java Native Interface,jni Standard is part of the Java platform that interacts with code written in Java code and in other languages. Here's a quick introduction to the steps to use JNI:

Writing a Java method with native declarations

Here take HelloWorld as an example:

Listing 1. Hello World Java Code

public class HelloWorld {
  static {
  System.loadLibrary(“helloworld”)}
  }

  public native void print()}

  public static void main(String[] args) {
  HelloWorld hello = new HelloWorld()}
  hello.print()}
  }
}

Compiling Java code and generating a C + + header file:

First compile this Java class: Javac Helloworld.java, and then generate a header file with an. h extension, Java provides a command Javah to generate the header file: Javah–jni HelloWorld, the following list shows the contents of the generated header file:

Listing 2. Hello World C + + header file

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>}
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
  * Class:   HelloWorld
  * Method:  print
  * Signature: ()V
  */
JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *, jobject)}

#ifdef __cplusplus
}
#endif
#endif

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.