I know how to use the basic type such as int
, char*
, struct
, but I don't know what represents the C++
type string
which is a class using jna
. I used the String
of Java
to represent the string
of C++
, but errors happens, so I think maybe they are not equal. Can anybody who know help me, thanks!
public class classer {
public static class sDoc extends Structure{
public static class ByReference extends sDoc implements Structure.ByReference { }
public String sTitle;
public String sContent;
public String sAuthor;
public String sBoard;
public String sDatatype;
}
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "LJClassifier" : "c"),
CLibrary.class);
boolean classifier_init(String conf, String sLicenseCode);
String classifier_exec(sDoc.ByReference d, int iType);
String classifier_detail(String classname);
void classifier_exit();
}
public static void main(String[] args) {
if(!CLibrary.INSTANCE.classifier_init("rulelist.xml",null)) {
System.out.print("classifier_init failed!\n");
return ;
}
sDoc.ByReference d= new sDoc.ByReference();
d.sTitle = "天翼定制手机天语E600";
d.sContent = "全球旅行必备:天翼定制手机天语E600 新浪 2011-9-26 15:53手机——这项人们使用率最高的电子产品,其更新换代速度更是快得无法想象。那么对于我们消费者而言,应当如何选择呢? 显然,频繁的换机是非常不划算的,更会增加生活开支,平白增添生活负担。因此,我们在购机之初就应当选择一款满足自身需求的手机。...";
d.sAuthor = "飞香";
d.sBoard = "69";
d.sDatatype = "论坛";
System.out.print("-----------------------------------------");
**String sResult = CLibrary.INSTANCE.classifier_exec(d,0);**
//System.out.print(sResult);
}
}
//it stoped at String sResult = CLibrary.INSTANCE.classifier_exec(d,0)
std::string
is not directly representable in JNA. You need a pure C interface, so you'll need to convert std::string
to const char*
in order to transfer data between JNA and C++.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.