[C++-sig] re: Newbie type conversion question

Mark Russell mrussell8081 at pacbell.net
Fri Nov 15 22:58:26 CET 2002


Thanks for your response, this works great going from c++ to python so now
I'm trying to workout how to get from python to c++.  I am wrapping parts of
DirectX8 for a game prototype and am using Mark Hammonds win32ui module
which wraps mfc to create the winapp.  To create a device in DirectX I need
to pass the HWND of my game window.  Win32ui represents this as an int in
python. To create a device I need to wrap a presentation parameters struct
and the target window attribute is an HWND.  So I need to go from python
(int)-->presentation param (HWND) and back.  Actually in this case I just
need to get a converted value to the presentation param struct but this case
comes up frequently in other areas.  Thanks to your help I have a good idea
how to go from c++ to python.  I am looking at implicitly_convertible to go
from python to c++.  Is this the right approach??

Thanks again,


> From: Mark Russell [mailto:mrussell8081 at pacbell.net]=20
> I am wrapping part of DirectX and have run into an number of=20
> variations of the problem described below.
> In struct IntHwnd; HWND is a pointer.  What I pass to the=20
> wrapper from python is an int representation of the pointer=20
> so I need to cast the int from python to a pointer in C++.  I=20
> need to do the reverse when getting the attribute. How do I=20
> accomplish this?

I'm not sure if this works, but it's worth a try:

struct HWND_PyInt {
	static PyObject* convert(const HWND& h) {
		return PyInt_FromLong((long) h);


I'm sort of curious why you need to access the HWND as an int though...

-- bjorn

More information about the Cplusplus-sig mailing list