I am extremely new to JNA and am kind of lost. I want to use the "GetRootElement" method present in the IUIAutomation interface inside the UIAutomationCore.dll in my java program.
Could someone please help me with some tutorial or code for the same?
Much appreciated.
UPDATE :
I tried doing something with the links provided by Daniel and now I face some other trouble. Class not registered. Here is my code :
test.java
public class test {
public interface UIAutomationCore extends Library{
UIAutomationCore INSTANCE = (UIAutomationCore) Native.loadLibrary("UIAutomationCore", UIAutomationCore.class);
IUIAutomationElement GetRootElement();
}
public static void main(String[] args) {
othermethod();
//System.out.println(a.toString());
}
public static void othermethod(){
IUIAutomation a = FactorySecond.createCUIAutomation();
System.out.println(a.toString());
}
}
FactorySecond.java
public abstract class FactorySecond {
private FactorySecond() {}
public static net.java.dev.jna.jna.IUIAutomation createCUIAutomation() {
Factory factory = new Factory();
return factory.createObject(net.java.dev.jna.jna.IUIAutomation.class);
}
}
IUIAutomation.java
@ComObject(clsId="{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}")
public interface IUIAutomation extends IUnknown {
@VTID(5)
net.java.dev.jna.jna.IUIAutomationElement getRootElement();
}
It gives the exception :
Exception in thread "main" com.sun.jna.platform.win32.COM.COMException: Class not registered (puArgErr=)
at com.sun.jna.platform.win32.COM.COMUtils.checkRC(COMUtils.java:112)
at com.sun.jna.platform.win32.COM.COMUtils.checkRC(COMUtils.java:95)
at com.sun.jna.platform.win32.COM.util.Factory.createObject(Factory.java:151)
at net.java.dev.jna.jna.FactorySecond.createCUIAutomation(FactorySecond.java:11)
at net.java.dev.jna.jna.test.othermethod(test.java:21)
at net.java.dev.jna.jna.test.main(test.java:17)
Can someone tell me what am I doing wrong ?
The best tutorial is the Getting Started link at the JNA project site.
You'll be doing something similar, loading the native library (UIAutomationCore) and then writing the function declaration for GetRootElement as a Java method, mapping the JNA types to Java types.
Check out other Win32 library implementations for more examples.