2016-11-03 150 views
1

我的工作JNA我的申请,我感到困惑的在Java中使用typedef结构指针。 请检查我的代码并指导我。 预先感谢您!typedef结构指针到JNA

下面是我的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; 
} 

现在我的问题是:这是什么在C++代码的意思*PHWDeviceInfo和哪能在我的java代码中使用这个指针?

+0

你可能想[阅读关于指针/引用(http://softwareengineering.stackexchange.com/a/141838)。 –

+0

你不明白什么?这是一个指针。在这里看到: http://stackoverflow.com/questions/1543713/c-typedef-of-pointer-to-structure –

+0

你不能真正用在Java代码中的指针。你能用它做什么? –

回答

0

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

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

JNA documents this clearly如通过@ areeba-伊尔凡-ULLAH汗指出。