[C++-sig] Re: Problem Wrapping DirectX with Boost Python

David Abrahams dave at boost-consulting.com
Tue Nov 12 20:05:59 CET 2002

Mark Russell <mrussell8081 at pacbell.net> writes:

> Hi Dave,

Hi Mark. Please post Boost.Python questions to the C++-sig:


> I am using Boost Python to wrap DirectX and have run into a problem
> I can't seem to get around.  Def seems to have trouble with
> __stdcall this works ok for me when I call bind directly so I'm not
> sure where to go from here.  I have attached a short test example
> cloned from the bind tests to show you where the problem is.  I am
> using msvc 6.5 and have tried both boost 1.29 and the latest from
> CVS.  Thanks in advance -- great library!  I am very excited to be
> working with it.

Thanks, I'm excited that so many people are using it!
> Test Code:
> #include <boost/python.hpp>
> using namespace boost::python;
> long __stdcall f_0()
> {
>     return 17041L;
> }
> {
>     def("f_0", f_0);
> }
> Error Message:
> Compiling...
> stdcall.cpp
> c:\boost\boost\python\detail\arg_tuple_size.hpp(61) : error C2664: 'struct
> boost::python::detail::char_array<0> __cdecl
> boost::python::detail::arg_tuple_size_helper(long (__cdecl *)(void))' :
> cannot convert parameter 1 from 'long (__stdcall *)(void)
> ' to 'long (__cdecl *)(void)'
>         This conversion requires a reinterpret_cast, a C-style cast or
> function-style cast

Right. The problem is that there are lots of Boost.Python components
which don't account for the presence of "extralegal" constructs like
__stdcall and __fastcall. In order to handle these automatically we'd
need, at the very least, to extend
boost/python/detail/arg_tuple_size.hpp to handle these cases, and I'm
guessing that there are a quite a few other places like that in the
code as well (e.g. boost/python/detail/returning.hpp). Here are your

1. Implement the extensions yourself and submit a patch. We'd really
   love that!

2. Write "thin wrapper" functions around all the functions you want to
   wrap, and wrap the wrappers:

   long f_0_aux() { return f_0(); }
      def("f_0", f_0_aux);

3. Wait for us to get around to extending Boost.Python to deal with
   __stdcall. Joel may be working on an ActiveX project soon himself,
   so it's not an impossibility that it will happen. However, this is
   still somewhat of a long shot.

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

More information about the Cplusplus-sig mailing list