我写了一个基于对话框MFC程序,现在有一个JAVA APPLET要调用到我这个程序里的一个类里的一个方法,要怎么做?听别人说要把我的程序编译成DLL然后JAVA APPLET再通过这个DLL来调用我的方法,那要怎么编译成DLL?下面是Borrow.h头文件内容:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
/* Header for class Borrow */#ifndef _Included_Borrow
#define _Included_Borrow
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Borrow
* Method: jieshu
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_Borrow_jieshu
(JNIEnv *, jobject, jstring);#ifdef __cplusplus
}
#endif
#endif
下面是Borrow.cpp内容:
#include "Borrow.h"
#include "CarrierDlg.h"
JNIEXPORT jboolean JNICALL Java_Borrow_jieshu (JNIEnv *, jobject, jstring s)
{
str = s;
return 0;
}这样子编译出现了好多错误:'CWnd' : base class undefined
'CDialog' : base class undefined等很多。
CarrierDlg.h是基于对话框MFC程序的一个头文件,供JAVA APPLET调用的方法体就在这里面。
请大家帮帮我,这事儿急!
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
/* Header for class Borrow */#ifndef _Included_Borrow
#define _Included_Borrow
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Borrow
* Method: jieshu
* Signature: (Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_Borrow_jieshu
(JNIEnv *, jobject, jstring);#ifdef __cplusplus
}
#endif
#endif
下面是Borrow.cpp内容:
#include "Borrow.h"
#include "CarrierDlg.h"
JNIEXPORT jboolean JNICALL Java_Borrow_jieshu (JNIEnv *, jobject, jstring s)
{
str = s;
return 0;
}这样子编译出现了好多错误:'CWnd' : base class undefined
'CDialog' : base class undefined等很多。
CarrierDlg.h是基于对话框MFC程序的一个头文件,供JAVA APPLET调用的方法体就在这里面。
请大家帮帮我,这事儿急!
你新建一个mfc的activeX工程来吧
你能说得详细点吗?回eduyu
我查了,可是好像跟JNI没关系
MFC的DLL必须用AfxLoadLibrary来加载,java是用LoadLibrary来加载的。
private long last_time;
private String last_comment;
/** Return time in milliseconds since last call,
* and set last_comment. */
native long sinceLast(String comment);
static
{
System.loadLibrary("dllname");//dllname为你dll的名字,例如dllname.dll
}
}2 用javah -jni Timer 生成c++可用的.h文件3 这是c++在dll内的代码,可以看到附加了很多改函数应用在java内的环境信息
extern "C" /* specify the C calling convention */
jdouble Java_Timer_sinceLast (
JNIEnv *env, /* interface pointer */
jobject obj, /* "this" pointer */
jstring comment) /* argument #1 */
{
// Note that the results of the first three statements
// could be saved for future use (though the results
// have to be made "global" first).
jclass cls = env->FindClass("timing.Timer");
jfieldId last_time_id = env->GetFieldID(cls, "last_time", "J");
jfieldId last_comment_id = env->GetFieldID(cls, "last_comment",
"Ljava_lang_String;"); jlong old_last_time = env->GetLongField(obj, last_time_id);
jlong new_last_time = calculate_new_time();
env->SetLongField(obj, last_time_id, new_last_time);
env->SetObjectField(obj, last_comment_id, comment);
return new_last_time - old_last_time;
}