JNA C Library Wrapper

62 views
Skip to first unread message

Дмитрий Заводников

unread,
May 20, 2013, 8:04:40 AM5/20/13
to jna-...@googlegroups.com
Hello!

I am a novice into JNA and maybe don't know well-known use-cases...

I am have such code in h-file:

...
void do_smf(FILE* file);
...


And it will be called from Java throw JNA like this:

...
public void do_smf(FILE file);
...


Where FILE is some class and I should create C library wrapper, open some file into this
library, get object FILE and use it to call method do_smf.

So, have already JNA some existing wrapper for C library or method to use java.io.File
without c FILE?

Timothy Wall

unread,
May 20, 2013, 7:32:05 PM5/20/13
to jna-...@googlegroups.com
It'd be easier if your native code exposed an interface that let you feed it a stream of bytes, or even a filename instead.

Since the FILE structure is opaque, you don't actually have to map it in JNA, you can generally get by using a Pointer, e.g.

Pointer fopen(String filename, String mode);
void fclose(Pointer fp);

If you want to get fancy and type-safe, you could do:

class FILE extends PointerType { }
FILE fopen(String filename, String mode);
void fclose(FILE fp);
> --
> You received this message because you are subscribed to the Google Groups "Java Native Access" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Дмитрий Заводников

unread,
May 20, 2013, 7:43:26 PM5/20/13
to jna-...@googlegroups.com
Thank you for your responce!

I am already implement seconf way with class FILE that extends PointerType.

вторник, 21 мая 2013 г., 5:32:05 UTC+6 пользователь Timothy Wall написал:
Reply all
Reply to author
Forward
0 new messages