freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

javajni調(diào)用的完全手冊-資料下載頁

2024-11-03 15:10本頁面

【導(dǎo)讀】JNI的簡單教程網(wǎng)上很多,看看就能夠明白,照著操作也基本能夠做下來。但是因?yàn)榇蠖嗟慕?。程寫的都不夠詳?xì),在照著操作時候可能會遇到幾個小問題,故開篇時在這里簡單總結(jié)一下。

  

【正文】 接上例子。我們先看一下 文件的內(nèi)容: /* DO NOT EDIT THIS FILE it is machine generated */ include /* Header for class testdll */ ifndef _Included_testdll define _Included_testdll ifdef __cplusplus extern C { endif /* * Class: testdll * Method: get * Signature: ()I */ JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass)。 /* * Class: testdll * Method: set * Signature: (I)V */ JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint)。 ifdef __cplusplus } endif endif 在具體實(shí)現(xiàn)的時候,我們只關(guān)心兩個函數(shù)原型 JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass)。 和 JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint)。 這里 JNIEXPORT 和 JNICALL 都是 JNI 的關(guān)鍵字,表示此函數(shù)是要被 JNI 調(diào)用的。而 jint 是以JNI 為中介使 JAVA的 int 類型與本地的 int 溝通的一種類型,我們可以視而不見,就當(dāng)做 int 使用。函數(shù)的名 稱是 JAVA_再加上 java 程序的 package 路徑再加函數(shù)名組成的。參數(shù)中,我們也只需要關(guān)心在 JAVA程序中存在的參數(shù),至于 JNIEnv*和 jclass 我們一般沒有必要去碰它。 好,下面我們用 文件具體實(shí)現(xiàn)這兩個函數(shù): include int i = 0。 JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass) { return i。 } JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint j) { i = j。 } 編譯連接成庫文件,本例是在 WINDOWS下做的,生成的是 DLL文件。并且名稱要與 JAVA中需要Java:JNI 調(diào)用資料整理 WSY 2020115 更新 調(diào)用的一致,這里就是 。把 的目錄下, java testdll運(yùn)行它,就可以觀察到結(jié)果了。 我的項目比較復(fù)雜,需要調(diào)用動態(tài)鏈接庫,這樣在 JNI 傳送參數(shù)到 C 程序時,需要對參數(shù)進(jìn)行處理轉(zhuǎn)換。才可以被 C 程序識別。 大體程序如下: public class SendSMS { static { (())。 (sms)。 } public native static int SmsInit()。 public native static int SmsSend(byte[] mobileNo, byte[] smContent)。 } 在這里要注意的是, path 里一定要 包含類庫的路徑,否則在程序運(yùn)行時會拋出異常: : no sms in at (:1491) at (:788) at (:834) at .(:14) at (:18) Exception in thread main 指引的路徑應(yīng)該到 .dll文件的上一級,如果指到 .dll,則會報: : C:\: Can39。t find dependent libraries at $(Native Method) at (:1560) at (:1485) at (:788) at (:834) at (:18) Exception in thread main 通過編譯,生成 頭文件。(建議使用 Jbuilder 進(jìn)行編譯,操作比較簡單!)這個頭文件就是 Java 和 C 之間的紐帶。要特別注意的是方法中傳遞的參數(shù)jbyteArray,這在接下來的過程中會重點(diǎn)介紹。 /* DO NOT EDIT THIS FILE it is machine generated */ include /* Header for class _mobilesoft_sms_mobilesoftinfo_SendSMS */ ifndef _Included__mobilesoft_sms_mobilesoftinfo_SendSMS define _Included__mobilesoft_sms_mobilesoftinfo_SendSMS ifdef __cplusplus extern C { endif /* * Class: _mobilesoft_sms_mobilesoftinfo_SendSMS * Method: SmsInit Java:JNI 調(diào)用資料整理 WSY 2020115 更新 * Signature: ()I */ JNIEXPORT jint JNICALL Java__mobilesoft_sms_mobilesoftinfo_SendSMS_SmsInit (JNIEnv *, jclass)。 /* * Class: _mobilesoft_sms_mobilesoftinfo_SendSMS * Method: SmsSend * Signature: ([B[B)I */ JNIEXPORT jint JNICALL Java__mobilesoft_sms_mobilesoftinfo_SendSMS_SmsSend (JNIEnv *, jclass, jbyteArray, jbyteArray)。 ifdef __cplusplus } endif endif 對于我要調(diào)用的 C程序的動態(tài)鏈接庫, C 程序也要提供一個頭文件, 。這個文件將要調(diào)用的方法羅列了出來。 /* * SMS API * Author: yippit * Date: */ ifndef MCS_SMS_H define MCS_SMS_H define DLLEXPORT __declspec(dllexport) /*sms storage*/ define SMS_SIM 0 define SMS_MT 1 /*sms states*/ define SMS_UNREAD 0 define SMS_READ 1 /*sms type*/ define SMS_NOPARSE 1 define SMS_NORMAL 0 define SMS_FLASH 1 define SMS_MMSNOTI 2 typedef struct tagSmsEntry { int index。 /*index, start from 1*/ int status。 /*read, unread*/ int type。 /*1can39。t parser 0normal, 1flash, 2mms*/ int storage。 /*SMS_SIM, SMS_MT*/ char date[24]。 char number[32]。 char text[144]。 } SmsEntry。 Java:JNI 調(diào)用資料整理 WSY 2020115 更新 DLLEXPORT int SmsInit(void)。 DLLEXPORT int SmsSend(char *phonenum, char *content)。 DLLEXPORT int SmsSetSCA(char *sca)。 DLLEXPORT int SmsGetSCA(char *sca)。 DLLEXPORT int SmsSetInd(int ind)。 DLLEXPORT int SmsGetInd(void)。 DLLEXPORT int SmsGetInfo(int storage, int *max, int *used)。 DLLEXPORT int SmsSaveFlash(int flag)。 DLLEXPORT int SmsRead(SmsEntry *entry, int storage, int index)。 DLLEXPORT int SmsDelete(int storage, int index)。 DLLEXPORT int SmsModifyStatus(int storage, int index)。 /*unread read*/ endif 在有了這兩個頭文件之后,就可以進(jìn)行 C 程序的編寫了。也就是實(shí)現(xiàn)對 JNI 調(diào)用的兩個方法。在網(wǎng)上的資料中,由于調(diào)用的方法實(shí)現(xiàn)的都比較簡單,(大多是打印字符串等)所以避開了 JNI 中最麻煩的部分,也是最關(guān)鍵的部分,參數(shù)的傳遞。由于 Java 和 C的編碼是不同的,所以傳遞的參數(shù)是要進(jìn)行再處理,否則 C 程序是會對參數(shù)在編譯過程中提出警告,例如; warning C4024: 39。SmsSend39。 : different types for formal and actual parameter 2 等。 的程序如下: include include JNIEXPORT jint JNICALL Java__mobilesoft_sms_mobilesoftinfo_SendSMS_SmsInit(JNIEnv * env, jclass jobject) { return SmsInit()。 } JNIEXPORT jint JNICALL Java__mobilesoft_sms_mobilesoftinfo_SendSMS_SmsSend(JNIEnv * env, jclass jobject, jbyteArray mobileno, jbyteArray smscontent) { char * pSmscontent 。 //jsize theArrayLengthJ = (*env)GetArrayLength(env,mobileno)。 jbyte * arrayBody = (*env)GetByteArrayElements(env,mobileno,0)。 char * pMobileNo = (char *)arrayBody。 printf([%s]\n , pMobileNo)。 //jsize size = (*env)GetArrayLength(env,smscontent)。 arrayBody = (*env)GetByteArrayElements(env,smscontent,0)。 pSmscontent = (char *)arrayBody。 printf(%s\n, pSmscontent)。 return SmsSend(pMobileNo,pSmscontent)。 } 對于 C 或 C++,在程序上是會有稍微的不同,這可以由讀者對其進(jìn)行適當(dāng)?shù)男薷?。這里要注意的是GetArrayLength, GetByteArrayElements 等這些 JNI 中已經(jīng)包含的方法,這些方法是專門對轉(zhuǎn)換參數(shù)類型而提供的。具體的方法有很多,在下一篇中會做專門的介紹。 在完成了上述的文件后,可以對 進(jìn)行編譯,生成 .dll文件(建議在 release 中編譯,這樣動 態(tài)鏈接庫的容積會比較?。。? 完成 .dll文件的編譯后,就可以在 Java 中調(diào)用 C 程序中的方法了。例如文件 Java:JNI 調(diào)用資料整理 WSY 2020115 更新 public class test { public test() { } public static void main(String[] args) { byte[] mobileno = { 0x31, 0x33, 0x36, 0x36, 0x31, 0x36, 0x33, 0x30, 0x36, 0x36, 0x37, 0x00}。 String smscontentemp = 早上好 。 byte[] temp = {0}。 try { byte[] smscontentdb = (gbk)。 byte[] smscontent = new byte[ + ]。 (smscontentdb, 0, smsconte
點(diǎn)擊復(fù)制文檔內(nèi)容
畢業(yè)設(shè)計相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1