Hi,
I need someone help me here.
I like to call a function in third party A.dll which is from PowerBuilder App by Java.
So first I worte C++ code to call A.dll for the function to confirm: String feGetMM( String a);
I worte code like here in C++:
typedef char * (CALLBACK
PROC_ADDR) ( const char);
const char* NAME = "feGetMM";
PROC_ADDR procAddr;
const char* passin = "123";
char * result;
HINSTANCE hinstLib = LoadLibrary( A.dll ); //load 3rd party library
if(hinstLib!=NULL) {
//get the function address
procAddr = (PROC_ADDR) GetProcAddress(hinstLib,NAME);
if(procAddr!=NULL)
result = (procAddr)( passin ); //call the function
....
I got right result.<<<<<<<<<<<<<
Then second I worte the same as C++ in JNI code to generate B.dll
JNIEXPORT jint JNICALL Java_xxxxx_feGetMM
(JNIEnv *env, jclass cl, jstring jstr) {
typedef char* (CALLBACK
PROC_ADDR) ( const char);
const char* NAME = "feGetMM";
PROC_ADDR procAddr;
const char* result;
HINSTANCE hinstLib = LoadLibrary( A.dll ); //load 3rd party library
if(hinstLib!=NULL) {
//get the function address
procAddr = (PROC_ADDR) GetProcAddress(hinstLib,NAME);
const char* cstr = env->GetStringUTFChars(jstr,NULL);
if(procAddr!=NULL)
result = (procAddr)(cstr); //call the function
.....
fails return NULL<<<<<<<<
*the B.dll builded successfully, but fail to call for result. The java main() call is fine. The "result" is always NULL.
I worte the same as C++ code in JNI but why it fails in JNI code call by Java?
I will appreciate your help if you could reply it quickly.
Thanks !