0

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.

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

SWIG doesn't recurse into #include definitions by default, and you normally don't want it to. See my answer for letting SWIG know about Windows types such as BOOL.
0

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.

Comments

0

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.

4 Comments

I am unable to use 0,1 from java side in place of SWIGTYPE_p_int32_t. and What about case where function is returning SWIGTYPE_p_int32_t and void* kind of pointers ?
But you can patch this type to a simple int. If your functions return void* you cannot do much with it in Java. However, you can store it in int and pass it back to native code where it accepts void*.
I can patch it for one function sir but I am trying to create wrapper of third party library which include these type at many places in the code not just single function.
You can #define SWIGTYPE_p_int32_t int
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.