日期:2014-05-19 浏览次数:20702 次
public class AAA { static { System.load("C:/AUTO_INIT.dll"); } public native static int auto_init(int a,int b); public static void main(String args[]){ AAA new_auto_init = new AAA(); System.out.println("Result="+new_auto_init.auto_init(0, 38400)); } }
/* DO NOT EDIT THIS FILE - it is machine generated */ #include "jni.h" /* Header for class AAA */ #ifndef _Included_AAA #define _Included_AAA #ifdef __cplusplus extern "C" { #endif /* * Class: AAA * Method: auto_init * Signature: (II)I */ JNIEXPORT jint JNICALL Java_AAA_auto_1init (JNIEnv *, jclass, jint, jint); #ifdef __cplusplus } #endif #endif /////////////////////////////////////////////////////// #ifndef _DLL_H_ #define _DLL_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ class DLLIMPORT DllClass { public: DllClass(); virtual ~DllClass(void); private: }; #endif /* _DLL_H_ */
/* Replace "dll.h" with the name of your header */ #include<windows.h> #include<stdio.h> #include "AUTO_INIT.h" #include <windows.h> JNIEXPORT jint JNICALL Java_AAA_auto_1init (JNIEnv * nev, jclass obj, jint a, jint b){ //const int * aa=a; //const int * bb=evn->GetInt(b); //void * objptr = CreateAUTO_INIT(); HINSTANCE hdll = NULL; hdll = LoadLibrary ( "Mwic_32.dll" ); typedef BOOL ( _stdcall *lpFileEncrypt )( INT, INT); lpFileEncrypt FileEncrypt1; FileEncrypt1 = ( lpFileEncrypt )::GetProcAddress( hdll, "auto_init" );//调用dll中的函数 int result = FileEncrypt1(0,38400); FreeLibrary( hdll ); //printf("restult=%d",result); //int result=auto_init(a,b); //env->ReleaseInt(a,aa); //env->ReleaseInt(b,bb); return result; } DllClass::DllClass() { } DllClass::~DllClass () { } BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } /* Returns TRUE on success, FALSE on failure */ return TRUE; }