使用java运行dll文件方法

本文介绍了如何使用JavaNativeAccess(JNA)库加载并操作WindowsDLL文件,通过WinningChssInterfaceDLL接口实现与COM组件的交互,展示了GetCardStatus方法的调用过程。
摘要由CSDN通过智能技术生成
  1. 引入依赖
 <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>5.9.0</version>
        </dependency>
  1. 创建接口类
public interface WinningChssInterfaceDLL extends Library {
	//加载文件。
    WinningChssInterfaceDLL INSTANCE = Native.loadLibrary("C:\\Users\\admin\\Desktop\\usb3ea.dll",WinningChssInterfaceDLL.class);
   //定义ddl文件的方法
    int GetCardStatus(Boolean a, Boolean b);
    void SetEncoding(short CardNo, int PackingVer, int FramingVer, int encoding, int bits);
    void StopSample();
    }
  1. 继承了Structure,与本地代码进行交互
@Data
public class COMWAVEDATA extends Structure {
    public int FrameNo;
    public long ArrivingTimeus;
    public int usInArrivingTime;
    public int nsInArrivingTime;
    public double Amp;
    public int ChannelId;
    public SYSTEMTIME ArrivingTimeST;
    public int RingdownCount;
    public int RisingRingdownCount;
    public long DurationTimeus;
    public long RiseTimeus;
    public double Enery;
    public double RMS;
    public double ASL;
    public long ArrivingTimens;
    public long DurationTimens;
    public long RiseTimens;
    public double[] ExParam = new double[17];
	//getFieldOrder 方法指定了这些字段的顺序,这在涉及到本地代码的情况下很重要,因为它确保了Java对象的布局与本地代码的期望布局相匹配。
    @Override
    protected List getFieldOrder() {
        return Arrays.asList(new String[]{"FrameNo", "ArrivingTimeus", "usInArrivingTime", "nsInArrivingTime", "Amp", "ChannelId", "ArrivingTimeST", "RingdownCount", "RisingRingdownCount"
                , "DurationTimeus", "RiseTimeus", "Enery", "RMS", "ASL", "ArrivingTimens", "DurationTimens", "RiseTimens", "ExParam"});
    }
  1. 调用方法
 int len = WinningChssInterfaceDLL.INSTANCE.GetCardStatus(true, true);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值