【问题标题】:typedef struct pointer into JNAtypedef 结构指针到 JNA
【发布时间】:2016-11-03 09:37:57
【问题描述】:

我正在为我的应用程序开发 JNA,我对在 java 中使用 typedef struct pointer 感到困惑。 请检查我的代码并指导我。 提前谢谢!

下面是我的 c++ 代码

typedef struct tagHWDeviceInfo
{
USHORT          VendorID;      // vendor id
USHORT          ProductID;     // product id
DWORD           nXExt;         // firmware width
DWORD           nYExt;         // firmware height
DWORD           preesure;      // pressure level
DWORD           penState;      // pen state
}HWDeviceInfo, *PHWDeviceInfo;

和java代码

public class HWDeviceInfo extends Structure{
    short VendorID;
    short ProductID;
    int   nXExt;        // firmware width
    int   nYExt;        // firmware height
    int   preesure;     // pressure level
    int   penState;
}

现在我的问题是:*PHWDeviceInfo 在 c++ 代码中是什么意思,如何在我的 java 代码中使用这个指针?

【问题讨论】:

  • 你到底有什么不明白的?这是一个指针。见这里:stackoverflow.com/questions/1543713/…
  • 而且您不能真正在 Java 代码中使用指针。你能用它做什么?
  • 您以前曾与 JNA 合作过吗?我们可以在 jna.jar 中使用 Pointer 类。我知道我们不能在 java 中使用指针,但请理解我的问题。
  • @СӏаџԁеМаятіи 看这篇文章JNA Overview

标签: java c++ pointers struct jna


【解决方案1】:

JNA 在函数调用中自动将Structure 的实例转换为struct *,并在结构字段定义中自动转换为structStructure.getPointer() 为您提供 JNA 将使用的指针。

您可以通过使用Structure.ByReferenceStructure.ByValue 接口标记您的类和/或参数类型来修改此默认行为。

@areeba-irfan-ullah-khan 指出的 JNA documents this clearly

【讨论】:

    猜你喜欢
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多