Closed timob closed 5 years ago
windows.go
needs to load the dll and find the two functions.
@timob any update on this issue? really looking forward to using this!
in winows.go,you can add code like following:
package jnigi
/*
#cgo CFLAGS:-I'D:/develop tool/jdk1.7.0_80/include' -I'D:/develop tool/jdk1.7.0_80/include/win32'
#cgo LDFLAGS:-ljvm -L'D:/develop tool/jdk1.7.0_80/jre/bin/server'
#include<jni.h>
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
typedef jint (*type_JNI_GetDefaultJavaVMInitArgs)(void*);
type_JNI_GetDefaultJavaVMInitArgs var_JNI_GetDefaultJavaVMInitArgs;
jint dyn_JNI_GetDefaultJavaVMInitArgs(void *args) {
return var_JNI_GetDefaultJavaVMInitArgs(args);
}
typedef jint (*type_JNI_CreateJavaVM)(JavaVM**, void**, void*);
type_JNI_CreateJavaVM var_JNI_CreateJavaVM;
jint dyn_JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args) {
jint ret = var_JNI_CreateJavaVM(pvm, penv, args);
return ret;
}
char* dllPath = "D:/develop tool/jdk1.7.0_80/jre/bin/server/jvm.dll";
type_JNI_GetDefaultJavaVMInitArgs Get_JNI_GetDefaultJavaVMInitArgs(){
HMODULE jvm_dll = LoadLibrary(dllPath);
type_JNI_GetDefaultJavaVMInitArgs ret =(type_JNI_GetDefaultJavaVMInitArgs) GetProcAddress(jvm_dll,"JNI_GetDefaultJavaVMInitArgs");
return ret;
}
type_JNI_CreateJavaVM Get_JNI_CreateJavaVM(){
HMODULE jvm_dll = LoadLibrary(dllPath);
type_JNI_CreateJavaVM ret =(type_JNI_CreateJavaVM) GetProcAddress(jvm_dll,"JNI_CreateJavaVM");
return ret;
}
void InitJNI(){
var_JNI_GetDefaultJavaVMInitArgs = Get_JNI_GetDefaultJavaVMInitArgs();
var_JNI_CreateJavaVM = Get_JNI_CreateJavaVM();
}
*/
import "C"
import(
"unsafe"
)
func jni_GetDefaultJavaVMInitArgs(args unsafe.Pointer) jint {
return jint(C.dyn_JNI_GetDefaultJavaVMInitArgs((unsafe.Pointer)(args)))
}
func jni_CreateJavaVM(pvm unsafe.Pointer, penv unsafe.Pointer, args unsafe.Pointer) jint {
return jint(C.dyn_JNI_CreateJavaVM((**C.JavaVM)(pvm), (*unsafe.Pointer)(penv), (unsafe.Pointer)(args)))
}
func init(){
C.InitJNI()
}
And when using the function,add args -Xint
when inital jvm args
@hanxueming126 thanks for that code. I've got a change coming that does what you have but mostly in Go init()
function like the other OS files.
The current master doesn't support Windows anymore because the functions:
are not implemented in
windows.go
. Please seelinux.go
for how these are implemented. Basically this file dynamically loads the jvm library.