EXCEPTION_ACCESS_VIOLATION

I am trying to run a native method in the JNI with a dll I have written. The code in the dll compiles fine but I get this error when I attempt to run:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x1001ab15, pid=1244, tid=924

#

# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)

the beginning of the method is:

HWND windowHandle;

TCHAR* exeName;

const char* e;

exeName ="";

e ="";

e = jenv->GetStringUTFChars(exe,0);

strncpy(exeName,e,strlen(e));

I belive the problem is the last line. I have tried commenting sections of the code out to see if it would run and it would run with all the code except the line "strncpy(exeName,e,strlen(e));"

I don't know what is causing this error and any help would be appreciated.

[912 byte] By [BassMan449a] at [2007-10-3 7:09:03]
# 1

Yes, the problem is in the last line.

C/C++ is NOT a Java and you should care about memory allocation and pointers. exeName variable is a pointer but initially your pointer points to zero character string - only null terminator actually. So you need to allocate some memory and point your pointer. And don't forget to release allocated memory after usage. Also be care with strncpy() - it's very easy to lost null terminator and catch another access violation bit later :)

exeName = new TCHAR[ strlen( e ) + 1 ];

strcpy( exeName, e );

...

delete [] exeName;

Michael.Nazarov@sun.coma at 2007-7-15 2:04:31 > top of Java-index,Java HotSpot Virtual Machine,Specifications...