added AutoHANDLE class to close a HANDLE automatically
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34708 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e38bacf884
commit
0cdd4e199e
@ -193,6 +193,21 @@ extern LONG APIENTRY _EXPORT
|
||||
#define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
|
||||
#endif
|
||||
|
||||
// close the handle in the class dtor
|
||||
class AutoHANDLE
|
||||
{
|
||||
public:
|
||||
wxEXPLICIT AutoHANDLE(HANDLE handle) : m_handle(handle) { }
|
||||
|
||||
bool IsOk() const { return m_handle != INVALID_HANDLE_VALUE; }
|
||||
operator HANDLE() const { return m_handle; }
|
||||
|
||||
~AutoHANDLE() { if ( IsOk() ) ::CloseHandle(m_handle); }
|
||||
|
||||
protected:
|
||||
HANDLE m_handle;
|
||||
};
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
||||
#include <wx/gdicmn.h>
|
||||
|
Loading…
Reference in New Issue
Block a user