要用java 调用别人提供的一个dll动态链接库BaraingApplyV2.dll中的一个函数int Init(const char * Data1,char * retMsg,char* Data2),我在网上查了好多关于jni方面的资料,发现其中最重要的就是要用c++写一个中间DLL,在这个中间dll中再去调用BaraingApplyV2.dll中的函数
我没学过c++,所以想请教大家:c++中怎么去调用BaraingApplyV2.dll中的函数int Init()JNIEXPORT jint JNICALL Java_HelloDll_f_Init
(JNIEnv * env, jclass, jstring data1, jstring retMsg, jstring data2){}
我没学过c++,所以想请教大家:c++中怎么去调用BaraingApplyV2.dll中的函数int Init()JNIEXPORT jint JNICALL Java_HelloDll_f_Init
(JNIEnv * env, jclass, jstring data1, jstring retMsg, jstring data2){}
然后在FreeLibrary(xxx);具体楼主可以多百度,
java调用dll很简单的,你现在的障碍应该是如何调研被封装了的BaraingApplyV2.dll具体是不是使用HINSTANCE 楼主还多问问,我仅用过一次了解不深入
JNIEXPORT jint JNICALL Java_HelloDll_f_1UserBargaingInit
(JNIEnv * env, jclass, jstring data1, jstring retMsg, jstring data2){
typedef int (WINAPI *dll_interface_type)(LPCTSTR,LPCTSTR,LPCTSTR);
HINSTANCE module = ::LoadLibrary("BaraingApply.DLL"); dll_interface_type f = (dll_interface_type)::GetProcAddress(module, "Init");
return f("$$$$","$$0~~$$",""); //call
::FreeLibrary(module);
}
但是这样就报这个错:
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x02d688ac, pid=2536, tid=3316
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_07-b03 mixed mode, sharing)
# Problematic frame:
# C [BargaingApply.DLL+0x988ac]
#
# An error report file with more information is saved as hs_err_pid2536.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
真急
如:int Init(const char * Data1,char * retMsg,char* Data2)
类里:public native int init(const String Data1,String retMsg,String Data2);