09-30-2013 05:49 PM - edited 09-30-2013 06:07 PM
I've been trying to build a .dll in teststand to automate the testing of a Java program, but I can't even get the JVM to start. This is the code I'm using to generate the dll in visual studio:
static JNIEnv *env = NULL;
static JavaVM *jvm = NULL;
int __declspec(dllexport) __stdcall startJVM(IDispatch* step)
{
JavaVMInitArgs vm_args;
JavaVMOption* options = new JavaVMOption[1];
string userClassPath = "";
options[0].optionString="-Djava.class.path=classpath";
vm_args.version = JNI_VERSION_1_6;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args)
return 0;
}
If I call this function via Teststand, the program immediately closes once it executes the last line of the function, no errors or anything.
Here is the info visual studio gives once I step over the JNI function call:
The thread 'Win32 Thread' (0x1838) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x19d8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1300) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x424) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1674) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1ef8) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x9f8) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x248) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1f60) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1acc) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x3a4) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1dfc) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1bb8) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x10ec) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1738) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1a68) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1eb4) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x180c) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x900) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1b94) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x2a4) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1bd0) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1f10) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0xec4) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1150) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1ca8) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1d3c) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1e74) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x3d8) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x97c) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1dc0) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1940) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1664) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x41c) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x62c) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1f58) has exited with code 1 (0x1).
The thread 'Win32 Thread' (0x1e58) has exited with code 1 (0x1).
Program Error.
Error Code: -17001
Where raised:
function: TypeUsageList:: DeleteGlobalTypeList
file: tstobj2\TypeList.cpp
line: 248
compilation time: 18:06:54 Jun 23 2013
Where caught: Debugging When Exception Constructed
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: TEException at memory location 0x0eefcadc..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbf80..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbf80..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbf80..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbf80..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbf80..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbf80..
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: std:: out_of_range at memory location 0x0eefbd24..
Program Error.
Error Code: -17001
Where raised:
function: TypeUsageList:: DeleteAllTypeUsageLists
file: tstobj2\TypeList.cpp
line: 952
compilation time: 18:06:54 Jun 23 2013
Where caught: Debugging When Exception Constructed
First-chance exception at 0x765cc41f in SeqEdit.exe: Microsoft C++ exception: TEException at memory location 0x0eefcad4..
The program '[6396] SeqEdit.exe: Native' has exited with code 1 (0x1).
I'm using jdk 1.7.0_40, which is where I'm getting the jni include files and jmv.lib file. I've tried using both the 1.7 client and server jmv.dll files, both of which cause the same crash. What am I doing wrong here?
10-01-2013 02:23 AM - edited 10-01-2013 02:23 AM
Update: I was able to get my .dll to work by loading the .dll with LoadLibrary and getting the JNI_CreateJavaVM function using GetProcAddress. I'm not really sure why my original method doesn't work, but either way this doesn't appear to be an issue with teststand.
10-01-2013 12:31 PM
Hey bclark,
Thank you for posting what worked for you but if you do not mind, could you elaborate more? Did you use LoadLibray within TestStand? Were you loading it before? This looks like there was some issue with the way memory was being allocated and *maybe* the previous way the dll was being called was dynamic. This would just be a conjecture though. Thanks for letting the forums know!
Best Regards
-KP
10-02-2013 03:15 PM
Hi Kurt-P,
I used LoadLibrary("javapath\jvm.dll") in my dll. Before that, I accessed the JNI_CreateJavaVM function directly by statically linking my dll with jvm.lib. I'm still not sure why that didn't work, but I don't mind using LoadLibrary instead.
10-23-2018 09:14 AM - edited 10-23-2018 09:15 AM
Did you solve the problem with java and teststand