JNA C語言與Java類型轉換(不定期更新)


首先是官方給出來的映射

 


 

以下是自己在配置過程中通過網上各種資料查找到的映射,(歡迎評論補充,我會一一補充進來)

C語言 Java
char * String (作為入口參數)
byte[]  (作為出口參數)
unsigned char * String  (作為入口參數)(不確定,沒具體使用過
Pointer (作為出口參數)
int * IntByReference
   
   

 

 

 

 

 

 

 


 

結構體

在Java中需要設計一個類並繼承Structure類

Demo:

 1 public class IDInfo extends Structure {
 2 
 3     public byte[] name       = new byte[32]; //姓名
 4     public byte[] sex        = new byte[4]; //性別
 5     public byte[] nation     = new byte[12]; //民族
 6     public byte[] birthday   = new byte[20]; //出生日期
 7 
 8     public static class ByValue extends IDInfo implements Structure.ByValue {
 9     }
10 
11     public static class ByReference extends IDInfo implements Structure.ByReference {
12     }
13 
14     @Override
15     protected List<String> getFieldOrder() {
16         // 順序必須與C語言機構體中的順序一致
17         List<String> fieldOrderList = new ArrayList<String>();
18         fieldOrderList.add("name"); //姓名
19         fieldOrderList.add("sex"); //性別
20         fieldOrderList.add("nation"); //民族
21         fieldOrderList.add("birthday"); //出生日期
22         
23         return fieldOrderList;
24     }
25 
26 }

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM