JAVA is a software development language running on virtual machines. It relies on virtual machines to explain bytecode, cleverly implementing cross-platform. JAVA is relatively secure because it is closed. However, external calls are implemented through the JNI dynamic library. Today, we will explain how to develop a JNI dynamic library for vc6.0 configuration.
1, need to download resources 1, jdk-7u45-windows-i586 2, vc6.0.
2. Compile a java Helloworld class
Public class HelloWorld {public native void displayHelloWorld (); // declare static {System. loadLibrary ("HelloWorldImpl"); // load the dynamic link library. "HelloWorldImpl" is the name of the dynamic link library to be loaded .} Public static void main (String [] args) {// TODO Auto-generated method stubHelloWorld helloWorld = new HelloWorld (); helloWorld. displayHelloWorld ();}}
3. Export HelloWorld. h
d:\JNI>javac HelloWorld.java
The exported content is as follows:
/* DO NOT EDIT THIS FILE - it is machine generated */#include
/* Header for class HelloWorld */#ifndef _Included_HelloWorld#define _Included_HelloWorld#ifdef __cplusplusextern "C" {#endif/* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject);#ifdef __cplusplus}#endif#endif
4. Use the vc6.0 win32dll project to add the header file and write the local implementation file
#include "HelloWord.h"#include
#include
/* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject) { printf("Hello World!\n"); return;}
5. Configure the header file of vc6.0 to include directories and library files. And pin the newly added Path to the top.
Last step compilation
Successful.