Java-C-Cobol getting Application error

Hi,

We have existing cobol dll, and need to call cobol dll funtion from Java. I have developed C dll which talks to cobol dll and fetch the information from cobol. I'm calling C dll from Java using JNI. I able to fetch the information from Cobol to C but could not able to get that information from C to Java and getting

javaw.exe -Application error

The instruction at "0x424a5c64" referenced memory at "0x00000000". The memory could not be "written".

There is no error if I don't call the Cobol dll at all - I mean the Java-C part works. I'm using pointers because cobol input parameters are pointers. Have you any suggestions about the problem?

Thanks in Advance,

Sudhakar

[720 byte] By [ysudhakara] at [2007-11-26 14:03:13]
# 1

Looks like there is n unititialized pointer that is addressing location 0.

One thing you could try is writing a small C program to invoke your DLL - that should tell you whether that part works.

Another thing you can do - if you have VC++ - is open your dll project in the IDE, set a breakpoint, and name the calling program to be java.exe. That will allow you to single-step through your dll and try to identify the error.

bschauwejavaa at 2007-7-8 1:46:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Thanks for the response. I have verified the code and all pointers are initialized. I'm getting the problem while returing C to Java.

In detailed

I able to get the output from cobol dll to C dll.

I have to take that output of cobol to Java from C dll.

At this point I'm getting Javaw.exe application error.

Java-C fine

C-Cobol fine

C-Java getting error.

If possible could you please explain how to debug my C dll in Visual Studio calling javaw.exe.

I have tried do open my C dll using development environment (Visual Studio) and I have got open with prompt box. Please suggest me which program need to specify here and how to link javaw.exe.

Thanks in Advance.

ysudhakara at 2007-7-8 1:46:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
Hi,Have you tried to use a generic JNI Wrapper like JNative since it seems that your C library does not add any feature to your Cobol DLL.If you give it a try please post if it was successful or not and why.--Marc ( http://jnative.sf.net)
mdentya at 2007-7-8 1:46:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

1. "Open in vc++" means "open the project".

2. When you open a dll project, if you look around the IDE you will find that there is a menu item that will show "project settings".

3. One possible setting for a DLL project is to specify the program to run (since you cannot directly execute a DLL).

4. What you want is to run the program java.exe, which is how JAVA is started.

5. You want to tell the java system about your java program. That means that all the stuff you usually pass to JAV on the command line must be entered into more project settings, as command-line options.

bschauwejavaa at 2007-7-8 1:46:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

Thanks for your information. I have tried to find out for null pointers, but doen't have any NULL pointers. I'm giving the code. Could you please check the code and give me the solution.

C Program

-

#include <jni.h>

#include <stdio.h>

#include <windows.h>

#include "MibFrame.h"

JNIEXPORT jstring JNICALL Java_main_MibFrame_processTranslations

(JNIEnv *env, jobject obj, jstring mibcode, jstring output, jstring error, jstring rc, jstring date)

{

const int arrayMIBSize = 100;

const int arrayOutputSize = 4096;

const int arrayErrorSize = 80;

const int arrayRCSize = 4;

const int arrayDateSize = 6;

size_t len;

char mibarray[arrayMIBSize];

char outputarray[arrayOutputSize];

char errorarray[arrayErrorSize];

char rcarray[arrayRCSize];

char datearray[arrayDateSize];

FILE *out;

out = fopen("mibtest.txt","w");

fprintf(out, "Entered the C Application \n");

fclose(out);

const char *mibCodeInput = env->GetStringUTFChars(mibcode, 0);

const char *outputInput = env->GetStringUTFChars(output, 0);

const char *errorInput = env->GetStringUTFChars(error, 0);

const char *returnCodeInput = env->GetStringUTFChars(rc, 0);

const char *dateInput = env->GetStringUTFChars(date, 0);

out = fopen("mibtest.txt","a");

fprintf(out, "prior to getting length \n");

fclose(out);

out = fopen("mibtest.txt","a");

fprintf(out, "\nfirst instance of parameter information \n");

fprintf(out, "mib code = %s \n", mibCodeInput);

fprintf(out, "output = %s \n", outputInput);

fprintf(out, "error = %s \n", errorInput);

fprintf(out, "return code = %s \n", returnCodeInput);

fprintf(out, "date = %s \n\n", dateInput);

fclose(out);

for (int a = 0; a < arrayMIBSize; a ++)

mibarray[a] = ' ';

mibarray[arrayMIBSize - 1] = '\0';

for (int b = 0; b < arrayOutputSize; b ++)

outputarray = ' ';

outputarray[arrayOutputSize - 1] = '\0';

for (int c = 0; c < arrayErrorSize; c ++)

errorarray[c] = ' ';

errorarray[arrayErrorSize - 1] = '\0';

for (int d = 0; d < arrayRCSize; d ++)

rcarray[d] = ' ';

rcarray[arrayRCSize - 1] = '\0';

for (int e = 0; e < arrayDateSize; e ++)

datearray[e] = ' ';

datearray[arrayDateSize - 1] = '\0';

len = env->GetStringLength(mibcode);

strncpy(mibarray, mibCodeInput, len);

mibarray[len] = '\n';

// mibptr = mibarray;

len = env->GetStringLength(output);

strncpy(outputarray, outputInput, len);

outputarray[len] = '\n';

// outputptr = outputarray;

len = env->GetStringLength(error);

strncpy(errorarray, errorInput, len);

errorarray[len] = '\n';

// errorptr = errorarray;

len = env->GetStringLength(rc);

strncpy(rcarray, returnCodeInput, len);

rcarray[len] = '\n';

// rcptr = rcarray;

len = env->GetStringLength(date);

strncpy(datearray, dateInput, len);

datearray[len] = '\n';

// dateptr = datearray;

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to Hinstance Call \n");

fclose(out);

out = fopen("mibtest.txt","a");

fprintf(out, "\nfirst instance of array information \n");

fprintf(out, "mib array = %s \n", mibarray);

fprintf(out, "output array = %s \n", outputarray);

fprintf(out, "error array = %s \n", errorarray);

fprintf(out, "return code array = %s \n", rcarray);

fprintf(out, "date array = %s \n\n", datearray);

fclose(out);

// get handle to dll

HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\Documents and Settings\\All Users\\Documents\\IBM\\wsappdev51\\workspace\\MIB\\main\\W0017604.dll");

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to FARPROC Call \n");

fclose(out);

// get pointer to the function in the dll

FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL), "W0017604");

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to type define \n");

fclose(out);

/*

Define the Function in the DLL for reuse. This is just prototyping

the dll's function. A mock of it. Use "stdcall" for maximum

compatibility.

*/

typedef void (__stdcall * pICFUNC)(char [], char [], char [], char [], char []);

// typedef void (__stdcall * pICFUNC)(char *, char *, char *, char *, char *);

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to obtaining process id \n");

fclose(out);

pICFUNC W0017604;

W0017604 = pICFUNC(lpfnGetProcessID);

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to call to W0017604 \n");

fclose(out);

// The actual call to the function contained in the dll

W0017604(mibarray, outputarray, errorarray, rcarray, datearray);

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to releasing the dll library \n\n");

fclose(out);

out = fopen("mibtest.txt","a");

fprintf(out, "\nsecond instance of array information \n");

fprintf(out, "mib array = %s \n", mibarray);

fprintf(out, "output array = %s \n", outputarray);

fprintf(out, "error array = %s \n", errorarray);

fprintf(out, "return code array = %s \n", rcarray);

fprintf(out, "date array = %s \n\n", datearray);

fclose(out);

// Release the Dll

FreeLibrary(hGetProcIDDLL);

out = fopen("mibtest.txt","a");

fprintf(out, "\nthird instance of array information (after conversion to jstring) \n");

fprintf(out, "mib array = %s \n", mibcode);

fprintf(out, "output array = %s \n", output);

fprintf(out, "error array = %s \n", error);

fprintf(out, "return code array = %s \n", rc);

fprintf(out, "date array = %s \n\n", date);

fclose(out);

env->ReleaseStringUTFChars(mibcode, mibCodeInput);

env->ReleaseStringUTFChars(output, outputInput);

env->ReleaseStringUTFChars(error, errorInput);

env->ReleaseStringUTFChars(rc, returnCodeInput);

env->ReleaseStringUTFChars(date, dateInput);

//return;

out = fopen("mibtest.txt","a");

fprintf(out, "Prior to return at end of program \n");

fclose(out);

return env->NewStringUTF(outputarray);

}

cobol input parameters are POINTERS and cobol program sends the output through function parameters.

Thanks in Advance.

ysudhakara at 2007-7-8 1:46:16 > top of Java-index,Java HotSpot Virtual Machine,Specifications...