# 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.