Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make structure in JNA?

Tags:

java

jna

I get this error when i run the code below;

Exception in thread "AWT-EventQueue-0" java.lang.Error: Structure.getFieldOrder() on class javaapplication2.NewJFrame$APPBARDATA returns names ([cbSize, hWnd, jCallbackMessage, jEdge, rc, sParam]) which do not match declared field names ([])
    at com.sun.jna.Structure.getFields(Structure.java:872)
    at com.sun.jna.Structure.deriveLayout(Structure.java:983)
    at com.sun.jna.Structure.calculateSize(Structure.java:908)
    at com.sun.jna.Structure.calculateSize(Structure.java:896)
    at com.sun.jna.Structure.allocateMemory(Structure.java:357)
    at com.sun.jna.Structure.<init>(Structure.java:191)
    at com.sun.jna.Structure.<init>(Structure.java:180)
    at com.sun.jna.Structure.<init>(Structure.java:167)
    at com.sun.jna.Structure.<init>(Structure.java:159)
    at javaapplication2.NewJFrame$APPBARDATA.<init>(NewJFrame.java:31)
    at javaapplication2.NewJFrame.<init>(NewJFrame.java:56)
    at javaapplication2.NewJFrame$7.run(NewJFrame.java:255)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

my class:

class APPBARDATA extends Structure {

    WinUser.DWORD cbSize;
    WinUser.HWND hWnd;
    WinUser.UINT_PTR uCallbackMessage;
    WinUser.UINT_PTR uEdge;
    WinUser.RECT rc;
    WinUser.LPARAM lParam;

    @Override
    protected List getFieldOrder() {
        return Arrays.asList(new String[]{"cbSize", "hWnd", "uCallbackMessage", "uEdge", "rc", "lParam"});
    }
}

    APPBARDATA pdata = new APPBARDATA();
    pdata.lParam = new WinUser.LPARAM(0);
    pdata.cbSize = new WinUser.DWORD(32);
    pdata.hWnd = WinUser.HWND_BROADCAST;

What is wrong?

like image 499
MOD Avatar asked Feb 24 '13 09:02

MOD


1 Answers

Flag your attributes as public because as specified in the doc, JNA use class.getFields() to obtain the list of attributes.

Javadoc of Class.getFields():

Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. ...

like image 74
Aubin Avatar answered Oct 21 '22 17:10

Aubin