Sign in to follow this  


Recommended Posts

No. The Standard C++ Library is a cross-platform library, so it would be a little odd to provide a very platform-specific feature like that.

However, I believe you can use boost smart pointers and specify the clean-up function (CloseHandle or DeleteObject, depending on the type of handle). I haven't done this myself, yet, but someone recently corrected me in an earlier post, suggesting you could indeed do this.

Or you could quickly make your own, even. Here's a shoddy example, probably complete with bugs, compiler errors, and so forth, to give you an example:
class auto_handle
explicit auto_handle(HANDLE handle);

operator HANDLE ();

HANDLE mHandle;

auto_handle(const auto_handle& handle);
auto_handle& operator = (const auto_handle& handle);

explicit auto_handle::auto_handle(HANDLE handle) :


auto_handle::operator HANDLE ()
return mHandle;

auto_handle::auto_handle(const auto_handle& handle)

auto_handle& auto_handle::operator = (const auto_handle& handle)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this