How to use unsigned int to be able to use a function for JNA (Java Native Interface)?

天涯浪子 提交于 2019-12-11 09:59:42

问题


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?

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);

回答1:


Use JNA's IntByReference.



来源:https://stackoverflow.com/questions/5627307/how-to-use-unsigned-int-to-be-able-to-use-a-function-for-jna-java-native-interf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!