Paul said:
So how do I get the directory of the current executable
so I can do a chdir() there?
I see I've mislead you. Sorry. I meant that you should (IMO) use explicit DLL
loading rather than relying on the primitive and inflexible (%Path% dependent)
stuff which is hard-coded into the stub lib. It's only a matter of a couple of
extra lines of code (well, maybe half a dozen) and insulates you from all sorts
of hidden nastiness. Respect the D in DLL and it'll be your friend ;-)
Anyway, here's some example code that I posted a couple of weeks ago. It lacks
error checking, but should provide useful pointers (or do I mean references?
;-)
I'm not sure what the mingw equivalent of the first two lines would be, but
since dynamically loading DLLs is /the/ central operation of any Windows
program, there must be an equivalent. With luck the code'll work as-is. I
repeat that you shouldn't need any special (to JNI) -l or -L flags for this to
work -- you are using DLLs not static libs, so the linker has nothing to do.
-- chris
=======================
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <jni.h>
typedef __declspec(dllimport) jint (__stdcall * CreateJavaVMFunc)(
JavaVM**,
void**,
void*);
// called with the full path to the JVM dll as its only parameter
int
main(int argc, char** argv)
{
// get lib entrypoint
HINSTANCE lib = LoadLibrary(argv[1]);
CreateJavaVMFunc createJavaVM = (CreateJavaVMFunc)GetProcAddress(
lib,
"JNI_CreateJavaVM");
// start JVM
JavaVMInitArgs initArgs;
JavaVMOption options[2] = { { "-verbose:jni" } , { "-Xcheck:jni" } };
initArgs.version = JNI_VERSION_1_2;
initArgs.nOptions = 0;
initArgs.options = options;
initArgs.ignoreUnrecognized = true;
JNIEnv *jniEnv;
JavaVM *javaVM;
createJavaVM(&javaVM, (void**)&jniEnv, &initArgs);
.........
=======================