[C++-sig] help passing image data
J.D. Yamokoski
yamokosk at ufl.edu
Wed May 24 00:18:37 CEST 2006
Alright, I thank everyone for their suggestions so far. Following
earlier advice, I am trying a little easier embedding project - just
trying to make a simple (not CImg) object available in a python
environment. The problem is that the program crashes when started. First
here is the code I have so far - much has been copied from various
things I have found on the web (I can include a zip of the VS workspace
if anyone is really interested):
First the ultra basic class I am trying to share with python:
-- Begin Values.h
class Values
{
public:
Values(void);
~Values(void);
float GetA();
float GetB();
void SetA(float A);
void SetB(float B);
protected:
float a;
float b;
};
-- End Values.h
Then my wrapping of this class using boost,
-- Begin ValuesModule.h
#include <boost/python.hpp>
using namespace boost::python;
#include "Values.h"
object value_class = class_< Values >("Values")
.def( "get_a", &Values::GetA )
.def( "get_b", &Values::GetB )
.def( "set_a", &Values::SetA )
.def( "set_b", &Values::SetB );
extern object value_obj = value_class();
BOOST_PYTHON_MODULE(Values)
{
value_class;
}
-- End ValuesModule.h
To keep this simple I won't get into the rest of the code, partly
because the program is crashing when it creates the global value_obj.
The call stack pointer stops at the creation of this object and I get an
"Access violation reading..." some memory address.
My thoughts so far were to create this global value_obj. Later right
before a call to PyRun_String, I add this object to the global
dictionary by,
object main_module ((
handle<>( borrowed( PyImport_AddModule("__main__") ) )
));
object main_namespace = main_module.attr("__dict__");
// Insert the app's global value_obj into the python dictionary
if ( PyDict_SetItem( main_namespace.ptr()
, PyString_FromString("valueobj")
, value_obj.ptr() ) == -1 )
{
throw python_exception( "Could not add value_obj to the dictionary!" );
}
But I am stuck simply creating the object for right now. Any suggestions?
More information about the Cplusplus-sig
mailing list