

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
53 messages in net.java.dev.jna.usersRe: [jna-users] How do I map X in C t...| From | Sent On | Attachments |
|---|---|---|
| genc...@web.de | May 20, 2009 6:35 am | |
| Timothy Wall | May 20, 2009 11:50 am | |
| Ahmet Özgür Gencaslan | May 25, 2009 2:15 am | |
| Timothy Wall | May 25, 2009 6:36 pm | |
| genc...@web.de | May 26, 2009 5:34 am | |
| genc...@web.de | May 26, 2009 5:37 am | |
| Timothy Wall | May 26, 2009 6:16 am | |
| genc...@web.de | May 26, 2009 8:49 am | |
| Timothy Wall | May 26, 2009 9:11 am | |
| Özgür Gencaslan | May 27, 2009 12:59 am | |
| Timothy Wall | May 27, 2009 3:52 am | |
| Zsolt Kúti | Aug 21, 2009 3:00 am | |
| Zsolt Kúti | Aug 21, 2009 3:32 am | |
| Daniel Kaufmann | Aug 21, 2009 6:00 am | |
| Olivier Chafik | Aug 21, 2009 6:22 am | |
| Zsolt Kúti | Aug 21, 2009 7:46 am | |
| Zsolt Kúti | Aug 21, 2009 7:46 am | |
| Olivier Chafik | Aug 21, 2009 3:11 pm | |
| Zsolt Kúti | Aug 21, 2009 11:11 pm | |
| Zsolt Kúti | Aug 22, 2009 4:02 am | |
| Zsolt Kúti | Aug 22, 2009 4:05 am | |
| Timothy Wall | Aug 22, 2009 5:08 am | |
| Zsolt Kúti | Aug 23, 2009 8:38 am | |
| Timothy Wall | Aug 23, 2009 9:17 am | |
| Olivier Chafik | Aug 23, 2009 10:49 am | |
| Zsolt Kúti | Aug 23, 2009 11:42 am | |
| Olivier Chafik | Aug 23, 2009 4:10 pm | |
| Zsolt Kúti | Aug 24, 2009 10:17 am | |
| Olivier Chafik | Aug 24, 2009 1:56 pm | |
| Timothy Wall | Aug 24, 2009 2:36 pm | |
| Olivier Chafik | Aug 24, 2009 4:17 pm | |
| Olivier Chafik | Aug 24, 2009 4:51 pm | |
| Timothy Wall | Aug 25, 2009 4:43 am | |
| Timothy Wall | Aug 25, 2009 4:48 am | |
| Olivier Chafik | Aug 25, 2009 7:07 am | |
| Timothy Wall | Aug 25, 2009 7:37 am | |
| Olivier Chafik | Aug 25, 2009 8:49 am | |
| Timothy Wall | Aug 25, 2009 10:39 am | |
| Olivier Chafik | Aug 25, 2009 3:02 pm | |
| Timothy Wall | Aug 26, 2009 6:25 am | |
| Olivier Chafik | Aug 26, 2009 11:14 am | |
| Samuel Audet | Aug 27, 2009 8:14 am | |
| Timothy Wall | Aug 27, 2009 8:34 am | |
| Timothy Wall | Aug 27, 2009 8:42 am | |
| Olivier Chafik | Aug 27, 2009 10:02 am | |
| Olivier Chafik | Aug 27, 2009 10:08 am | |
| Olivier Chafik | Aug 27, 2009 10:13 am | |
| Timothy Wall | Aug 27, 2009 10:15 am | |
| Samuel Audet | Aug 27, 2009 9:01 pm | |
| Olivier Chafik | Aug 28, 2009 9:21 am | |
| Samuel Audet | Aug 28, 2009 9:40 am | |
| Timothy Wall | Aug 28, 2009 12:18 pm | |
| Samuel Audet | Aug 28, 2009 7:18 pm |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] How do I map X in C to Y in Java? | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | May 26, 2009 9:11:38 am | |
| List: | net.java.dev.jna.users | |
On May 26, 2009, at 11:50 AM, genc...@web.de wrote:
Now i want to create/instanciate a Structure and use it with a native method.
this is the library function definition
int klom_spot_send_new_wordlist(Pointer spot_id, com.sun.jna.ptr.PointerByReference wordlist_list, int nr_wordlist);
nr_wordlist probably needs to be IntByReference, if it's returning the number of items in wordlist_list.
In general, you'll be better off presenting your C declaration next to your proposed Java mapping, rather than including the JNAerator auto- generated stuff. At the very least, leave in the auto-generated comments from JNAerator which includes the original C declaration.
This is the autogenerated code of the Structure by JNAerator.
public static class klom_spot_wordlist_s extends com.sun.jna.Structure { public klom_spot_wordlist_s() { } public klom_spot_wordlist_s(com.sun.jna.Pointer pointer, int offset) { super(); useMemory(pointer, offset); read(); } public klom_spot_wordlist_s(klom_spot_wordlist_s struct) { this(struct.getPointer(), 0); } ... public com.sun.jna.ptr.ByteByReference name; public com.sun.jna.ptr.ByteByReference name_orig; public com.sun.jna.ptr.PointerByReference phrases; public int nr_phrases; public int lm_nr; }
the following code simply crashes, which seems to be because the structure is not correct.
How can I get a Pointer from a Java String and pass it to a ByteByReference ?
PointerByReference wordlist_ptr = new PointerByReference(); // klomspot_array klom_spot_wordlist_s[] word_list = new klom_spot_wordlist_s[1]; Pointer[] wp_array = new Pointer[1];
// klomspot element klom_spot_wordlist_s wl_element = new klom_spot_wordlist_s();
// wordlist name as ByteByReference ByteByReference b_name = new ByteByReference(); Memory b_name_mem = new Memory(20); b_name_mem.setString(0, "name"); b_name.setPointer(b_name_mem.getPointer(0));
// wordlist orig_name as ByteByReference ByteByReference b_name_orig = new ByteByReference(); Memory b_name_mem_orig = new Memory(20); b_name_mem_orig.setString(0, "name_orig"); b_name_orig.setPointer(b_name_mem_orig.getPointer(0));
// initializing first array-element wl_element.lm_nr = 1; wl_element.name = b_name; wl_element.name_orig = b_name_orig; wl_element.nr_phrases = 1;
// setting phrases StringArray sa = new StringArray(new String[]{"foo", "faa"}); PointerByReference ptr_phrase = new PointerByReference(); ptr_phrase.setPointer(sa.getPointer(0));
wl_element.phrases = ptr_phrase;
// setting array-element word_list[0] = wl_element; wp_array[0] = wl_element.getPointer();
// set first Pointer address. wordlist_ptr.setPointer(wp_array[0]);
thanks in advance
...
____________________________________________________________ Text: GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://produkte.web.de/go/04/







