用jni的方法通过C++写了一个dll后,其他的java程序怎么调用这个dll中的方法?

解决方案 »

  1.   

    dll的函数的命名是否符合要求,即包括“包名_类名_方法名”?
    如果符合要求,则定义名称为“包名”的包中的名称为“类名”的类;
    再在类中定义名称为“方法名”的方法。不同平常的是要加上native前缀。
    把dll文件放在loadlibrary能发现的地方(path路径中即可)。
      

  2.   

    因此,一般不会出现这种情况:先编dll在设计java类。
    jni只是实现java与本地语言互相访问的方法。
    应该重在设计java类的功能,具体到某个方法需要用native来实现,再写dll。
      

  3.   

    import java.io.*;public class qq{
    static
    {
    System.loadLibrary("GBandBIG5");
    }         //GbToBig5 : Convert gb code to big5 code
    public native static String GbToBig5(String inStr); public static void main(String[] args){
    String test="上海敏杰软件有限公司";  try{
    System.out.println(qq.GbToBig5(test));
    String res=qq.GbToBig5(test); FileWriter t = new FileWriter("hello.txt");
    t.write(res,0,res.length());
    t.flush();
    }catch(IOException e){
    }
    }
    }
    编译通过,运行的时候出错:java.lang.UnsatisfiedLinkError: GbToBig5
    注:GbToBig5.dll是我通过jni在c++中实现的,上面的程序是我另外写的一个测试程序,用来测试GbToBig5()这个方法。