如何使用unsigned int能够使用JNA(Java Native Interface)的函数? [英] How to use unsigned int to be able to use a function for JNA (Java Native Interface)?

查看:374
本文介绍了如何使用unsigned int能够使用JNA(Java Native Interface)的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JNA在我的Java应用程序中使用C ++库。我在Java中使用接口来使用这些函数。该函数在C ++中使用三个参数:unsigned int,const char *和long *。 JNA在Java中实现了Strings(根据他们的文档)传入char *。同样,它使用long []传入long *。但是,我对于我应该为unsigned int传递的类型感到困惑。传入的char *表示文件的名称,无论我使用哪种类型的第一个参数,它似乎都不能识别文件。此外,最后一个long类型实际上在执行函数后返回一个值。如果我对第一个参数使用short或int类型,则此数字似乎是正确的,但是,如果我对第一个参数使用long类型,则它是不正确的。任何人都可以帮忙吗?

I'm using JNA in order to use a C++ library in my Java application. I am using an interface in Java to use these functions. The function uses three arguments in C++: an unsigned int, a const char*, and a long*. JNA implements Strings (according to their documents) in Java to pass in a char*. Likewise, it uses a long[] to pass in a long*. I'm confused, however, about the type that I should pass in for the unsigned int. The char* that is passed in represents the name of the file, and no matter what type I use for the first argument, it does not seem to recognize the file. Furthermore, the last, long type actually returns a value after the function is executed. If I use the short or int type for the first argument, this number seems to be correct, however, if I use the long type for the first argument, it is incorrect. Can anyone help?

举一个例子,这里是C ++中的实际原型所遵循的目前我作为Java中的接口原型:

For an example, here's what the actual prototype in C++ is followed by what I currently have as the interface prototype in Java:

int JrConnect(unsigned int id, const char* config_file, long* handle);

public int JrConnect(int[] id, String[] config_file, long[] handle);


推荐答案

使用JNA的 IntByReference

这篇关于如何使用unsigned int能够使用JNA(Java Native Interface)的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆