[C++-sig] In a C++ extension, how to use a C++ class exported in another extension

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Tue Jul 5 11:11:28 CEST 2005

--- Clark <foo.Clark at gmail.com> wrote:
> en... The GUI library I used is wxPython, which is wrapped by SWIG. And
> other parts of my program is wrapped by Boost.Python. I need extract a
> C++ pointer wxDC * from a wxPython's DC. 

I have some interest in this, too. Just like you we are using both wxPython and

I just checked in a simplified version of my BOOST_PYTHON_SWIG_ARG() macro.
Look here for revision 1.1 of swig_arg.hpp (it may take a couple of hours to
show up, therefore I am also attaching the file):


Copy the file somewhere into your source tree (the license is BSD-style open
source). #include "swig_arg.hpp" and write


somewhere in your module's init function. Simply .def() your functions with
wxDC* arguments. In Python, pass dc.this to your wrapped function. See also
swig_args_ext.cpp and tst_swig_args.py in the CVS directory above.

Is this all you need? Or do you also want to pass wxDC* and other wx* objects
to a function with a common base class as argument? That you could do easily
with thin wrappers (one-liners), e.g.:

  void foo(wxObject* obj);
  void foo_dc(wxDC* obj) { foo(obj); }
  void foo_nb(wxNotebook* obj) { foo(obj); }

In your init function:

  def("foo", foo_dc);
  def("foo", foo_nb);


Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: swig_arg.hpp
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050705/43c267f1/attachment.txt>

More information about the Cplusplus-sig mailing list