[IronPython] Cast to a method pointer using CTYPES

Dino Viehland dinov at microsoft.com
Wed Feb 9 20:09:45 CET 2011


You want to pass a Python function, method, or other callable into C as a function pointer?  This stack overflow question covers that: http://stackoverflow.com/questions/874245/python-ctypes-and-function-pointers

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Andrew Evans
Sent: Wednesday, February 09, 2011 10:41 AM
To: users at lists.ironpython.com
Subject: [IronPython] Cast to a method pointer using CTYPES

Forgive me if what I ask is a novice question. I have some C code that was asked to bring to Python I prefer IronPython and remember seeing that CTYPES was implemented into it :-)

I am not really the best C coder and was suggested by C coders that it couldn't be done in Python. I aim to prove them wrong

int main(int argc, char **argv)
{
   int (*func)();
   func = (int (*)()) myCode;
   printf("myCode Length is : %d",strlen(myCode));
   (int)(*func)();



}
is it possible to cast to a function pointer in IronPython using CTYPES I was looking at the CTYPES docs and from what I understand CTYPES has something called callback functions.

Anyway any idea or help

would be very valuable

Thank You
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110209/7803ad63/attachment.html>


More information about the Ironpython-users mailing list