1 message in net.java.dev.jna.usersRe: [jna-users] Feature Request: publ...
FromSent OnAttachments
Timothy WallNov 19, 2007 12:50 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Feature Request: public Pointer(long peer)Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Nov 19, 2007 12:50:42 pm
List:net.java.dev.jna.users

On Nov 19, 2007, at 3:29 PM, rzo wrote:

Hello,

the constructor Pointer(long peer) is not public. Could you pls set it to public.

I have the following issue:

I am receiving messages through a callback function. The function definition requires an int (LPARAM), which is sometimes interpreted as int sometimes as a window handle.

LRESULT CALLBACK HookProc(

int nCode, WPARAM wParam, LPARAM lParam );

But HWND hWnd = new Pointer(lParam)

is currently not possible. I tried to define LPARAM as UNION, so that I could interpret it as int or Pointer, but this does not seem to work. It always returns null.

Before you can extract a non-primitive type from a union, you must set the active field via Union.setType(), e.g.

class LPARAM extends Union { public int iParam; public Pointer pParam; }

LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) { // assuming LPARAM is a union lParam.setType(Pointer.class); lParam.read(); // Pointer field may now be read accurately System.out.println("Pointer value is " + lParam.pParam); }

"setType" is required to avoid populating the Java Union fields with bogus objects. If you still get a "null" (and you know the value is not null), please file a bug on the issue.

Alternatively, you can define your callback parameters to be the specific type being used (see the w32keyhook example and the HOOKPROC defs in examples/win32/User32.java).