10 Replies Latest reply: Oct 3, 2012 5:32 AM by EJP RSS

    What am I doing wrong?

    855297
      Hi,

      I am writing a Java-C++ DLL bridge to an existing DLL (A IBM Datastage DLL).
      I have a very simple method in Java called testConnection, it takes no parameters and has no return value. The code in the JNI C++ DLL is also very simple, hard coded values to set the server information and the a call to get all the projects once logged in.

      If I call the native method from Java then it fails everytime with invalid login credentials (Datastage error 80011) but if I call the very same JNI DLL from a CLI app written in C++ then it works everytime.
      Essentially I see the same code runs for both scenarios but the results are completely different, with only how I call the DLL as the difference between the 2 tests.
      I am using Java 1.6.0 from Eclipse and Visual C++ 2008 Express Edition

      Java result:
      E:\workspace_jni_projects\TestConnection>java TestApp
      in testconnection()
      result of set server params... 0
      last error = 80011
      [ 7784] [  ERROR] detach, env=02B813EC, DetachCurrentThread() had a problem; entering SHUTDOWNMODE

      CLI app result:
      E:\workspace_pbt_c++\TestConnection\Debug>TestConnection.exe
      in testconnection()
      result of set server params... 0
      getProjectList result = project1
      The Java code:

      public class TestConnection {
      public native void testConnection();
           
           static
           {
                System.loadLibrary("TestDatastageConnection");
           }
      }


      public class TestApp {
           public static void main(String[] args)
           {
                TestConnection app = new TestConnection();
                app.testConnection();
           }
      }

      The C++ Code:

      DLL Project:
      // TestDataStageConnection.cpp : Defines the exported functions for the DLL application.
      //

      #include "stdafx.h"

      #include "dsapi.h"

      #include "TestConnection.h"

      JNIEXPORT void JNICALL Java_TestConnection_testConnection(JNIEnv *, jobject)
      {
           printf(">>> in testconnection()\n");
           DSSetServerParams("domain", "username", "password", "server");
           printf(">>> result of set server params... %d\n", DSGetLastError());
           char* result = DSGetProjectList();
           if(result != NULL)
           {
                printf(">>> getProjectList result = %s\n", result);
           }
           else
           {
                printf(">>> last error = %d\n", DSGetLastError());
           }
      }

      Test Project:
      // TestConnection.cpp : Defines the entry point for the console application.
      //

      #include "stdafx.h"

      #include "TestConnection.h"

      int tmain(int argc, TCHAR* argv[])
      {
           Java_TestConnection_testConnection(NULL, NULL);
      }