2016-11-03 145 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汗指出。