7 messages in net.java.dev.jna.usersRe: [jna-users] Trivial question.
FromSent OnAttachments
Jorge Nieto-MadridSep 9, 2008 3:47 am 
Timothy WallSep 9, 2008 6:24 am 
Jorge Nieto-MadridSep 11, 2008 4:08 am 
Timothy WallSep 11, 2008 6:02 am 
Jorge Nieto-MadridSep 11, 2008 8:43 am 
Timothy WallSep 11, 2008 9:07 am 
Jorge Nieto-MadridSep 15, 2008 5:10 am 
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] Trivial question.Actions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 11, 2008 9:07:01 am
List:net.java.dev.jna.users

Try W32API.INVALID_HANDLE_VALUE

On Sep 11, 2008, at 11:43 AM, Jorge Nieto-Madrid wrote:

Hi Timothy,

Thank you very much for your fast reply, I wonder how you get to answer all those emails you become everyday! Well, I have mapped the void * parameters to Pointer and the HANDLE as in the examples. My question now is, how can I map the argument (HANDLE)0xFFFFFFFF in the function, because you said I can not assign arbitrary values to pointers.

function readMemory() hShare = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL, PAGE_READWRITE, 0, sizeof(VIRTUAL_DEVICE), cpName);

I declared HANDLE hShare = new HANDLE(); public static boolean OpenShareMemory(String cpName) { .... HANDLE hff = new HANDLE(); //How could I represent the 0xFFFFFFFF ?? hShare = CreateFileMapping(hff, 0, PAGE_READWRITE, 0, getSizeOfVirtualDevice(), cpName);

.... }

Thanks so much!

2008/9/11 Timothy Wall <twal@dev.java.net>

On Sep 11, 2008, at 7:08 AM, Jorge Nieto-Madrid wrote:

I was interested in learning how JNA relates a memory Address (an integer) with the contains of the addressed memory. In C++ a pointer is just a variable that stores a memory address that you can assign to and also dereference, so if a function returns a memory address (pointer) you can dereference it to view its contents. I don't know how this would be possible in JNA (I read the doc. but it seems you can only see the contents of a pointer but no the address).

In general you can't assign arbitrary values to pointers, but you can derive via offset (Pointer.share), write to memory (Pointer.setXXX, Pointer.write) and read from memory (Pointer.getXXX, Pointer.read).

Anyway this is the code I would like to map to JNA:

...

If I map HANDLE to int, should I map:

Look at the examples in com.sun.jna.examples.win32 and com.sun.jna.win32. Most of the basic win32 type definitions are already there.

And in general, Pointers do *not* map to integer types.

I another file I define the Kernel32 Interface public interface Kernel32 extends StdCallLibrary { // Method declarations, constant and structure definitions go here Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("C:\\windows\\system32\\kernel32.dll", Kernel32.class);

You don't need an absolute path for kernel32. Again, look at the example Kernel32 implementation.

Kernel32 SYNC_INSTANCE = (Kernel32) Native.synchronizedLibrary(INSTANCE);

This is only needed if your library requires it. Kernel32 does not.

Pointer CreateFileMappingW(int hFile, int lpFileMappingAttributes, int flProtect, int dwMaximumSizeLow, int dwMaximumSizeHigh, String lpName); ....

I tried this way but I did not work. Any suggestions?? thanks.

I'd recommend using the default options set up by W32API rather than explicitly invoking A/W functions. If you *are* going to explicitly use a XXXW function, you have to use WString, not String, unless you install a type mapper to ensure String is converted to WString.

Again, the w32 example mappings show how all of this is done.