用jni.
呵呵,具体我不会 :)

解决方案 »

  1.   

    java的jni目录中有jni.h,里面是java与c++的接口函数
      

  2.   

    好象还是loadlibrary具体忘了原来做过一个等回家查查先
      

  3.   

    使用 java.lang.Runtime.loadLibrary(String libname)方法
    这个方法必须被静态初始化static { System.loadLibrary("LibFile"); }
     好象在你调用这个dll的类里必须先声明dll里的方法 而且必须声明为静态的。具体要等到我回去查查原来的程序 周一再继续
      

  4.   

    看了别人的帖子又想起一点 dll里的方法在类里必须先声明成native的静态方法
      

  5.   

    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;
      }
    }
    这个是我已经成功使用的例子
      

  6.   

    1.Write a Class to declare the native method:
    public class ShowMsg
    {
    static 
    {
    System.loadLibrary("showlib");
    }

    public String getEncodeString(String sin)
    {
    byte[] bts = sin.getBytes();
    return new String(getNativeEncodeBytes(bts,bts.length));
    }

    public native byte[] getNativeEncodeBytes(byte[] sinbts,int btlen);
    }
      

  7.   

    2.Use javah.exe to get a C++ head file:
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <c:\jdk\include\jni.h>
    /* Header for class ShowMsg */#ifndef _Included_ShowMsg
    #define _Included_ShowMsg
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     ShowMsg
     * Method:    getNativeEncodeBytes
     * Signature: ([BI)[B
     */
    JNIEXPORT jbyteArray JNICALL Java_ShowMsg_getNativeEncodeBytes
      (JNIEnv *, jobject, jbyteArray, jint);#ifdef __cplusplus
    }
    #endif
    #endif
      

  8.   

    3.Write your implemention code in a C++ file:
    #include <C:\Microsoft\Microsoft Visual Studio\VC98\Include\CTYPE.H>
    #include <c:\jdk\include\jni.h>
    #include <c:\jdk\include\win32\jni_md.h>
    #include "c:\jni\ShowMsg.h"
    #include <C:\Microsoft\Microsoft Visual Studio\VC98\Include\stdio.h>#define BUFFSIZE 256JNIEXPORT jbyteArray JNICALL Java_ShowMsg_getNativeEncodeBytes(JNIEnv *env, jobject this, jbyteArray buf, jint bufsize)
    {
    char sIn[BUFFSIZE];
    char sOut[BUFFSIZE];

    (*env)->GetByteArrayRegion(env,(jbyteArray)buf,0,bufsize,sIn);
    sIn[bufsize] = 0;
             // This is my C++ api,you must NOT use!!!! :)
    pwd_encode(sIn,sOut);
    //printf("%s=>%s",sIn,sOut);

    buf = (*env)->NewByteArray(env,bufsize*2);
    (*env)->SetByteArrayRegion(env,buf,0,bufsize*2,sOut);

    return buf;
    }
      

  9.   

    上面的是个完整的例子(除了我调用的另一个C的代码),如果你要调用DLL,只要在该C文件中调用那个DLL的接口即可.另外:我不需要你的分,分对我来说没多大意义,你给那些想要的人吧:)
    不过我希望你能关注我的Kylin
      

  10.   

    我要说的 全被ATONER说了,哎
      

  11.   

    使用xFuntion来调用,它是一个java包。应该比JNI方便。到Google上查一下。
      

  12.   

    要是在JAVA中频繁调用DLL,会不会降低效率,致使速度较慢呢?