Java中可以调用Com组件吗?

shadows_ 2002-02-26 10:41:03
请给个例子!谢谢!
...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
armyshu 2002-02-26
  • 打赏
  • 举报
回复
读取网卡的MAC地址,用到WINDOWS的DLL库,只要将方法申明为NATIVE就行
public class MACCode {

public static void main(String args[]) {

MACCode mac = new MACCode();
System.out.println("本机网卡MAC地址为 "+mac.getFormattedCode());
}

public native String getMACCode();

static {

System.loadLibrary("MACCodeDLL") ;
}

public String getFormattedCode() {

String code = this.getMACCode();
code = code.toUpperCase();
code = code.substring(0,2)+"-"+code.substring(2,4)+
"-"+code.substring(4,6)+
"-"+code.substring(6,8)+
"-"+code.substring(8,10)+
"-"+code.substring(10,12);
return code;
}

}
armyshu 2002-02-26
  • 打赏
  • 举报
回复
public class MACCode {

public static void main(String args[]) {

MACCode mac = new MACCode();
System.out.println("本机网卡MAC地址为 "+mac.getFormattedCode());
}

public native String getMACCode();

static {

System.loadLibrary("MACCodeDLL") ;
}

public String getFormattedCode() {

String code = this.getMACCode();
code = code.toUpperCase();
code = code.substring(0,2)+"-"+code.substring(2,4)+
"-"+code.substring(4,6)+
"-"+code.substring(6,8)+
"-"+code.substring(8,10)+
"-"+code.substring(10,12);
return code;
}

}
该例子为读取机子的网卡MAC地址,用到了WINDOWS的DLL库,在JAVA中调用时只需要将方法申明为native就行了
ChDw 2002-02-26
  • 打赏
  • 举报
回复
需要使用JNI方法,使用C语言编写一个DLL然后调用

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧