

![]() | 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: |
22 messages in net.java.dev.jna.usersRe: [jna-users] c FILE pointers in Java?| From | Sent On | Attachments |
|---|---|---|
| Simon BASLE | Jul 17, 2007 6:12 am | |
| Timothy Wall | Jul 17, 2007 9:16 am | |
| Simon BASLE | Jul 17, 2007 9:44 am | |
| Timothy Wall | Jul 17, 2007 10:10 am | |
| Simon BASLE | Jul 17, 2007 10:12 am | |
| Timothy Wall | Jul 17, 2007 11:18 am | |
| Nikolas Lotz | Jul 18, 2007 1:27 am | |
| Simon BASLE | Jul 18, 2007 5:35 am | |
| Nikolas Lotz | Jul 19, 2007 5:57 am | |
| Simon BASLE | Jul 19, 2007 6:07 am | |
| Nikolas Lotz | Jul 19, 2007 9:08 am | |
| Simon BASLE | Jul 24, 2007 8:40 am | |
| Simon BASLE | Jul 24, 2007 8:40 am | |
| Timothy Wall | Jul 24, 2007 9:55 am | |
| Timothy Wall | Jul 24, 2007 10:08 am | |
| Simon BASLE | Jul 25, 2007 6:00 am | |
| Simon BASLE | Jul 25, 2007 7:33 am | |
| Timothy Wall | Jul 25, 2007 7:53 am | |
| Timothy Wall | Jul 25, 2007 7:58 am | |
| Simon BASLE | Jul 25, 2007 8:29 am | |
| Timothy Wall | Jul 25, 2007 12:32 pm | |
| Timothy Wall | Jul 26, 2007 2:44 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] c FILE pointers in Java? | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Jul 24, 2007 9:55:54 am | |
| List: | net.java.dev.jna.users | |
On Jul 24, 2007, at 11:41 AM, Simon BASLE wrote:
Hi, I was wondering if there is an already implemented way of using C FILE pointers in Java using jna/jni ??
Use com.sun.jna.Pointer wherever FILE* is used.
I'd notably like to use the pre defined symbol stdout,
You can either write a DLL function that returns the value, or do a symbol lookup on stdout (you should be able to get the address of a variable the same as a function). Something like NativeLibrary.getInstance("c").getFunction("stdout") (note that Function is derived from Pointer).
and also convert from FILE to java File class (of course for this I'll need to create a kind of wrapping class, with the appropriate FILE Structure and methods to convert from Java's File class).
Perhaps you mean FileOutputStream? The java File class mostly just encapsulates a filesystem path, and throws in a few utility functions. Normally a File object has no real connection to the file system, while a FILE* usually is associated with an open file descriptor (an "int" value). There is a java.io.FileDescriptor which has a private int field representing a file descriptor, and it has predefined constants for stdout, stdin, and stderr (and can thus be used to create a FileIn/OutputStream.
You'd need to extract the file descriptor from the FILE* object (which is usually done with "fileno", which might be a function or a macro, so you might need to write a native method, or write a java mapping of the FILE struct so that you can access the file descriptor directly).
You probably don't really want to convert between native and java objects unless you really have to; it's generally cleaner to leave the native objects opaque and just hand them off to the next native function, rather than trying to convert their meaning into something in Java.
The idea is that I'd like to use a native method that needs a FILE * argument. Most of the time that argument is to be stdout. Any tips? :) Thanks Simon







