免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
JNA調(diào)用C語(yǔ)言動(dòng)態(tài)鏈接庫(kù)學(xué)習(xí)實(shí)踐總結(jié) 第2頁(yè)

2.JNA模擬普通傳值參數(shù)

C語(yǔ)言函數(shù):

int function1(int a, float b, long c)

JNA模擬:

int function1(int a, float b, long c)

3.JNA模擬C語(yǔ)言數(shù)組
 
C語(yǔ)言函數(shù):
 
void function1(char * data)
 
void function2(const unsigned char* data)
 
JNA模擬:

void function1(char[] data) 或者 void function1(byte[] data)
void function2(char[] data) 或者 void function2(byte[] data)

4.JNA模擬基本類(lèi)型指針
 
JNA的ByReference有很多子類(lèi),這些類(lèi)都在com.sun.jna.ptr包中:
 
IntByReference,LongByReference,F(xiàn)loatByReference,DoubleByReference,ShortByReference、ByteByReference、PointerByReference等等
 
從這些名字大家應(yīng)該可以看出來(lái)他們的作用。
 
下面直接上例子吧:
 
C語(yǔ)言函數(shù):
 
long function(int * a, long * b, float * c, double * d, short * e)
 
JNA模擬:

long function(IntByReference aRef, LongByReference bRef, FloatByReference cRef,  DoubleByReference dRef,  ShortByReference eRef)

如何構(gòu)建這些對(duì)象呢?

FloatByReference cRef = new FloatByReference();    //使用默認(rèn)初始值(具體多少我也不知道)
FloatByReference cRef = new FloatByReference(0);  //初始值為0

調(diào)用方法和普通參數(shù)一樣:
 
function(..., cRef, ...);
 
獲取結(jié)果值:

float fVal = cRef.getValue();

JNA都為我們做的很簡(jiǎn)單,不是嗎?
 
5. JNA模擬指針、指針的指針、模擬void *,void ** 等指針
 
C函數(shù):
 
void function(int * pInt, int ** ppInt, void * pVoid, void ** ppVoid)
 
JNA模擬:

void function(IntByReference pInt, PointerByReference ppInt, Pointer pVoid, PointerByReference ppVoid)
調(diào)用舉例:
IntByReference pInt = new IntByReference(0);
PointerByReference ppInt = new PointerByReference(Pointer.NULL); //指向指針的指針,初始化為NULL
Pointer pVoid = Pointer.NULL; //創(chuàng)建一個(gè)指向NULL的指針
PointerByReference ppVoid = new PointerByReference(Pointer.NULL);
調(diào)用:function(pInt, ppInt, pVoid, ppVoid);

(1)PointerByReference是指向指針的指針,遇到指針的指針都可以使用它來(lái)模擬,那么如何獲取到它指向的指針呢?
 
Pointer p = ppVoid.getValue(); //獲取指針
 
(2)如何獲取指針的指針呢?

Pointer p1 = ....;
PointerByReference pp1 = new PointerByReference(p1);
PointerByReference ppp1 = new PointerByReference(pp1.getPointer());

這些操作大家可以自己做實(shí)驗(yàn)嘗試,對(duì)于PointerByReference對(duì)象,getValue()是取值,而getPointer()是取這個(gè)指針的指針。
 
看著復(fù)雜,其實(shí)都很簡(jiǎn)單!JNA要比JNI好用多了。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
函數(shù)指針總結(jié)_
[原]C/C++:如何理解復(fù)雜的聲明 - C/C++ - raof01-Haste mak...
你想錯(cuò)了,并不是所有指針都是4字節(jié)。
C語(yǔ)言中的函數(shù)指針學(xué)習(xí)筆記
第一部分 基礎(chǔ)語(yǔ)言之六函數(shù)
JNA API Documentation
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服