在公司里,不同的系統(tǒng)使用不能的語言非常正常,我曾經(jīng)在一個(gè)公司就職,原先的博客系統(tǒng)使用asp編寫的,里面有很多dll文件,在asp里,可直接調(diào)用
dll文件,非常簡單,但由于系統(tǒng)升級后,都統(tǒng)一使用了Java,那么原先編寫的很多模塊(封裝在dll里的)就都不能用了,但有一個(gè)加密算法還非得在客
服系統(tǒng)里用到(因?yàn)樾屡f系統(tǒng)要并行運(yùn)行一段時(shí)間,客服系統(tǒng)必須同時(shí)能管理新舊兩大系統(tǒng)),那么如何在Java中調(diào)用VB編寫的Dll文件呢?代碼如下:
import com.jacob.com.*;
import com.jacob.activeX.*;
public class VbdllCall
{
public static String md5CallVbdll(String str){
String res="";
try {
ActiveXComponent pp = new ActiveXComponent("md5.Class1");
Dispatch myCom = (Dispatch) pp.getObject(); //生成一個(gè)對象
Variant result = Dispatch.call( myCom, "MD5", str) ;
res=result.toString();
}catch (Exception e) {
res="";
e.printStackTrace();
}
return res;
}
}
posted on 2008-12-09 13:18
墻頭草 閱讀(819)
評論(1) 編輯 收藏