JNA 调用dll 老是Invalid memory access,哭了

weixin_45703877 2019-10-02 06:53:40

public interface KfbLibrary extends Library {
// File libPath = new File("lib/ImageOperationLib.dll"); // windows
File libPath = new File("C:/soft/opt/ImageOperationLib.dll"); // linux
KfbLibrary INSTANCE = (KfbLibrary) Native.loadLibrary(libPath.getAbsolutePath(), KfbLibrary.class);

// File identification structure
class ImageInfoStruct extends Structure {
public int DataFilePTR;

@Override
protected List<String> getFieldOrder() {
return Arrays.asList("DataFilePTR");
}

public static class ByReference extends ImageInfoStruct implements Structure.ByReference {}
public static class ByValue extends ImageInfoStruct implements Structure.ByValue {}
}

int InitImageFileFunc(ImageInfoStruct.ByReference sImageInfo, String Path);

int UnInitImageFileFunc(ImageInfoStruct.ByReference sImageInfo);

Pointer GetImageStreamFunc(ImageInfoStruct.ByReference sImageInfo, float fScale, int nImagePosX, int nImagePosY, IntByReference nDataLength, PointerByReference ImageStream);

int GetHeaderInfoFunc(ImageInfoStruct.ByValue sImageInfo, IntByReference khiImageHeight, IntByReference khiImageWidth, IntByReference khiScanScale, FloatByReference khiSpendTime, DoubleByReference khiScanTime, FloatByReference khiImageCapRes, IntByReference khiImageBlockSize);
int GetImageDataRoiFunc(ImageInfoStruct.ByReference sImageInfo, float fScale, int sp_x, int sp_y, int nWidth, int nHeight, PointerByReference pBuffer, IntByReference DataLength, boolean flag);

int GetThumnailImageFunc(ImageInfoStruct.ByReference sImageInfo, PointerByReference ImageData, IntByReference nDataLength, IntByReference nThumbWidth, IntByReference nThumbHeight);
int GetThumnailImagePathFunc(String szFilePath, PointerByReference ImageData, IntByReference nDataLength, IntByReference nThumbWidth, IntByReference nThumbHeight);

int GetPriviewInfoFunc(ImageInfoStruct.ByReference sImageInfo, PointerByReference ImageData, IntByReference nDataLength, IntByReference nPriviewWidth, IntByReference nPriviewHeight);
int GetPriviewInfoPathFunc(String szFilePath, PointerByReference ImageData, IntByReference nDataLength, IntByReference nPriviewWidth, IntByReference nPriviewHeight);

int GetLableInfoFunc(ImageInfoStruct.ByReference sImageInfo, PointerByReference ImageData, IntByReference nDataLength, IntByReference nLabelWidth, IntByReference nLabelHeight);
int GetLableInfoPathFunc(String szFilePath, PointerByReference ImageData, IntByReference nDataLength, IntByReference nLabelWidth, IntByReference nLabelHeight);

...全文
1182 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shao_keke 2019-10-02
  • 打赏
  • 举报
回复
100R,几天都没搞定
shao_keke 2019-10-02
  • 打赏
  • 举报
回复
代码在上面的github,只求成功调用dll 里面的GetHeaderInfoFunc 一个函数,qq499646194 50r奖励
shao_keke 2019-10-02
  • 打赏
  • 举报
回复
https://github.com/shaokeke/kfbslide.git 另加50r
weixin_45703877 2019-10-02
  • 打赏
  • 举报
回复
weixin_45703877 2019-10-02
  • 打赏
  • 举报
回复
关键代码

private ImageInfoStruct.ByReference sImageInfo = new ImageInfoStruct.ByReference();
private ImageInfoStruct.ByValue sValue = new ImageInfoStruct.ByValue();

public void getHeaderInfo() {
		IntByReference khiImageHeight = new IntByReference(); 
		IntByReference khiImageWidth = new IntByReference();
		IntByReference khiScanScale = new IntByReference();
		FloatByReference khiSpendTime = new FloatByReference();
		DoubleByReference khiScanTime = new DoubleByReference();
		FloatByReference khiImageCapRes = new FloatByReference();
		IntByReference khiImageBlockSize = new IntByReference();
		int status = KfbLibrary.INSTANCE.GetHeaderInfoFunc(this.sValue, khiImageHeight, khiImageWidth, khiScanScale,
				khiSpendTime, khiScanTime, khiImageCapRes, khiImageBlockSize);
		if (status != 1) {
			System.err.println("failed to get header info");
			return;
		}
		
		this.width = khiImageWidth.getValue();
		this.height = khiImageHeight.getValue();
		this.capRes = khiImageCapRes.getValue();
/
	}
weixin_45703877 2019-10-02
  • 打赏
  • 举报
回复

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧