- public class APCluster {
- public native int[] CallAPClusterDll( int arg_Int,
- double[] arg_DoubleArray,
- boolean arg_boolean);
- static
- {
- System.loadLibrary("APClusterDllMedium");
- }
- }
- /* DO NOT EDIT THIS FILE - it is machine generated */
- #include <jni.h>
- /* Header for class APCluster */
- #ifndef _Included_APCluster
- #define _Included_APCluster
- #ifdef __cplusplus
- extern "C" {
- #endif10 /*
- * Class: APCluster
- * Method: CallAPClusterDll
- * Signature: (I[DZ)[I
- */
- JNIEXPORT jintArray JNICALL Java_APCluster_CallAPClusterDll
- (JNIEnv *, jobject, jint, jdoubleArray, jboolean);
- #ifdef __cplusplus
- }
- #endif21
- #endif
- #include "APCluster.h"
- #include <stdio.h>
- #include <windows.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef int* (__stdcall *APCLUSTER32)(double*, unsigned int, bool);
- JNIEXPORT jintArray JNICALL Java_APCluster_CallAPClusterDll
- (JNIEnv *env, jobject _obj, jint _arg_int, jdoubleArray _arg_doublearray, jboolean _arg_boolean)
- {
- HMODULE dlh = NULL;
- APCLUSTER32 apcluster32;
- if (!(dlh=LoadLibrary("apclusterwin.dll"))) //第三方DLL位置
- {
- printf("LoadLibrary() failed: %d\n", GetLastError());
- }
- if (!(apcluster32 = (APCLUSTER32)GetProcAddress(dlh, "apcluster32"))) //具体调用apcluster32方法
- {
- printf("GetProcAddress() failed: %d\n", GetLastError());
- }
- int m_int = _arg_int; //类型转换
- double* m_doublearray = env->GetDoubleArrayElements(_arg_doublearray, NULL);
- bool m_boolean = _arg_boolean;
- int* ret = (*apcluster32)(m_doublearray, m_int, m_boolean); /* actual function call */
- jintArray result = env->NewIntArray(_arg_int);
- env->SetIntArrayRegion(result, 0, _arg_int, (const jint*)ret);
- FreeLibrary(dlh); /* unload DLL and free memory */
- if(ret)
- {
- free(ret);
- }
- return result;
- }
- #ifdef __cplusplus
- }
- #endif
(JNIEnv *env, jobject _obj, jint _arg_int, jdoubleArray _arg_doublearray, jboolean _arg_boolean) ......
- typedef unsigned char jboolean;
- typedef unsigned short jchar;
- typedef short jshort;
- typedef float jfloat;
- typedef double jdouble;
- jintArray result = env->NewIntArray(_arg_int);
- env->SetIntArrayRegion(result, 0, _arg_int, (const jint*)ret);
- public class Test
- {
- public static void main(String[] args)
- {
- double arg_doublearray[] = {0.1, 0.2, 0.3};
- int arg_int = 3;
- boolean arg_boolean = true;
- int[] result = new APCluster().CallAPClusterDll(arg_int, arg_doublearray, arg_boolean);
- .....
- }
- }
上一篇:OpenGL开发包介绍