Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-12-29 09:44:22


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. :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk