[C++-sig] Newbie type conversion question

Bjorn Pettersen BPettersen at NAREX.com
Fri Nov 15 21:42:15 CET 2002


> From: Mark Russell [mailto:mrussell8081 at pacbell.net] 
> 
> 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 the attribute. How do I 
> 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);
	}
};

BOOST_PYTHON_MODULE(nrx)
{
    to_python_converter<HWND,HWND_PyInt>();
    ....
}

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