用于自定义库的 JNA

发布于 2024-10-08 04:50:07 字数 617 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖风昔人 2024-10-15 04:50:07

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文