
29 Dec
2004
29 Dec
'04
2:44 p.m.
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 ); }
I think bind(ReleaseDC, hWnd, _1) should work.
That's what I'd use, too. :-)