[C++-sig] problems with lvalue_from_pytype

David Abrahams dave at boost-consulting.com
Sat Nov 23 02:55:13 CET 2002

Mark Russell <mrussell8081 at pacbell.net> writes:

> David,
> From your last reply:
> snip...
> One way is just to find out what the real type of the pointee is on your
> own, by
> examining the header file.
> An HWND is a pointer to an HWND__ struct defined as follows:
> struct HWND__ { int unused; };
> typedef struct HWND__* HWND
> I have attached three files noddy.cpp cn.cpp, and cnl.cpp-- cnl
> contains my conversion for noddy objects just using longs cn does
> the same thing using HWND.  The following python session shows how
> it works for longs:
> C:\developer\com-hacking\boost hacking\convert noddy long>python
> Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import noddy,cnl
>>>> n=noddy.noddy()
>>>> m=cnl.magic()
>>>> m.magicnum
> 1957
>>>> m.magicnum=n
>>>> m.magicnum
> 453311
> cnl (convert noddy long) contains a struct called magic with a single data
> member--magicnum.  The struct initializes magicnum to 1957.  Noddy's all
> have an int value attribute 453311.  I assign a noddy to m.magicnum
> (setattr) and my converter correctly retrieves values and assigns it to the
> magicnum data member.  The problem is indeed occurring when I try to do the
> same thing using pointers (my attempt is in cn.cpp).  I just want to pass an
> int from python to my converter--have the converter cast the int to an HWND
> (pointer).  How does knowing the real type help me in this situation?

As I wrote several messages ago:

> So if you want to convert to HWND, your converter's execute function
> must return a reference to the type that HWND points to
                       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