用于自定义库的 JNA
我是 JNA 基础设施的新手,但我认为要点是我有一些库“someLib”,并且我创建了一个 java 接口来匹配它。那我就可以“只是”使用它吗?
但问题是我不确定我需要模拟什么,特别是我需要一些类的功能。
假设我的 C++ 库有一个“AdvancedString”对象 - 它在内部使用一些其他类。
这意味着它看起来像这样:
class B { ... };
class AdvancedString {
private:
B b;
public:
AdvancedString doSomething () { ... }
};
我需要能够在 Java 代码中说出 AdvancedString.doSomething () 并让它工作。这意味着我需要...为 AdvancedString 类创建一个接口?
public interface AdvancedStringInterface extends StdCallLibrary {
public AdvancedStringInterface doSomething ();
}
这看起来合理吗?或者我错过了什么。感谢您提供的任何见解!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JNA 将帮助您访问 C 函数和数据。一种选择是在 C API 中公开 C++ 功能。
如果您想访问许多 C++ 类,SWIG 更适合。它可以为您的 C++ 类创建 Java 包装器。它非常强大,但有一个学习曲线。
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.