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:
@@ -193,6 +193,21 @@ extern LONG APIENTRY _EXPORT
|
|||||||
#define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
|
#define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
|
||||||
#endif
|
#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
|
#if wxUSE_GUI
|
||||||
|
|
||||||
#include <wx/gdicmn.h>
|
#include <wx/gdicmn.h>
|
||||||
|
Reference in New Issue
Block a user