栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Java引入C++的库 并使用相应的接口

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java引入C++的库 并使用相应的接口

Java引入C++的库
  • 1、创建类实现Library
  • 使用

1、创建类实现Library
package com.zkhx.jna;

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

public interface IData2CCompentLibrary extends Library {

//    IData2CCompentLibrary INSTANCE = Native.loadLibrary("C:\Users\Rosa\Desktop\CPlusPlusNetworkModule.dll", IData2CCompentLibrary.class);
       IData2CCompentLibrary INSTANCE = Native.loadLibrary("D:\devlopment_tool\CPlusPlusNetworkModule.dll", IData2CCompentLibrary.class);

//    String setJStringToJson(String pcServiceIp,int size);
//    const char* setJStringToJson(const char * pcServiceIp,int size);


    
    String CplusplussetJStringToJson(String pcdata, int size);
	
}

使用
protected void channelRead0(ChannelHandlerContext channelHandlerContext, 
DatagramPacket msg) throws Exception {

 //读取网络包数据,转换为16进制字符串
  ByteBuf content2 = msg.content();


  ByteBuf copy = content2.copy();
  int sidInt = copy.readIntLE();//获取信源地址
  int didInt = copy.readIntLE();//获取目的地址
  copy.readIntLE();//信息类别
  String sidHex = Integer.toHexString(sidInt).toUpperCase();
  String didHex = Integer.toHexString(didInt).toUpperCase();

  if (!didHex.equalsIgnoreCase("A001")) return;

  //调用dll库解析网络包数据
  byte[] bytes = new byte[content2.readableBytes()];
  content2.readBytes(bytes);
  String data = bytesToHexString(bytes);
  int length = data.length();

  String resultJson = null;
     switch (sidHex) {
            case "1001": 
  				resultJson = IData2CCompentLibrary.INSTANCE.CplusplussetJStringToJson(data, length);
  		
  		}
}		
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1001991.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号