Basic knowledge of vegetable chicken crawl Pit
Because of the keygen of something I will only build under WIN!! So only this is the worst!!
Before has been the android under the call so file with JNI, now try Java in the win platform to call the DLL first or the old routine, directly in the DLL popped a message box the concrete flow is as follows: Define a method in Java, implement this method in C + +, pop the message box inside the method.
First define a class in Java
Code:
Package Cn.ylca.dll;public class Dllentity {//local method public native void MessageBox ();}
Second step console to bin directory
Using Javah to generate Dllentity header files
The resulting file contents are as follows
Code:
/* Don't EDIT this file-it are machine generated */#include <jni.h>/* Header for class cn_ylca_dll_dllentity */#if Ndef _included_cn_ylca_dll_dllentity#define _included_cn_ylca_dll_dllentity#ifdef __cplusplusextern "C" {#endif/** class:cn_ylca_dll_dllentity* method:messagebox* Signature: () v*/jniexport void Jnicall java_cn_ylca_dll_dllentity _messagebox (jnienv *, jobject); #ifdef __cplusplus} #endif #endif
Third step to create a new DLL project
Then copy the content you just generated to the CPP file and you'll need a jni.h header file to copy it to the include file in the JDK directory.
The code is as follows
Code:
javadll.cpp : Defines the entry point for the DLL application.//#include "stdafx.h" #include <stdio.h> #include <windows.h>BOOL Apientry dllmain ( HANDLE hModule, dword ul_reason _for_call, LPVOID lpReserved ) { return true;} /* do not edit this file - it is machine generated */#include "jni.h"/* header for class cn_ylca_dll_dllentity */#ifndef _ included_cn_ylca_dll_dllentity#define _included_cn_ylca_dll_dllentity#ifdef __cplusplusextern " C " {#endif/** class: cn_ylca_dll_dllentity* method: messagebox* Signature: () V*/ jniexport void jnicall java_cn_ylca_dll_dllentity_messagebox (jnienv *env, jobject obj) {// Fill in the parameter name //here, you're not allowed to say anything else! messagebox (null, "Test!", "demo", 0);} #ifdef __cplusplus} #endif #endif
The fourth step is how to use the creation of a test class in Java to invoke
Code:
public class Test {public static void main (string[] args) {//load DLL for the specified path system.load ("D://javadll//debug//javadll.dll"); Create local Method Object Dllentity dllentity = new dllentity (); Call Method Dllentity.messagebox (); }
Java calls a dynamic-link library (DLL)