我写了一个基于对话框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调用的方法体就在这里面。
请大家帮帮我,这事儿急!

解决方案 »

  1.   

    我是新建了Win32 Dynamic-link Library的空工程,然后把Borrow.h添加进去,再写一Borrow.cpp,想这样子生成DLL,可是事实是不行,好多错误。
      

  2.   

    好像得封装成COM,
    你新建一个mfc的activeX工程来吧
      

  3.   

    查JNI,java native interface
      

  4.   

    回:akirya
    你能说得详细点吗?回eduyu
    我查了,可是好像跟JNI没关系
      

  5.   

    java不支持MFC的DLL,你自己做成regular DLL,然后手工添加MFC支持。
    MFC的DLL必须用AfxLoadLibrary来加载,java是用LoadLibrary来加载的。
      

  6.   

    由于JNI只支持函数级别的互操作,所以思路大概这样,用java写个wrap的类,类的方法来自于c++写的dll。代码如下:1 这是你的java的wrap的类,注意有个native的方法,表示java不定义此函数,定义在随后要load的dll里。class Timer {
      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;
    }
      

  7.   

    谢谢eduyu如此热心回答,可惜我不是JAVA上面的问题,是VC的问题,MFC程序不能生成DLL文件。。算了,夜了,先下班了。希望明早能看到曙光:)