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!

