• JNA使用


    JNA与C对应的数据类型:

    image

    image

    注意:

           使用byte[]对应C++中的char* 可以返回函数执行的结果值

    一、添加JNA需要的jar包

         1、jna.jar

         2、platform.jar

     

    二、编写调用DLL的类

    package rfid;
    
    import com.sun.jna.*;
    import com.sun.jna.ptr.*;
    
    public interface MasterRD extends Library {
    
        MasterRD instance = (MasterRD) Native.loadLibrary("MasterRD",
                MasterRD.class);
    
        int lib_ver(IntByReference ver);
    
        int rf_init_com(int port, NativeLong baud);
    
        int rf_beep(short idev, byte msec);
    
        int rf_request(short idev, byte model, short[] tagtype);
    
        int rf_anticoll(short idev, byte bcnt, byte[] psnr, byte[] prlength);
    
        int rf_select(short idev, byte[] psnr, byte srclen, byte[] size);
    
        int rf_M1_authentication2(short idev, byte model, byte block, byte[] key);
    
        int rf_M1_read(short idev, byte block, byte[] pdata, byte[] plen);
    
        int rf_M1_write(short idev, byte block, byte[] data);
    
        int rf_light(short idev, byte color);
    
        int rf_ClosePort();
    }

    其中MasterRD为MasterRD.dll 文件名,对应于DLL中的函数如下【部分举例】:

    /*
    *    提取DLL接口 
    */
    #ifndef _EXPORT_FUNC_H_
    #define _EXPORT_FUNC_H_
    
    
    #include <Windows.h>
    
    int (WINAPI* lib_ver)(unsigned int *nVer);
    
    int (WINAPI * des_encrypt)(unsigned char *szOut,unsigned char *szIn , unsigned int inlen,unsigned char *key,unsigned int keylen);
    
    int (WINAPI * des_decrypt)(unsigned char *szOut,unsigned char *szIn , unsigned int inlen,unsigned char *key,unsigned int keylen);
    
    int (WINAPI * rf_init_com)(int port,long baud);
    
    int (WINAPI * rf_init_device_number)(unsigned short icdev);
    
    int (WINAPI * rf_get_device_number)(unsigned short *Icdev);
    
    int (WINAPI * rf_get_model)(unsigned short icdev,unsigned short *Version);
    
    int (WINAPI * rf_get_snr)(unsigned short icdev,unsigned char *Snr);
    
    int (WINAPI * rf_beep)(unsigned short icdev,unsigned char msec);
    
    #endif

     

    三、使用

    MasterRD.instance.lib_ver()  ….

  • 相关阅读:
    【转】MyEclipse项目的字符编码设置
    【转】VS2008中 ATL CLR MFC Win32 区别
    【转】字符数组与字符指针
    【转】How to: Convert Between Various String Types
    【转】ATL基础BSTR CComBSTR SysAllocString
    【转】PHP ini_set ini_get 可操作配置参数列表
    【转】字符、字符数组、char、string的区别分析
    【转】PHP 计算页面执行时间
    【转】Java 如何判断String为空?
    【转】Converting char array to BSTR
  • 原文地址:https://www.cnblogs.com/luosongchao/p/3616149.html
Copyright © 2020-2023  润新知