0

I am novice jn JNA and am getting a bit confused with mixture of java and C++. In the WNDPROC callback method, the LPARAM is sent to the callback has to be used to retrive the DEV_BROADCAST_DEVICEINTERFACE class object. This is my code:

    public static User32.WNDPROC WndProc = new User32.WNDPROC() {    
        @Override     
        public LRESULT callback(HWND hWnd, int uMSG, WPARAM uParam, LPARAM lParam)    
        {
             User32.DEV_BROADCAST_DEVICEINTERFACE b = (User32.DEV_BROADCAST_DEVICEINTERFACE)      lParam;                                      

             if(b != null){ 
                 System.out.println("Device Name: " + b.dbcc_name.toString ());           System.out.println("New Volume GUID:" +     b.dbcc_classguid.toString());
             }
        }

The compiler begins to complain when I try to convert the lParam to class object, for obvious reasons. How do I achieve this?

1 Answer 1

1

You don't have to use LPARAM; if you're being passed a structure (or other specific type) by the native code, you can define the appropriate method signature and JNA will do the right thing, converting the native value into something useful in Java.

public LRESULT callback(HWND hWnd, int uMSG, WPARAM uParam, User32.DEV_BROADCAST_DEVICEINTERFACE lParam);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.