如何用C语言结构定义转换成Java code? [英] How to convert C language structure definition into Java code?
本文介绍了如何用C语言结构定义转换成Java code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作 ITLSSPProc.dll
有本地方法,它在C语言下面的结构定义,但我必须用Java编写code。我不断搜索的最后三天,但无法找到一个解决方案。
1.typedef结构{
无符号__int64 FixedKey;对于固定主机密钥// 8字节数
无符号__int64 EncryptKey;对于可变密钥// 8字节数
} SSP_FULL_KEY; 2.typedef结构{
无符号__int64发生器;
无符号__int64模量;
无符号__int64 HostInter;
无符号__int64 HostRandom;
无符号__int64 SlaveInterKey;
无符号__int64 SlaveRandom;
无符号__int64 KeyHost;
无符号__int64 KeySlave;
} SSP_KEYS 3.typedef结构{
SSP_FULL_KEY关键; //全键
无符号长波特率; //包的波特率
无符号长超时; //多久毫秒等待从站的应答
unsigned char型会将PortNumber; //主机的串行COM端口号
unsigned char型SSPAddress; //从站的SSP地址
unsigned char型RetryLevel; //多少次尝试,从不答复
unsigned char型EncryptionStatus; //这是一个加密的命令0 - 无,1 - 是的
unsigned char型CommandDataLength; //在命令字节数
unsigned char型CommandData [255]; //包含命令字节数组
unsigned char型ResponseStatus; //响应状态(PORT_STATUS枚举)
unsigned char型ResponseDataLength; //多少响应中的字节
unsigned char型ResponseData [255]; //响应数据的阵列
unsigned char型IgnoreError; //标志燮preSS错误框(0 - 显示,1燮preSS)
} SSP_COMMAND
下面是Java code我都试过了,但我不能够调用本地方法:
公共类SSP_FULL_KEY
{
长FixedKey;
长EncryptKey;
公共SSP_FULL_KEY(长固定,长ENCR)
{
FixedKey =修复;
EncryptKey = ENCR;
}
} 公共类SSP_COMMAND
{
//字符串会将PortNumber;
SSP_FULL_KEY关键;
长波特率; //包的波特率
长超时; //多久毫秒等待从站的应答
字符串会将PortNumber; //主机的串行COM端口号
串SSPAddress; //从站的SSP地址
串RetryLevel; //多少次尝试,从不答复
串EncryptionStatus; //这是一个加密的命令0 - 无,1 - 是的
串CommandDataLength; //在命令字节数
的String [] = CommandData新的String [255]; //包含命令字节数组
串ResponseStatus; //响应状态(PORT_STATUS枚举)
串ResponseDataLength; //多少响应中的字节
字符串ResponseData [] =新的String [255]; //响应数据的阵列
串IgnoreError; //标志燮preSS错误框(0 - 显示,1 - SUP preSS) 公共SSP_COMMAND(字符串COMPORT)
{
波特率= 9600;
超时= 500;
=会将PortNumber COMPORT;
RetryLevel =5;
IgnoreError =0;
EncryptionStatus =0;
ResponseStatus =0;
ResponseDataLength =0;
SSPAddress =0;
CommandDataLength =0;
关键=新SSP_FULL_KEY(012345670123,012345670123); }
}本地方法:OpenSSPComPort(SSPCOMMAND * CMD)
下面我传递的参数:
指向SSP_COMMAND结构
返回:
WORD 0失败,1表示成功
块引用>和得到错误不合适的链接错误
解决方案看看投放< href=\"http://www.tangiblesoftwaresolutions.com/Product_Details/CPlusPlus_to_Java_Converter_Details.html\"相对=nofollow> C到Java的转换器
I am working on
ITLSSPProc.dll
which has native methods, it has the following struct definition in C-language but I have to write code in Java. I have searched continuously for the last three days but can't find a solution.1.typedef struct{ unsigned __int64 FixedKey; // 8 byte number for fixed host key unsigned __int64 EncryptKey; // 8 Byte number for variable key }SSP_FULL_KEY; 2.typedef struct{ unsigned __int64 Generator; unsigned __int64 Modulus; unsigned __int64 HostInter; unsigned __int64 HostRandom; unsigned __int64 SlaveInterKey; unsigned __int64 SlaveRandom; unsigned __int64 KeyHost; unsigned __int64 KeySlave; }SSP_KEYS 3.typedef struct{ SSP_FULL_KEY Key; // the full key unsigned long BaudRate; // baud rate of the packet unsigned long Timeout; // how long in ms to wait for a reply from the slave unsigned char PortNumber; // the serial com port number of the host unsigned char SSPAddress; // the SSP address of the slave unsigned char RetryLevel; // how many retries to the slave for non-response unsigned char EncryptionStatus; // is this an encrypted command 0 – No, 1 - Yes unsigned char CommandDataLength; // Number of bytes in the command unsigned char CommandData[255]; // Array containing the command bytes unsigned char ResponseStatus; // Response Status (PORT_STATUS enum) unsigned char ResponseDataLength; // how many bytes in the response unsigned char ResponseData[255]; // an array of response data unsigned char IgnoreError; // flag to suppress error box (0 – display,1 suppress) }SSP_COMMAND
Here is the Java code I have tried, but I am not able to call the native methods:
public class SSP_FULL_KEY { long FixedKey; long EncryptKey; public SSP_FULL_KEY(long fix, long encr) { FixedKey = fix; EncryptKey = encr; } } public class SSP_COMMAND { //string PortNumber; SSP_FULL_KEY key; long BaudRate; // baud rate of the packet long Timeout; // how long in ms to wait for a reply from the slave String PortNumber; // the serial com port number of the host String SSPAddress; // the SSP address of the slave String RetryLevel; // how many retries to the slave for non-response String EncryptionStatus; // is this an encrypted command 0 - No, 1 - Yes String CommandDataLength; // Number of bytes in the command String[] CommandData = new String[255]; // Array containing the command bytes String ResponseStatus; // Response Status (PORT_STATUS enum) String ResponseDataLength; // how many bytes in the response String ResponseData[] = new String[255]; // an array of response data String IgnoreError; // flag to suppress error box (0 - display,1- suppress) public SSP_COMMAND(String comport) { BaudRate = 9600; Timeout = 500; PortNumber = comport; RetryLevel = "5"; IgnoreError = "0"; EncryptionStatus = "0"; ResponseStatus = "0"; ResponseDataLength = "0"; SSPAddress = "0"; CommandDataLength = "0"; key = new SSP_FULL_KEY(012345670123, 012345670123); } } native method:OpenSSPComPort(SSPCOMMAND * cmd)
Here I pass the parameters:
Pointer to SSP_COMMAND structure Returns: WORD 0 for fail, 1 for success
and getting error unsatisfied link error
解决方案Take a look on C to java converter
这篇关于如何用C语言结构定义转换成Java code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文