jna 返回 Structure 的使用问题

会上树的狼 2014-12-08 03:07:15
我在使用jna返回的是Structure的时候出了奇怪现象,不出错误信息,好像是崩了。
package Gundll;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

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

public interface detect extends Library {
String path = detect.class.getResource("").getFile();
File file = new File(path);
String filePath = file.getPath();
detect INSTANCE = (detect) Native.loadLibrary(filePath + File.separator + "detect", detect.class);

public static class PredictResult extends Structure implements Structure.ByReference {
public static class ByReference extends PredictResult implements Structure.ByReference {
}

public static class ByValue extends PredictResult implements Structure.ByValue {
}

public int centerX;
public int centerY;
public int radius;

@Override
protected List getFieldOrder() {
List a = new ArrayList();
a.add("centerX");
a.add("centerY");
a.add("radius");
return a;
}
}

public static class DtOut extends Structure {
public static class ByReference extends DtOut implements Structure.ByReference {
}

public static class ByValue extends DtOut implements Structure.ByValue {
}

public byte[] imageName = new byte[1000];
int width;//4byte
int height;//4byte
int objectSum;//4byte
public PredictResult.ByValue[] PredictResult = new PredictResult.ByValue[200];

@Override
protected List getFieldOrder() {
List a = new ArrayList();
a.add(imageName);
a.add(width);
a.add(height);
a.add(objectSum);
a.add("PredictResult");
return a;
}
}


// 初始化
void GunPredictInit();

// 调用算法
DtOut GunPredict(String imageFileName);
}


下面是调用类
package Gundll;

import Gundll.detect.DtOut;

public class Test {
// String path = detect.class.getResource("").getFile();
// File file = new File(path);
// String filePath = file.getPath();

public static void main(String[] args) {
try {
// 初始化
detect.INSTANCE.GunPredictInit();
detect detect1 = detect.INSTANCE;
DtOut dtOut = detect1.GunPredict("c:/1.jpg");
System.out.println("=================================");
System.out.println("imageName:" + dtOut.imageName);
// System.out.println("width:" + dtOut.width);
// System.out.println("height:" + dtOut.height);
// System.out.println("objectSum:" + dtOut.objectSum);
// System.out.println("PredictResult:" + dtOut.PredictResult);
} catch (Exception e) {
e.printStackTrace();
}
}
}

运行后的结果如下图:
...全文
146 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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