Hi everybody,
This is more like a C++ problem so I excuse in advance for that. I am sure that others encountered the same problem and I was curious how to solve it.
Basically, what I am trying to do is to call a function placed in a dllA file from my dllB. My dllB is called from from a
Java application; this is the standard way to do it. I have no header file for the dllA so I am trying to connect at runtime via LoadLibrary.
Even if the code looks OK, compiles OK, when I try to call it from Java throws this error:
-------------------------------------
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6FB35
Function=[Unknown.]
Library=(N/A)
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.
Current Java
thread:
at Tester.getMessage(Native Method)
at Tester.main(Tester.java:12)
Dynamic libraries:
0x00400000 - 0x00405000 c:\jdk1.4\bin\java.exe
0x77F60000 - 0x77FBE000 D:\WINNT\System32\ntdll.dll
0x77DC0000 - 0x77DFF000 D:\WINNT\system32\ADVAPI32.dll
0x77F00000 - 0x77F5E000 D:\WINNT\system32\KERNEL32.dll
0x77E70000 - 0x77EC5000 D:\WINNT\system32\USER32.dll
0x77ED0000 - 0x77EFC000 D:\WINNT\system32\GDI32.dll
0x77E10000 - 0x77E67000 D:\WINNT\system32\RPCRT4.dll
0x78000000 - 0x78040000 D:\WINNT\system32\MSVCRT.dll
0x6D400000 - 0x6D503000 c:\jdk1.4\jre\bin\hotspot\jvm.dll
0x77FD0000 - 0x77FFA000 D:\WINNT\System32\WINMM.dll
0x77FC0000 - 0x77FC8000 D:\WINNT\System32\mmdrv.dll
0x6BD00000 - 0x6BD1A000 D:\WINNT\System32\cs32ba11.dll
0x71700000 - 0x7178A000 D:\WINNT\system32\COMCTL32.dll
0x6D200000 - 0x6D207000 c:\jdk1.4\jre\bin\hpi.dll
0x6D3D0000 - 0x6D3DD000 c:\jdk1.4\jre\bin\verify.dll
0x6D240000 - 0x6D255000 c:\jdk1.4\jre\bin\java.dll
0x6D3F0000 - 0x6D3FD000 c:\jdk1.4\jre\bin\zip.dll
0x10000000 - 0x1000B000 D:\WINNT\system32\JNIDLL2.dll
0x76AC0000 - 0x76ADD000 D:\WINNT\System32\imagehlp.dll
0x10300000 - 0x1032A000 D:\WINNT\System32\mspdb50.dll
0x731B0000 - 0x731BA000 D:\WINNT\System32\PSAPI.DLL
Local Time = Tue Sep 25 13:02:45 2001
Elapsed Time = 1
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.0-beta-b65 mixed mode)
#
# An error report file has been saved as hs_err_pid225.log.
# Please refer to the file for further information.
#
----------------------------------------------------
The source code of my dllB file is:
#include "stdafx.h"
# include <jni.h>
# include <stdio.h>
# include <Tester.h>
# include <windows.h>
typedef char (*MYPROC)(unsigned short, unsigned short);
JNIEXPORT jint JNICALL Java_Tester_getMessage(JNIEnv *, jobject);
JNIEXPORT jint JNICALL Java_Tester_getMessage(JNIEnv *env, jobject obj)
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary("CT32");
// If the handle is valid, try to get the function address.
jint c = 0;
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "CT_init");
// If the function address is valid, call the function.
if (fRunTimeLinkSuccess = (ProcAdd != NULL))
{
unsigned short x1 = 1;
unsigned short x2 = 1;
ProcAdd (x1,x2);
c = 1;
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess) printf("message via alternative method\n");
return c;
}
It is the ProcAdd (x1,x2); call that throws the error. If I comment this line everything works just fine.
Thank you in advance for your help.
Best Regards,
Adrian Muscalu
------------------
[This message has been edited by Adrian Muscalu (edited September 25, 2001).]