可以不用jni 具体望了明天查了看
http://expert.csdn.net/Expert/topic/1647/1647824.xml?temp=.6572077

解决方案 »

  1.   

    什么是jni啊!我还不知道呢!mfc呢?dll又是什么啊!
    怎么这么深奥啊!
      

  2.   

    我看到过一个xMethod还是xFunction(你到Google查一下),它是个java包,你可以不用懂JNI就可调用dll。
      

  3.   

    //JNI-使用JNI调用dll.txt可以考虑使用JNI。
    分两种情况:
    1、如果你已经有一个DLL了,需要在Java中使用:
       可以先在Java中声明相应的方法,然后生成.h,再依据.h新建一个DLL调用旧的DLL中的东东
    2、如果没有DLL,则好办:
       可以先在Java中声明相应的方法,然后生成.h,再依据.h新建一个DLL
    假定工作目录在:F:\java\1、源代码:
    //:testdll.javapublic class testdll { 
      static { 
        System.loadLibrary("testdll"); 
      }   public native static int get(); 
      public native static void set(int i); 
      public static void main(String[] args) { 
        testdll test = new testdll(); 
        test.set(10); 
        System.out.println(test.get()); 
      } 
    } 2、使用javah:
    javah testdll
    则会在当前目录下生成F:\java\testdll.h文件,这个文件需要被C/C++程序调用来生成所需的库文件。
    内容如下:
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class testdll */#ifndef _Included_testdll
    #define _Included_testdll
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     testdll
     * Method:    get
     * Signature: ()I
     */
    JNIEXPORT jint JNICALL Java_testdll_get
      (JNIEnv *, jclass);/*
     * Class:     testdll
     * Method:    set
     * Signature: (I)V
     */
    JNIEXPORT void JNICALL Java_testdll_set
      (JNIEnv *, jclass, jint);#ifdef __cplusplus
    }
    #endif
    #endif3、
    对于已生成的f:\java\testdll.h头文件,C/C++所需要做的,就是把它的各个方法具体的实现。
    然后编译连接成库文件即可。
    再把库文件拷贝到JAVA程序的路径下面,就可以用JAVA调用C/C++所实现的功能了。 4、testdll.cpp文件具体实现这两个函数: 
    a、在vc中新建...-工程-Win32 Dynamic-Link Library,输入相关信息(工程名为testdll)
    b、新建...-文件-C++Source Files,输入相关信息(文件名为testdll)
    c、输入cpp内容: 
    #include "testdll.h" 
    int i = 0; 
    JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass) 

    return i; 

    JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint j) 

    i = j; 

    d、编译之前,需要设置工具-选项-Directories(Platform:Win32  Show directories for:Include files),加入三个目录:
    F:\J2SDK1.4.1-01\INCLUDE
    F:\J2SDK1.4.1-01\INCLUDE\WIN32
    F:\JAVA(此目录即testdll.h所在的目录)5、编译连接成库文件,本例是在WINDOWS下做的,生成的是testdll.DLL文件。
    并且名称要与JAVA中需要调用的一致,这里就是testdll.dll 6、把testdll.dll拷贝到testdll.class的目录下,java testdll运行它,就可以观察到结果了。 
      

  4.   

    干吗非用jndi不可 我原来做的就没有这么复杂 
    dll里的方法必须在这里声明为本地的  dll是c++builder做的
    public class GetData {
      public native String GetSerial(String S1);  public native String GetIP(String S1);  public native String GetMAC(String S1);  public native String GetCorp(String S1);  public native byte[] baGetCorp(String S1);  static {
        System.loadLibrary("Antiscan"); 
      }  public String getcorp(String S1) {
        String bS = null;
        byte ba[] = baGetCorp(S1);  //这里调用dll里的方法
        if (ba != null) {
          bS = new String(ba);
        }
        return bS;
      }
    }
    这个是我已经成功使用的例子