rybit
rybit

Reputation: 756

JNA for a custom library

I am new to the JNA infrastructure but I think that the gist is that I have some library "someLib" and I create a java interface to match it. Then I can 'just' use it right?

But the problem is that I am unsure of what I need to mock out, specifically there are some classes that I need the features of.

Lets say that my C++ lib has a 'AdvancedString' object - that internally uses some other classes.

Meaning it looks like this:

class B { ... };

class AdvancedString { 
  private: 
    B b;

  public:
    AdvancedString doSomething () { ... }

};

And I need to be able in the Java code to say AdvancedString.doSomething () and have it work. This means that I need to...create an interface for the AdvancedString class?

public interface AdvancedStringInterface extends StdCallLibrary {
  public AdvancedStringInterface doSomething ();
}

Does that seem reasonable? Or am I missing something. Thanks for any insight you can give!

Upvotes: 0

Views: 513

Answers (1)

Andy Thomas
Andy Thomas

Reputation: 86411

JNA will help you access C functions and data. One option is to expose your C++ functionality in a C API.

If you want to access many C++ classes, SWIG is a better fit. It can create Java wrappers for your C++ classes. It is very powerful, but there is a learning curve.

Upvotes: 1

Related Questions