[C++-sig] Not using virtual method

bob bob bobismyname at tiscali.co.uk
Thu May 6 05:53:23 CEST 2004

Hello, I'm having difficulties concerning using callbacks that have been extended in python. I'm using the windows video API DirectShow to play video to a screen through a transform method. The problem occurs when the Transform method is called from an object extended in python as a callback, not when called explicitly. How do I represent this functionality and prevent the python interpreter from crashing? I would like to try creating a thin wrapper to allow play to allow threads,

how can you do this?


Many Thanks,



// Cut down version of the C++ code


class Callback


            virtual void Transform() = 0;



class Player


            Player(Callback *);

            void Play();        // Play the video to the screen, returns allowing video to continue play



class Callback_Wrap : public Callback


            Callback_Wrap(PyObject *obj) : self(obj) {}

            virtual Transform() {call_method<void>(self, "Transform");}

            PyObject *self;





            class_<Callback, boost::noncopyable, boost::shared_ptr<Callback_Wrap> >("Callback")

                        .def("Transform", &Callback::Transform)



            class_<Player>("Player", init<Calback *>())

                        .def("Play", &Player::Play)





# Example python use


from MyVideo import *


class My_Callback(Callback):

            def Transform(self):

                        print "Hello, My_Callback here!"


a = My_Callback()

b = Player(a)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20040506/e0f160af/attachment.htm>

More information about the Cplusplus-sig mailing list