[C++-sig] Newbie type conversion question

Mark Russell mrussell8081 at pacbell.net
Fri Nov 15 23:51:55 CET 2002

Yes this helps I just want to check my understanding of converters and what
I think I need to do for this case.  From the thread you sent me:

You need to register an lvalue converter for FILE. Something like:

    struct pyfile_to_FILE
        static File& execute(PyObject& o) { return *PyFile_AsFile(&o); }

    // In your module init function

So I need to write a converter that makes the cast from int to HWND based on
the model above.  Now I don't want every int converted so I think I need to
write an HWND object wrapper in python with the int I want converted as an
attribute then my converter will convert these as desired.  Is this correct?
Thanks for the quick replies boost python is a blast to work with.


Mark Russell <mrussell8081 at pacbell.net> writes:

> I am wrapping part of DirectX and have run into an number of variations of
> the problem described below.
> In struct IntHwnd; HWND is a pointer.  What I pass to the wrapper from
> python is an int representation of the pointer so I need to cast the int
> from python to a pointer in C++.  I need to do the reverse when getting
> attribute. How do I accomplish this?
> struct IntHwnd
> {
> 	HWND w;
> };

This seems like a similar problem:


Does that help at all?

More information about the Cplusplus-sig mailing list