JNI and Wrapper.dll - Failure in java.exe

Hello!

I have a problem with JNI and a Wrapper.dll:

I've created a Wrapper.dll to call a Native-Methods-DCOM-DLL from Java. The Java-Program itself works fine, also the functions in the wrapper.dll. However, if I run both, I get a crash of java.exe.

My Java-Program loads the DLL correct, finds the functions and performs all the operations, then it returns to java; but just before the end of the java-program, it crashes with a memory-failure in java.exe.

The wrapper.dll establishes a connection to a Server and to a database (on this server) and posts some new folders and files, which indeed causes no failures.

The relevant code is following:

JAVA:

class Director

{

//initiates connection, creates a directory and releases connection

publicnativestaticint InitConnection(String Server, String ProjectName, String Username, String Password);

static

{

System.loadLibrary("COMWrapper");

}

}

class TestDirectorTest

{

publicstaticvoid main(String[] args)

{

Director test =new Director();

test.InitConnection("http://...","demo_project","admin","");

//this method is executed, then everything crashes

//why at the end?

System.out.println("Program Finished");

}

}

DLL:

#import"Native_Methods.dll"

JNIEXPORT jint JNICALL Java_TestDirector_InitConnection

(JNIEnv* env, jobject this_obj, jstring jServer, jstring jDataBase, jstring jUserName, jstring jPassword)

{

//get Java-Strings

const char* Server=env->GetStringUTFChars(jServer,NULL);

const char* DataBase=env->GetStringUTFChars(jDataBase,NULL);

const char* UserName=env->GetStringUTFChars(jUserName,NULL);

const char* Password=env->GetStringUTFChars(jPassword,NULL);

//COM-Initialize

CoInitialize(NULL);

//Create Instance

td.CreateInstance(CLSID_TDConnection);

td->InitConnection(Server, Database);

td->ConnectProject(DataBase, UserName, Password);

//... Add Node...New Folder...

td->ReleaseConnection();

CoUninitialize();

//Release Strings

env->ReleaseStringUTFChars(jTDAPIHost,TDAPIHost);

env->ReleaseStringUTFChars(jDataBase,DataBase);

env->ReleaseStringUTFChars(jUserName,UserName);

env->ReleaseStringUTFChars(jPassword,Password);

printf("End DLL");

return NOERROR;

}

Can anybody help me with this? Thank you very much!

[3896 byte] By [MainS] at [2007-9-26 9:36:06]
# 1

This MAY be the problem:

getStringUtf takes as input the address of a boolean which the java system will fill in if the call results in a copy. (In other words, it is a runtime system option whether or not to copy the strings.)

You should be releasing those strings only if a copy has, in fact, been made.

I suggest you give the NewStringUTF some booleans into which to write what happen3ed, and you check those to determine whether or not to relase the copies.

bschauwe at 2007-7-1 21:04:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hello Bill!

Thanks for your help, but the the JNI-Functions GetStringUTFChars and ReleaseStringUTFChars aren't the problem. I've tested my wrapper.dll without them (by passing "constant strings" to the functions) and it didn't work either.

Is it possible that the VM can't call a wrapper.dll which calls a DCOM-DLL? So where is my failure? And what can I try?

Bye

MainS

By the way:

The sign before the JNI-functions in my code should be an arrow, as env points to them.

(env->ReleaseStringUTFChars(jTDAPIHost,TDAPIHost);)

MainS at 2007-7-1 21:04:55 > top of Java-index,Java HotSpot Virtual Machine,Specifications...