Xvolks Posted February 18, 2010 Posted February 18, 2010 (edited) Hi, I'm new to AutoIt and I'm unable to find a way to call a function pointer returned by a DLL. An example may be clearer that description ; I want to do the following (error checking removed for readability): JNIEnv *env; JavaVMInitArgs vm_args; JavaVMOption options[1]; options[0].optionString = CLASS_PATH; vm_args.version = JNI_VERSION_1_4; vm_args.options = options; vm_args.nOptions = 1; vm_args.ignoreUnrecognized = JNI_FALSE; //load the JVM DLL HINSTANCE handle = LoadLibrary(RUNTIME_DLL); //get the function pointer to JNI_CreateJVM createJVM = (CreateJavaVM)GetProcAddress(handle, "JNI_CreateJavaVM"); res = createJVM(&vm, (void **)&env, &vm_args); //locate the class : I'm stuck HERE ! cls = env->FindClass(CLASS_NAME); For now I've written : If FileExists($runtime) Then $dll = DllOpen($runtime) $env = 0 $option = DllStructCreate("BYTE*;ptr") $vmInitArgs = DllStructCreate("DWORD;DWORD;ptr;BYTE") DllStructSetData($option, 1, $classPath) DllStructSetData($vmInitArgs, 1, 0x00010004) DllStructSetData($vmInitArgs, 2, 1) DllStructSetData($vmInitArgs, 3, DllStructGetPtr($option)) DllStructSetData($vmInitArgs, 4, 0) $res = DllCall($dll, "DWORD", "JNI_CreateJavaVM", "ptr*", $env, "ptr", ) If $res < 0 Then MsgBox(4096, "Erreur...", "Impossible to create JVM !") Else #how to call $env->FindClass EndIf Any clues are welcome. --Xvolks Edited February 18, 2010 by Xvolks
PsaltyDS Posted February 18, 2010 Posted February 18, 2010 DllCall() returns an array, so you should usually be testing something like: If $res[0] <> 0 Then After that, you seem to be getting an open process handle in $env, with which you want to do... what? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Xvolks Posted February 19, 2010 Author Posted February 19, 2010 Thank you for your answer. The purpose of this script is to do a Java launcher in replacement of the standard java.exe This script is able to read all needed informations (classpath, main class, option, ...) from an INI file. I've already did that in C but lost my sources. A sample in C can be found here : http://www.devx.com/Java/Article/34438/1763?supportItem=1 C++ syntax : cls = env->FindClass(CLASS_NAME); C syntax : cls = (*env)->FindClass(env, CLASS_NAME); Autoit syntax ? Thank you for your help. --Xvolks
PsaltyDS Posted February 19, 2010 Posted February 19, 2010 All I can think of (pulled cluelessly out of my... hat) is that maybe the process handle responds to DLL-like calls? Then, it would be something like (assuming ByValue): $aRET = DllCall($env, "str", "FindClass", "str", "ClassName") _ArrayDisplay($aRET, "$aRET) Doesn't even sound right typing it, but since nobody smarter chimed in... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Xvolks Posted February 20, 2010 Author Posted February 20, 2010 All I can think of (pulled cluelessly out of my... hat) is that maybe the process handle responds to DLL-like calls? Then, it would be something like (assuming ByValue): $aRET = DllCall($env, "str", "FindClass", "str", "ClassName") _ArrayDisplay($aRET, "$aRET) Doesn't even sound right typing it, but since nobody smarter chimed in... It seems I have to go the way described in this post : http://www.autoitscript.com/forum/index.php?showtopic=95510&st=0&p=691729&#entry691729 Basically, allocate native memory, construct native function in assembler, jump to it with CreateThread API (this what I do not want to do because thread creation is not the purpose here) --Xvolks
hans_castorp Posted February 1, 2020 Posted February 1, 2020 Did you ever get this to work? I am trying the same thing, but it already fails when calling "JNI_CreateJavaVM"
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now