Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why fail to call third party funciton in DLL via JNI but workable in C++?

843829Apr 7 2005
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 !
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2005
Added on Apr 7 2005
0 comments
152 views