javacode:
package cn.com.cloud.sea.nativeTest;
public class NativeCreateDate {
public static void main(String[] args) {
System.loadLibrary("NativeCreateDateDLL");
showDate();
}
public native static void showDate();
}
c++ code:
#include "cn_com_cloud_sea_nativeTest_NativeCreateDate.h"
#include<iostream>
using namespace std;
JNIEXPORT void JNICALL Java_cn_com_cloud_sea_nativeTest_NativeCreateDate_showDate(JNIEnv * env, jclass jclazz)
{
jclass date = env->FindClass("java/util/Date");//创建Date实例
jmethodID method_date_init = env->GetMethodID(date,"<init>","()V");//获得构造函数方法对象
jobject now = env->NewObject(date,method_date_init);//获得当期日期对象
jmethodID method_date_execute = env->GetMethodID(date,"getTime","()J");
jlong time = env->CallLongMethod(now,method_date_execute);
cout<<time<<endl;
}