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