سؤال

I have created swig interface file to create JNI for my C++ Files. but some of my C++ Files include functions which accept pointer as argument like (void*) , C++ BOOL and Swig converts it into type like SWIGTYPE_p_int32_t how to pass such kind of data type from java ?

for example one of the function's actual prototype is like below in C++

DLL_API void DLL_CALLCONV FreeImage_Initialise(BOOL load_local_plugins_only FI_DEFAULT(FALSE));

which is converted in Java file with swig

public static void FreeImage_Initialise(SWIGTYPE_p_int32_t load_local_plugins_only)

how to pass such value from java ?

I have many classes which include such kind of arguments in function. is there any way so that I can apply solution to bulk files for handle datatype as simple as possible.

I have read one way to do that is create helper function but I cannot go for it because i have many c++ classes and for each and every function creating helper function for returning pointer is not way to go.

Please suggest any other way if possible.

هل كانت مفيدة؟

المحلول

Solved myself. Swig was not be able to recognize all the typedef in header files and hence it was producing that kind of Types in wrapper. I need to redefine them in Interface file.

نصائح أخرى

About booleans, I would recommend using boolinstead of BOOL because JNI directly provides a type signature for it: Z (you can check signatures at: JNI Types and Data Structures)

About pointers, if are pointer to basic types, this is declared by adding [in front of corresponding signature, this is: int* --> [I. If it's a pointer to a own class, swig will create a fully qualified class.

Hope this helps.

This is because of the weird declaration of BOOL type.

In this particular case, you can pass an int there from Java side. Either 0 or 1 will do the right job.

Or you can change BOOL to bool in your native code by creating a small wrapper for this library.

SWIG doesn't know about windows types. Add %include <windows.i> to the interface definition.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top