By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

Re: ctypes shared object FILE*

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.