首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从c++ dll调用其参数为结构且结构的属性为字符串的函数

从c++ dll调用其参数为结构且结构的属性为字符串的函数
EN

Stack Overflow用户
提问于 2013-01-22 16:07:52
回答 1查看 357关注 0票数 1

我知道如何使用基本类型,如intchar*struct,但我不知道如何表示C++类型string,它是一个使用jna的类。我使用JavaString来表示C++string,但是会发生错误,所以我认为它们可能不相等。知道的人能帮我吗,谢谢!

公共类classer {

代码语言:javascript
复制
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);


 }

}

//在字符串sResult = CLibrary.INSTANCE.classifier_exec(d,0)处停止

EN

回答 1

Stack Overflow用户

发布于 2013-01-22 20:39:49

std::string不能在JNA中直接表示。您需要一个纯C接口,因此需要将std::string转换为const char*,以便在JNA和C++之间传输数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14454069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档