How to map C++ char**, int* and Enum types in Java?
1 posts in topic
Flat View  Flat View

Posted By:   vani_hemmige
Posted On:   Tuesday, March 20, 2001 09:01 AM

I am writing a Java application which uses C++ code. I have a function that takes char**, int* and Enum types in C++.
How should I write the corresponding Java method? Can anybody please tell me?

Re: How to map C++ char**, int* and Enum types in Java?

Posted By:   Alexander_Krapf  
Posted On:   Wednesday, March 21, 2001 02:31 PM

Hi Vani,

it depends mostly on what the char** stands for. If it represents an array of character strings, your Java method should look like this:

( String[] arg1, IntHolder arg2, int arg3 )

In your native method you would have to extract the string bytes anf build a C-array of strings. The IntHolder assumes that you use this argument as an inout argument and that you have to read a result. IntHolder basically just wraps around a primitive int field. Enums map to ints or to enumeration classes. There are some articles available on how to represent enumeration types in Java, but that's is a whole different issue.

You might want to check out our JunC++ion product at http://www.codemesh.com. It would simplify the native method implementation drastically by allowing you to write code like this:

( ..., const String::array1D & arg1, IntHolder & arg2, jint arg3 )
char ** arr = new char* [ arg1.length ];
int inout = arg2.value;
myenum en = (myenum)arg3;


call_cpp( arr, &inout, en );

Much nicer than having to write all that JNI code...

Good luck,


About | Sitemap | Contact