64位jdk 調用32位dll


 

delphi有一部分邏輯翻譯成java未遂,想到dll封裝

又奈何導出的是32位dll,切jdk版本不太合適

嘗試了一些網上的辦法,技術不達標,最后還是用java搞咯,輕車熟路的

 

我的大體思路:寫個調用dll的java文件,cmd用32位jdk運行,程序執行cmd命令

 

1、准備:jdk 、jna.jar

2、寫個調用dll的方法(關鍵詞替換掉了)

import com.sun.jna.Library;
import com.sun.jna.Native;

public class testDll {

    public static void main(String[] args) {
        System.load(args[1]+"****.dll");
        testDll.testInter test = (testDll.testInter) Native.loadLibrary("****", testInter.class);
        System.out.println(test.test(args[0]));
    }

    public interface testInter extends Library {
        public String test(String str);
    }
}

3、編譯,我把jna,jar放到了bin目錄

D:
cd D:\softwares\Java\java32\jdk1.7.0_65\bin
javac.exe -classpath jna-4.1.0.jar testDll.java

4、試下效果

傳了兩個參數,
dll所在的目錄當成參數傳過來了

java.exe -cp .;jna-4.1.0.jar passEncode testStr D:\

 

java調用:

Process process = Runtime.getRuntime().exec("cmd /c cd "+path+" &&java -cp .;jna-4.1.0.jar testDll "+str + " "+path+"/");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while((line=reader.readLine())!=null){result.append(line);}
reader.close();
process.destroy();

 

算是能解決我的問題,不通用處還請多多指教


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM