[C++-sig] Wrapping and Passing HWND with Boost.Python

Niall Douglas s_sourceforge at nedprod.com
Tue May 1 15:18:48 CEST 2012


A HWND is always a void * i.e. an opaque pointer. Unfortunately some 
people using BPL think that BPL can't handle opaque pointers, so they 
do fun stuff like use a thunk struct type for void * instead, and 
wrap the lot in manual pointer casting. It's far easier just to 
declare it an opaque pointer and be done with it.

It is very unfortunate indeed that win32gui returns a HWND as an 
integer. It isn't an integer and must not be treated as one. Still, 
it's easy to write a routine which converts python integers to void 
*.

Niall


On 30 Apr 2012 at 14:54, Ehsan Pi wrote:

> Thanks Roman for your quick reply,
> 
> That's what confuses me. HWND is essentially a pointer to an int to hold
> the window handle. How can to convert them to each other?
> 
> Ehsan
> 
> On Mon, Apr 30, 2012 at 2:46 PM, Roman Yakovenko
> <roman.yakovenko at gmail.com>wrote:
> 
> > On Mon, Apr 30, 2012 at 9:11 PM, Ehsan Pi <ehsanpii at gmail.com> wrote:
> > > In python I get the not-match error:
> > >
> > >     >>> import MyWrapper
> > >     >>> import win32gui
> > >     >>> hwnd = win32gui.GetDesktopWindow()
> > >     >>> foo = MyWrapper.Foo(hwnd)
> > >     Traceback (most recent call last):
> > >       File "<stdin>", line 1, in <module>
> > >     Boost.Python.ArgumentError: Python argument types in
> > >         Foo.__init__(Foo, int)
> > >     did not match C++ signature:
> > >         __init__(struct _object *, struct HWND__ * window)
> > >     >>>
> > >
> > > How can I correct this problem to be able to pass a window's handle (from
> > > win32gui) in Python to C++ class, and interact with it?
> >
> > I think the error is pretty clear: the exported constructor expects a
> > pointer to some struct(?) HWND__, while, win32gui returns the handle
> > as integer. You will have to find some way to associate handle as
> > integer with handle as HWND__.  Once you find it, you can use
> > "make_constructor" functionality, which is also supported by py++.
> >
> > HTH.
> > _______________________________________________
> > Cplusplus-sig mailing list
> > Cplusplus-sig at python.org
> > http://mail.python.org/mailman/listinfo/cplusplus-sig
> >
> 


-- 
Technology & Consulting Services - ned Productions Limited.
http://www.nedproductions.biz/. VAT reg: IE 9708311Q.
Work Portfolio: http://careers.stackoverflow.com/nialldouglas/





More information about the Cplusplus-sig mailing list