日期:2014-05-20 浏览次数:20817 次
// JNITest.cpp : 定义 DLL 应用程序的导出函数。
//
#include "stdafx.h"
JNIEXPORT void JNICALL Java_edu_hebut_JNITest_JNI_testPrint (JNIEnv * env, jclass obj, jstring msg)
{
const jchar* strMsg= env->GetStringChars(msg,0);
MessageBox(0,(LPCWSTR)strMsg,L"调用VC++的MessageBox!",0);
env->ReleaseStringChars(msg,strMsg);
}
JNIEXPORT jint JNICALL Java_edu_hebut_JNITest_JNI_testAdd (JNIEnv *env, jclass obj, jint a, jint b)
{
long ca=a,cb=b,cr=a+b;
WCHAR msg[100];
wmemset(msg,0,sizeof(WCHAR)*100);
swprintf_s(msg,100,L"%d + %d = %d",ca,cb,cr);
MessageBox(0,msg,L"加法运算",0);
return a+b;
}
package edu.hebut.JNITest;
public class JNI {
public static native void testPrint(String msg);
public static native int testAdd(int a,int b);
}
/**
*
*/
package edu.hebut.JNITest;
import edu.hebut.JNITest.JNI;
/**
* @author
*
*/
public class JNITest {
static {
System.loadLibrary("JNITest");
}
/**
* @param args
*/
public static void main(String[] args) {
//System.out.println(System.getProperty("java.library.path"));
//JNI.testPrint("hello,JNI!");
System.out.println(JNI.testAdd(1, 2));
}
}