class java.lang.Error - Invalid memory access - wrong mapping?

589 views
Skip to first unread message

Philipp Hana

unread,
Mar 10, 2014, 12:32:25 PM3/10/14
to jna-...@googlegroups.com
Hello,

I'm very new to JNA and would like to control a .NET App through Java (e.g. ButtonClicks,..). Therefore I got a .dll from a college which already works with JNI but not with my JNA test application.
When calling the same function he does: mylib.INSTANCE.Java_automation_JniAutomation_BindApp("D:\\dsl\\myapp.exe"); 
i get the following error:
class java.lang.Error - Invalid memory access
at com.sun.jna.Native.invokeVoid(Native Method)
at com.sun.jna.Function.invoke(Function.java:367)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy6.Java_automation_JniAutomation_BindApp(Unknown Source)

What I found out, that this error occurs, when the mapping is incorrect. but I can't figure out whats wrong about


The methode is loaded beforehand by a .dll.
       public interface mylib extends Library {
            mylib INSTANCE = (mylib)
                    Native.loadLibrary((Platform.isWindows() ? "automation" : "c"),
                            mylib.class);

            boolean Java_automation_JniAutomation_BindApp(String appPath);
        }

The methode in the .cpp file, which generates looks like this:
JNIEXPORT jboolean JNICALL Java_automation_JniAutomation_OpenApp(JNIEnv * env, jobject obj, jstring filePath)
{
   LPWSTR filePathLPCWSTR = JStringtoLPWSTR(env, filePath);
LPSTARTUPINFOW si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
//si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
BOOL open_val = CreateProcessW(NULL, filePathLPCWSTR, NULL, NULL, FALSE, 0, NULL, NULL, si, &pi);
   
   return (open_val != FALSE);
}


Would be great, if anyone could help me on this! Thanks in advance,
Philipp

ps: iam using VB 2013 Express, 64xbit to generate the .dll and Intelli IDEA 64xbit for the binding-call

Philipp Hana

unread,
Mar 13, 2014, 6:06:16 AM3/13/14
to jna-...@googlegroups.com
Update:
I still couldn't figure out, why i got this error.
Anyway I am going to use the UIAutomation from Windows now to use the WPF Functions in Java. Looks promising.
Philipp

Timothy Wall

unread,
Mar 13, 2014, 6:25:34 AM3/13/14
to jna-...@googlegroups.com
You need to bind JNA interfaces to methods exported from a DLL. You do NOT bind JNA interfaces to JNI functions; JNI functions are meant to be bound directly by the JVM.

Your function "JNIEXPORT jboolean JNICALL Java_automation_JniAutomation_OpenApp(JNIEnv * env, jobject obj, jstring filePath)” is a JNI function. You can have the JVM bind to it directly, you don’t need JNA for that.
> --
> You received this message because you are subscribed to the Google Groups "Java Native Access" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Philipp Hana

unread,
Mar 13, 2014, 5:53:28 PM3/13/14
to jna-...@googlegroups.com
Thanks a lot Timothy!
Reply all
Reply to author
Forward
0 new messages