
On Wed, Dec 29, 2004 at 04:44:22PM +0200, Peter Dimov wrote:
Jonathan Wakely wrote:
struct DCReleaser { DCReleaser(HWND hwnd) : hwnd(hwnd) {} void operator()(void* p) { ReleaseDC( hwnd, (HDC)p ); } HWND hwnd; };
handle make_dc( HWND hWnd ) { return handle( GetDC( hWnd ), DCReleaser(hWnd) ); }
Yep. Note also that shared_ptr will call the deleter with an HDC, not a void*, so the cast in operator() is not necessary:
void operator()(HDC p) const { ReleaseDC( hwnd, p ); }
Yes, of course it will. Silly me. Thanks, Peter.
I think bind(ReleaseDC, hWnd, _1) should work.
That's what I'd use, too. :-)
Finally, Dirk, if you don't want to use shared_ptr<void> (and casts) everywhere you can include boost/type_traits.hpp and use remove_pointer: typedef shared_ptr<remove_pointer<HDC>::type> dc_handle; typedef shared_ptr<remove_pointer<HWND>::type> wnd_handle; jon -- "It is unbecoming for young men to utter maxims." - Aristotle