public JNIResult AttachCurrentThreadAsDaemon(out JNIEnv penv, JavaVMInitArgs?args) { if (attachCurrentThreadAsDaemon == null) { MethodWrapper.GetDelegateForFunctionPointer(functions.AttachCurrentThreadAsDaemon, ref attachCurrentThreadAsDaemon); } IntPtr env; JNIResult result; if (args.HasValue) { JavaVMInitArgs value = args.Value; result = attachCurrentThreadAsDaemon.Invoke(native, out env, &value); } else { result = attachCurrentThreadAsDaemon.Invoke(native, out env, null); } if (result == JNIResult.JNI_OK) { penv = new JNIEnv(env); } else { penv = null; } return(result); }
public JNIResult AttachCurrentThreadAsDaemon(out JNIEnv penv, JavaVMInitArgs? args) { if (attachCurrentThreadAsDaemon == null) { MethodWrapper.GetDelegateForFunctionPointer(functions.AttachCurrentThreadAsDaemon, ref attachCurrentThreadAsDaemon); } IntPtr env; JNIResult result; if (args.HasValue) { JavaVMInitArgs value = args.Value; result = attachCurrentThreadAsDaemon.Invoke(native, out env, &value); } else { result = attachCurrentThreadAsDaemon.Invoke(native, out env, null); } if (result == JNIResult.JNI_OK) { penv = new JNIEnv(env); } else { penv = null; } return result; }
private static void Init() { if (!init) { string findJvmDir = FindJvmDir(); AddEnvironmentPath(findJvmDir); var args = new JavaVMInitArgs(); try { //just load DLL Dll.JNI_GetDefaultJavaVMInitArgs(&args); init = true; } catch (BadImageFormatException ex) { // it didn't help, throw original exception throw new JNIException("Can't initialize jni4net. (32bit vs 64bit JVM vs CLR ?)" + "\nCLR architecture: " + ((IntPtr.Size == 8) ? "64bit" : "32bit") + "\nJAVA_HOME: " + (Bridge.Setup == null || Bridge.Setup.JavaHome == null ? "null" : Path.GetFullPath(Bridge.Setup.JavaHome)) , ex); } } }
public static void CreateJavaVM(out JavaVM jvm, out JNIEnv env, bool attachIfExists, params string[] options) { Init(); IntPtr njvm; IntPtr nenv; var args = new JavaVMInitArgs(); args.version = JNI_VERSION_1_4; if (options.Length > 0) { args.nOptions = options.Length; var opt = new JavaVMOption[options.Length]; for (int i = 0; i < options.Length; i++) { opt[i].optionString = Marshal.StringToHGlobalAnsi(options[i]); } fixed(JavaVMOption *a = &opt[0]) { args.options = a; } } JNIResult result; if (attachIfExists) { IntPtr njvma; int count; result = Dll.JNI_GetCreatedJavaVMs(out njvma, 1, out count); if (result != JNIResult.JNI_OK) { throw new JNIException("Can't enumerate current JVMs " + result); } if (count > 0) { njvm = njvma; jvm = new JavaVM(njvm); result = jvm.AttachCurrentThread(out env, args); if (result != JNIResult.JNI_OK) { throw new JNIException("Can't join current JVM " + result); } return; } } result = Dll.JNI_CreateJavaVM(out njvm, out nenv, &args); if (result != JNIResult.JNI_OK) { Console.Error.WriteLine("Can't load JVM (already have one ?)"); throw new JNIException("Can't load JVM (already have one ?) " + result); } jvm = new JavaVM(njvm); env = new JNIEnv(nenv); }
public static void CreateJavaVM(out JavaVM jvm, out JNIEnv env, bool attachIfExists, params string[] options) { Init(); IntPtr njvm; IntPtr nenv; var args = new JavaVMInitArgs(); args.version = JNI_VERSION_1_4; if (options.Length > 0) { args.nOptions = options.Length; var opt = new JavaVMOption[options.Length]; for (int i = 0; i < options.Length; i++) { opt[i].optionString = Marshal.StringToHGlobalAnsi(options[i]); } fixed (JavaVMOption* a = &opt[0]) { args.options = a; } } JNIResult result; if (attachIfExists) { IntPtr njvma; int count; result = Dll.JNI_GetCreatedJavaVMs(out njvma, 1, out count); if (result != JNIResult.JNI_OK) { throw new JNIException("Can't enumerate current JVMs " + result); } if (count > 0) { njvm = njvma; jvm = new JavaVM(njvm); result = jvm.AttachCurrentThread(out env, args); if (result != JNIResult.JNI_OK) { throw new JNIException("Can't join current JVM " + result); } return; } } result = Dll.JNI_CreateJavaVM(out njvm, out nenv, &args); if (result != JNIResult.JNI_OK) { Console.Error.WriteLine("Can't load JVM (already have one ?)"); throw new JNIException("Can't load JVM (already have one ?) " + result); } jvm = new JavaVM(njvm); env = new JNIEnv(nenv); }
public JNIResult AttachCurrentThread(out JNIEnv penv, JavaVMInitArgs? args) { if (attachCurrentThread == null) { MethodWrapper.GetDelegateForFunctionPointer(functions.AttachCurrentThread, ref attachCurrentThread); } IntPtr env; JNIResult result; if (args.HasValue) { JavaVMInitArgs initArgs = args.Value; result = attachCurrentThread.Invoke(native, out env, &initArgs); } else { result = attachCurrentThread.Invoke(native, out env, null); } penv = new JNIEnv(env); return result; }
public JNIResult AttachCurrentThread(out JNIEnv penv, JavaVMInitArgs?args) { if (attachCurrentThread == null) { MethodWrapper.GetDelegateForFunctionPointer(functions.AttachCurrentThread, ref attachCurrentThread); } IntPtr env; JNIResult result; if (args.HasValue) { JavaVMInitArgs initArgs = args.Value; result = attachCurrentThread.Invoke(native, out env, &initArgs); } else { result = attachCurrentThread.Invoke(native, out env, null); } penv = new JNIEnv(env); return(result); }
internal JNIResult AttachCurrentThread(out JNIEnv penv, JavaVMInitArgs? args) { if (attachCurrentThread == null) { MethodWrapper.GetDelegateForFunctionPointer(functions.AttachCurrentThread, ref attachCurrentThread); } IntPtr env; JNIResult result; //DC: using Patch_IgnoreArgsInAttach to handle the prob with attaching existing VMs if (BridgeSetup.Patch_IgnoreArgsInAttach == false && args.HasValue) { JavaVMInitArgs initArgs = args.Value; result = attachCurrentThread.Invoke(native, out env, &initArgs); } else { result = attachCurrentThread.Invoke(native, out env, null); } penv = new JNIEnv(env); return result; }
internal static extern JNIResult JNI_GetDefaultJavaVMInitArgs(JavaVMInitArgs* args);
internal static extern JNIResult JNI_CreateJavaVM(out IntPtr pvm, out IntPtr penv, JavaVMInitArgs* args);
private static void Init() { if (!init) { string findJvmDir = FindJvmDir(); AddEnvironmentPath(findJvmDir); var args = new JavaVMInitArgs(); try { //just load DLL Dll.JNI_GetDefaultJavaVMInitArgs(&args); init = true; } catch (BadImageFormatException ex) { // it didn't help, throw original exception throw new JNIException("Can't initialize jni4net. (32bit vs 64bit JVM vs CLR ?)" + "\nCLR architecture: " + ((IntPtr.Size == 8) ? "64bit" : "32bit") + "\nJAVA_HOME: " + (Bridge.Setup == null || Bridge.Setup.JavaHome == null ? "null" : Path.GetFullPath(Bridge.Setup.JavaHome)) , ex); } } }