From: Timothy Wall <
twal...@java.net>
>short answer: you don't
>long answer: C++ classes aren't automatically mapped onto something more or less equivalent in Java,
>and can't be without a significant amount of work.
This type of question (mapping C++) often pops up on this list.
I accept both the short and long answers but I've not seen it explained why?
So I'm sort of looking for an 'even longer answer'.
Is it *only* the name mangling (which I presume varies from C++ compiler to compiler)
or is there something else? I mean at the end of the day every C++ class member function will
be a standard C function with a mangled name with the first argument being a pointer
to an instance of the class, right?
Trickier part is properly calling virtual functions as one would need to figure out how the
vtable works. But again I presume there is some sort of index to a vtable that the
C++ compiler creates and that is passed to some vtable lookup system and it should be
possible to call them using that mechanism?
The info for above could likely be harvested from the the C++ code with disassembly
tools or compiler linker/listings...
So above is what Timothy meant when he wrote "can't be without a significant amount of work"?!
I can see virtual base classes and pointer casting could get pretty interesting ...
and runtime type information too...begins to feel like a challenge!
Templates seem to add yet another complication as the functions are generated
only if the template is instantiated ... that would be pretty much impossible with JNA?
Why am I rambling about this? Cause it would seem to me that for some simple
cases it would/should be feasible to call C++ stuff from Java using JNA but it can
get awfully complicated pretty easily.
I don't see writing a C wrapper as an option as then one loses the very thing that
makes JNA attractive ie getting rid of the C tool chain. On might as well use JNI
then. Of course it is totally doable.
So the 'short answer' is mostly spot on I guess.
One more thing: an entry (lost the reference) in StackOverflow suggested that
jnaerator can generate JNA mappings for C++ classes, is that correct?
If so what are the limitations?
I have no immediate need for this, hence too lazy to try to find out, but if
someone wants to educate the followers of this list feel free to educate us...
cheers Kusti
And thanks for Timothy for JNA and the support!