Hi,
Yeah, I've included python.h and object.h but the compiler still complain
about not finding PyObject. It's weird. So I'm developing and App on
windows using VS 8.0. I've intalled Python 2.5 and have added the include
directory to my project's configuration. I'm also using boost.python in
another application to wrap my C++ classes.
Here's the C++ class I'm wrapping:
class widget
{
public:
widget(const string &name, unsigned int myint) :
{
}
static unsigned int __stdcall Callback(void * voidPtr);
void startMessageHandler();
void stopMessageHandler();
virtual void handleMessage(void *message)=0;
};
So the idea here is that the Python user will derive from widget and
override the virtual method "handleMessage". A thread is spawned by
"startMessageHandler()" that does some work and periodically calls
"handleMessage" passing it a chunk of memory. This memory is intended to be
zero-copy. Okay, so I've implemeted this class to set up the class for
Python:
class py_widget : public widget
{
public:
py_widget(PyObject *p, const string &name, unsigned int myint) :
self(p),
py_widget(name, myint)
{
}
void handleMessage(void *message);
PyObject *self;
};
where handleMessage has the following implementation:
void PyAsyncQueue::handleMessage(void *message)
{
//get the memory block size with a method not shown here
int size = getSize(message);
//create a buffer object so the Python users can access memory block
directly.
PyObject *obj = PyBuffer_FromReadWriteMemory( message, size ) ;
//now what ????
//I've tried calling the method directly based on some info I found
some documentation, but this doesn't
//compile because the compile can't find PyObject. Also, I really know
what it looks like anyways.
//self->attr("handleMessage")(obj);
//This boost.python call doesn't work either.
//call_method<void>(self, "handleMessage", obj);
}
Thanks for your suggestions on this,
James