Jump to content

How to call function pointers from a DLL ?


Xvolks
 Share

Recommended Posts

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 by Xvolks
Link to comment
Share on other sites

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?

:mellow:

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

:mellow:

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
Link to comment
Share on other sites

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...

:mellow:

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

Link to comment
Share on other sites

  • 9 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...