ctypes shared object FILE*

member thudfoo thudfoo at opensuse.us
Fri Nov 14 00:02:58 CET 2008

On 11/8/08, Dog Walker <thudfoo at gmail.com> wrote:
> I need to call a function in a shared object with this signature:
>  init_dialog(FILE *input, FILE *output)
>  The FILE*'s are to stdin and stdout.
>  The call from python is libdialog.init_dialog( x, y)
>  I need to define x and y so that they will have the structure of
>  sys.stdin and sys.stdout; the called function (init_dialog) is using a
>  (std?) function fileno to extract the fileno from the FILE* describing
>  stdin and stdout.
>  How can I do this?

I should have said "stderr" rather than "stdout".

And the answer is:

from ctypes import *
from ctypes.util import find_library
libc = CDLL(find_library("c"))
libdialog = CDLL(find_library("dialog"))
class FILE(Structure): pass

libdialog.init_dialog(POINTER(FILE).in_dll(libc, "stdin"),
POINTER(FILE).in_dll(libc, "stderr"))

>  --
>  I have seen the future and I'm not in it!
> --
>  http://mail.python.org/mailman/listinfo/python-list

More information about the Python-list mailing list