日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

jni c java互相调用_通过JNI实现Java和C++的相互调用

發布時間:2023/12/10 c/c++ 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jni c java互相调用_通过JNI实现Java和C++的相互调用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

評論

#?re: 通過JNI實現Java和C++的相互調用

2008-07-29 14:14

Always BaNg.

不錯,把字符轉換也一并講了吧,比如UTF-8的處理,USC-2與MBCS轉換等。??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-07-29 14:17

role0523

你是指Java和C++之間的字符轉換?

目前還沒有研究過字符轉換。

回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-07-31 23:58

coldsummer

如果是現成的dll呢?比如某硬件提供的開發dll開發包,我如何調用???回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-08-01 00:05

role0523

@coldsummer

由于JAVA調用C++需要一定的格式,比如在JAVA中聲明native方法,然后通過javah生成一個頭文件,然后寫cpp文件,但必須實現這個頭文件中聲明的JNIEXPORT方法。這些方法是Java調用C++的入口。所以在這些方法內部填寫對你的DLL的調用即可。??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-08-26 17:14

lfking

你的這個JAVA調用C++的例子,我試了一整天,沒試明白!~~

在最后編譯成DLL文件時老是報錯,不知道是怎么回事!~~~

錯誤代碼如下:請你幫分析一下!謝謝!~

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2144: syntax error : 'void' should be preceded by ';'

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2146: syntax error : missing ';' before identifier 'Java_org_druze_test_TestNative_sayHello'

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2182: 'JNICALL' : illegal use of type 'void'

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2065: 'JNIEnv' : undeclared identifier

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2065: 'env' : undeclared identifier

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2065: 'jobject' : undeclared identifier

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2146: syntax error : missing ')' before identifier 'obj'

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2078: too many initializers

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(5) : error C2059: syntax error : ')'

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(6) : error C2143: syntax error : missing ';' before '{'

c:\documents and settings\william\my documents\visual studio 2005\projects\nativecode\nativecode\source.cpp(6) : error C2447: '{' : missing function header (old-style formal list?)

Generating Code...

生成日志保存在“file://c:\Documents and Settings\william\My Documents\Visual Studio 2005\Projects\NativeCode\NativeCode\Debug\BuildLog.htm”

NativeCode - 13 個錯誤,0 個警告

========== 全部重新生成: 0 已成功, 1 已失敗, 0 已跳過 ==========

回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-08-26 17:38

role0523

你沒有指定jni.h,jni_md.h的include path,以及 jvm.dll的路徑,具體參考文章后半部分??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-08-27 10:24

lfking

你說要指定jni.h 和 jni_md.h的include path 這個我都做了,就是少做一個JVM.DLL的路徑,試過了,還是一樣的錯誤!~

我做的是JAVA 連接 C++ 需要做這個JVM.DLL的路徑嗎???回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-08-27 10:46

role0523

sorry, jvm.dll不用指定,因為我們這里不需要它。

這樣好了,你把org_druze_test_TestNative.h和jni.h復制到source.cpp相同的目錄下,將#include 修改為#include "jni.h" 試試看。

你的問題是jni.h的頭文件沒有在頭文件的搜索路徑當中。??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-08-27 12:01

lfking

我按照你上面寫的步聚建立一個WIN32的工程,建好以后,會自動建立一個stdafx.h的頭文件和stdafx.cpp文件!然后運行source.cpp的時候提示錯誤說必須要用stdafx.h這個頭文件,加上去以后就出現這些錯誤了!

唉!~把jni.h放到source.cpp同一個目錄下了,還是不行!~~

我留個QQ號給你吧,Q上聊!47145748!

你這BOLG上面不能發圖片!

回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-08-27 12:04

lfking

vc以前從來沒接觸過,只是聽說過!所以用起來有點愚純!~~抱歉!~~??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-08-27 15:12

role0523

你把stdafx.h的頭文件和stdafx.cpp刪除掉吧??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-08-28 10:31

lfking

無語了都.....

如果把stdafx.h和stdafx.cpp刪除的話,會提示錯誤,說沒有加載stdafx.h文件。

大哥,這個例子你試過沒啊??是否成功了?你那個版本的VC??我是用VC2005做的!??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-08-28 11:00

role0523

就如我文中所說,我用的VS2008,VC6,codeBlocks.我沒搞定,不會寫東西的。你的問題在于你對C++的編譯器不是很熟悉,這我幫不了你。

BTW:如果把stdafx.h和stdafx.cpp刪除的話,會提示錯誤,說沒有加載stdafx.h文件。

那是你的某個地方#include了這個文件,OK???回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2008-08-28 14:53

lfking

7.編譯,生成NativeCode.dll,并將其copy到環境變量PATH的路徑下。

10.注意NativeCode.dll必須放置在java命令能訪問的路徑中。

這個不是很了解。能不能在說的具體點!

我是把NativeCode.dll放在與TestNative.java文件同一個目錄下! ??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2008-08-28 14:58

role0523

NativeCode.dll是由java.exe->jvm.dll->NativeCode.dll這樣調用的。你把NativeCode.dll放到與java.exe同目錄下,OK?

回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2009-05-21 18:10

Necho

完全按照樓主的做法結果確報這個錯誤,請樓主幫我看下吧

First-chance exception at 0x00411a20 in NativeCode2.exe: 0xC0000005: Access violation reading location 0x00000000.

Unhandled exception at 0x00411a20 in NativeCode2.exe: 0xC0000005: Access violation reading location 0x00000000.??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2009-05-21 18:21

Necho

補充一下 應該就是不能findclass??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2009-05-21 18:24

Necho

如果可以的話 請加我MSN:necho_leco@yhotmail.com

或者QQ :55128128

想向你請教,謝謝~! ??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2009-05-22 10:19

Necho

測試成功了 感謝LZ提供這么詳細的說明 謝謝~~!!??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2009-09-04 14:43

阿飛

樓主,請問下:我在VC6。0控制臺下可以加載JAVA虛擬機了,為什么到了VC6.0的MFC下用同樣的方法加載不了(編譯不報錯,但是調試的時候通不過),盼回復,謝謝!??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用[未登錄]

2009-12-18 13:40

sunny

樓主:

請問我在編譯C++時,出現這個錯誤訊息:

error C2065: 'JNI_VERSION_1_6' : undeclared identifier

我使用的是JDK1.6??回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2009-12-18 23:39

nobody

@sunny 看看這個聲明在哪個頭文件里面,把它include進來

回復??更多評論

#?re: 通過JNI實現Java和C++的相互調用

2010-01-09 11:52

next

@lfking

朋友,這個連接的最下方是你要的答案

http://www.experts-exchange.com/Programming/Languages/CPP/Q_22048796.html

引用:

phongtran72:

Well, this generates error:

#include "jni.h"

#include "stdafx.h"

#include

#include

And this is solution:

#include "stdafx.h"

#include

#include

#include "jni.h"??回復??更多評論

總結

以上是生活随笔為你收集整理的jni c java互相调用_通过JNI实现Java和C++的相互调用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。