471,595 Members | 1,091 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Re: ctypes shared object FILE*

On 11/8/08, Dog Walker <th*****@gmail.comwrote:
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
Nov 13 '08 #1
0 1082

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Heller | last post: by
19 posts views Thread by Thomas Heller | last post: by
1 post views Thread by Srijit Kumar Bhadra | last post: by
reply views Thread by Srijit Kumar Bhadra | last post: by
3 posts views Thread by Paddy | last post: by
2 posts views Thread by Sells, Fred | last post: by
1 post views Thread by Dog Walker | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.