Amparo
Amparo

Reputation: 824

Non standard types with JNA

I would like to call DLL functions using JNA but the library uses non standard C types.

I can see in wikipedia what it is the mapping between C and Java standard types but, what is it happening with custom types?

Upvotes: 0

Views: 163

Answers (2)

Luis Colorado
Luis Colorado

Reputation: 12698

The mapping of Java classes to architecture dependant types is preciselly the purpose of the JNI library. Think of it as an interface library only, with maps the classes and types passed to a JNI call into the types and classes of a C or C++ program, so expect non-standard issues on doing that.

Think that interfacing to linux/gcc should be a bit different to interfacing to Windows/VisualStudio, for example.

Anyway, the guys at Oracle(former Sun Microsystems) have done a good work, trying to hide the most of the architecture dependant code and trying to be as standard as possible.

My gratitude to them from here :)

Upvotes: 0

visibleman
visibleman

Reputation: 3315

You can write a wrapper in C/C++. This wrapper includes the header that defines the custom types. The new wrapper function should accept only standard types as input and "translate" to custom types before calling the library function, in the same way the returned value can also be translated. Now call your wrapper function from Java via JNA.

Otherwise you could always look into SWIG and JNI.

Upvotes: 0

Related Questions