Passing WINNT file name as a argument from java to C code

Hi ,

Plz help me on the following issue for which we are struggling from last 2 weeks.

I am working on the encrption/decryption of some native files involving C based DES algorithm functions.

I have got some native files whose names has to be passed from my jni code to Native c code as parameters to those C functions.

I am using the GetStringUTFChars() in the following manner.

Is it the correct way.if wrong plz rectify my code.

JNIEXPORT jlong JNICALL Java_com_deceval_siidj_desgmdlib_DESObj_SetKeyFile

(JNIEnv *env, jobject obj, jstring filename)

{

long retskeyfile;

const char *fname;

fname =(char*) (*env)->GetStringUTFChars(env,filename,0);

if (fname == NULL) {

return -7; /* OutOfMemoryError already thrown */

}

retskeyfile=SetKeyFile( (char *)fname );

(*env)->ReleaseStringUTFChars(env,filename,fname);

return retskeyfile;

}

//C code is as follow

longSetKeyFile( char *filename )

{

#define MAXSIZE 2048

FILE *mfile;

char buffer [ MAXSIZE + 1 ];

int n;

/*printf ("sizeof int %i\n" , sizeof(int) );

printf ("sizeof long %i\n" , sizeof(long) );

printf ("sizeof char %i\n" , sizeof(char) );*/

mfile = fopen( filename , "rb" );

if ( mfile == NULL ) return -1;

n = fread (buffer , 1 , MAXSIZE , mfile );

fclose(mfile);

if ( (n=processBuffer( buffer , n ))!=0 ) return n;

_st[0] = 1 ;

return 0;

}

I am getting a return value -2 but expected value is 0.

Is there any other mechanism for passing on the file name from java code to C code.

Thanks in advance,

Santhosh

[1722 byte] By [chatrapathia] at [2007-11-26 20:37:31]
# 1
Print the name of the file before using it.Does it actually have a complete path? If not then that is probably the reason.
jschella at 2007-7-10 1:53:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
On NT it could be a permissions problem as well.There are windows API calls that allow you to verify file existence and check permissions.
jschella at 2007-7-10 1:53:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Hi jschell,

Thank you for the reply.yes,I am passing the absolute path itself as below. And Iam using JNI to invoke the functions in C.

public final static String KEY_FILE = System.getProperty("java.home").concat("\\bin\\keys002.rel");

Can u plz let me know the best site for WIndows API calls that you mentioned above.

chatrapathia at 2007-7-10 1:53:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
Hi,See File Management Functions at http://msdn2.microsoft.com/en-us/library/aa364232.aspxYou can call those functions with JNative (a free LGPL native bridge).--Marc ( http://jnative.sf.net)
mdentya at 2007-7-10 1:53:47 > top of Java-index,Java HotSpot Virtual Machine,Specifications...