Thread overview
DLL using JNI
Aug 06, 2007
jimp
Aug 06, 2007
Walter Bright
Aug 07, 2007
Walter Bright
August 06, 2007
I am using the C/C++ compiler version 8.49.

I have a DLL that can be called from either a C/C++ program or from a Java program using the Java Native Interface (JNI). When called from a C++ program it works OK. When called from a Java program, it works OK until the DLL needs to terminate. Then I get a message box for a Java Application Error. It says "The instruction at 0x1004c962 referenced memory at 0x82db0008. The memory could not be read." The Java.exe program must be terminated using the task manager.

I compile the DLL with other compilers and it works OK with Java. It is only Digital Mars that has a problem. Following is a copy of the def file, which is the only additional input to Digital Mars.

Why will the DLL not terminate with Digital Mars?


LIBRARY "AStylej.dll"
DESCRIPTION 'AStyle as a JNI DLL'
EXETYPE NT
SUBSYSTEM WINDOWS
CODE SHARED EXECUTE
DATA WRITE

EXPORTS
    _Java_ASInterface_AStyleMain@16    @ 1
    Java_ASInterface_AStyleMain = _Java_ASInterface_AStyleMain@16 @ 2
    _Java_ASInterface_GetVersion@8     @ 3
    Java_ASInterface_GetVersion = _Java_ASInterface_GetVersion@8 @ 4
August 06, 2007
jimp wrote:
> Why will the DLL not terminate with Digital Mars?

I have no idea. I suggest compiling the DLL with debug on, and run it under the debugger.
August 07, 2007
jimp wrote:
> Then I get a message box for a Java Application Error. It says
> "The instruction at 0x1004c962 referenced memory at 0x82db0008. The memory
> could not be read."

Being C/C++, this could very well be that your code suffers from an uninitialized pointer or a dangling pointer. It is not at all unusual for such code to appear to work with one compiler and fail with another, as the memory layouts are different.