jna java调用sdofiledll_java - 使用Java JNA调用DLL库 - 堆栈内存溢出

博主在尝试使用Java 1.8和JNA v3.0.9调用DLL库时,遇到了结构体定义和参数传递的问题。具体表现为在设置NET_DVR_XML_CONFIG_INPUT结构体的lpRequestUrl字段时遇到空指针异常,并且在调用NET_DVR_STDXMLConfig时收到“参数无效”的错误。博客中提供了结构体的Java实现以及当前的调用代码,寻求帮助解决这两个问题。
摘要由CSDN通过智能技术生成

我有一个带有DLL库的SDK。 我正在从Java 1.8和JNA v3.0.9调用库,但是在定义结构时遇到了麻烦

SDK文档指出:

调用NET_DVR_STDXMLConfig来传递请求URL:GET / ISAPI / AccessControl / UserInfo / capabilities?format = json,以使人员管理功能了解配置详细信息和注意事项。

NET_DVR_STDXMLConfig API调用定义为:

BOOL NET_DVR_STDXMLConfig(

LONG lUserID,

NET_DVR_XML_CONFIG_INPUT *lpInputParam,

NET_DVR_XML_CONFIG_OUTPUT *lpOutputParam

);

lpInputParam

[IN] Input parameters, refer to the structure NET_DVR_XML_CONFIG_INPUT for details.

lpOutputParam

[IN/OUT] Output parameters, refer to the structure NET_DVR_XML_CONFIG_OUTPUT for details.

NET_DVR_XML_CONFIG_INPUT结构的定义:

struct{

DWORD dwSize;

void *lpRequestUrl;

DWORD dwRequestUrlLen;

void *lpInBuffer;

DWORD dwInBufferSize;

DWORD dwRecvTimeOut;

BYTE byForceEncrpt;

BYTE byNumOfMultiPart;

BYTE byRes[30];

}

dwSize

Structure size.

lpRequestUrl

Request URL (command) for implement different functions, and it is in string format.

dwRequestUrlLen

Request URL size.

lpInBuffer

Buffer for storing input parameters (request messages), see the input content details structure in NET_DVR_MIME_UNIT.

dwInBufferSize

Input buffer size.

dwRecvTimeOut

Receiving timeout, unit: ms, 0-5000ms (default).

byForceEncrpt

Whether to enable force encryption (the messages will be encrypted by AES algorithm for transmission): 0-no, 1-yes.

byNumOfMultiPart

Number of message segments: 0-invalid; other values-number of message segments, which is transmitted by the parameter lpInBuffer in the structure NET_DVR_MIME_UNIT.

NET_DVR_MIME_UNIT结构的定义是

struct{

char szContentType[32];

char szName[MAX_FILE_PATH_LEN/*256*/];

char szFilename[MAX_FILE_PATH_LEN/*256*/];

DWORD dwContentLen;

char* pContent;

BYTE byRes[16];

}

szContentType

Content type (corresponds to Content-Type field in the message), e.g., text/json. text/xml, and so on. The content format must be supported by HTTP.

zName

Content name (corresponds to name field in the message), e.g., name="upload".

szFilename

Content file name (corresponds to filename field in the message), e.g., filename="C:\Users\test\Desktop\11.txt".

dwContentLen

Content size.

pContent

Data point.

到目前为止,这是我在Java中所做的事情:DLL调用和结构定义

//DLL native call

boolean NET_DVR_STDXMLConfig(int lUserID, Pointer lpInputParam, Pointer lpOutputParam);

public static class NET_DVR_XML_CONFIG_INPUT extends Structure

{

public int dwSize;

public Pointer lpRequestUrl;

public int dwRequestUrlLen;

public Pointer lpInBuffer;

public int dwInBufferSize;

public int dwRecvTimeOut;

public byte byForceEncrpt;

public byte byNumOfMultiPart;

public byte[] byRes = new byte[30];

@Override

protected List getFieldOrder() {

return Arrays.asList("dwSize", "lpRequestUrl", "dwRequestUrlLen", "lpInBuffer", "dwInBufferSize",

"dwRecvTimeOut","byForceEncrpt","byNumOfMultiPart", "byRes");

}

}

public static class NET_DVR_XML_CONFIG_OUTPUT extends Structure {

public int dwSize;

public Pointer lpOutBuffer;

public int dwOutBufferSize;

public int dwReturnedXMLSize;

public Pointer lpStatusBuffer;

public int dwStatusSize;

public byte[] byRes = new byte[32];

@Override

protected List getFieldOrder() {

return Arrays.asList("dwSize", "lpOutBuffer",

"dwOutBufferSize", "dwReturnedXMLSize", "lpStatusBuffer",

"dwStatusSize", "byRes");

}

}

public static class NET_DVR_MIME_UNIT extends Structure{

public byte[] szContentType = new byte[32];

public byte[] szName = new byte[MAX_FILE_PATH_LEN];

public byte[] szFilename = new byte[MAX_FILE_PATH_LEN];

public int dwContentLen;

public String pContent;

public byte[] byRes = new byte[16];

@Override

protected List getFieldOrder() {

return Arrays.asList("szContentType", "szName", "szFilename", "dwContentLen", "pContent","byRes");

}

}

这是我的库调用

NET_DVR_XML_CONFIG_INPUT struInput = new NET_DVR_XML_CONFIG_INPUT();

NET_DVR_XML_CONFIG_OUTPUT struOuput = new NET_DVR_XML_CONFIG_OUTPUT();

String strInput = new String("GET /ISAPI/AccessControl/UserInfo/capabilities?format=json\r\n\"");

byte[] byInput = strInput.getBytes();

System.arraycopy(byInput, 0, struInput.lpRequestUrl, 0, byInput.length); // Nullpointer exception

struInput.dwRequestUrlLen = byInput.length;

NET_DVR_MIME_UNIT mimeUnit = new NET_DVR_MIME_UNIT();

//mimeUnit.pContent = new Memory(MAX_XML_CONFIG_LEN); // Dont know what to put in here

struInput.lpInBuffer = mimeUnit.getPointer();

struOuput.dwOutBufferSize = MAX_XML_CONFIG_LEN;

struOuput.dwStatusSize = struOuput.dwOutBufferSize;

struInput.write();

struOuput.write();

NET_DVR_STDXMLConfig(userID,struInput.getPointer(), struOuput.getPointer()); // Getting a generic "parameters not valid" error msg

我不确定自己的结构。 设置requestURL时,我获取了一个空指针。我的调用还返回了一个通用的“参数无效”错误消息。

任何帮助,不胜感激。

提前致谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值