From 83c749e394ef1e95b594634634a90aee89e8d8af Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 21 Mar 2022 14:16:37 +0100 Subject: [PATCH] Add SC_HANDLE helper class Signed-off-by: Simon Rozman --- include/WinStd/Win.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/WinStd/Win.h b/include/WinStd/Win.h index 601f3b0c..b0dfe5f1 100644 --- a/include/WinStd/Win.h +++ b/include/WinStd/Win.h @@ -2192,6 +2192,37 @@ namespace winstd } }; + /// + /// SC_HANDLE wrapper class + /// + class sc_handle : public handle + { + WINSTD_HANDLE_IMPL(sc_handle, NULL) + + public: + /// + /// Closes an open object handle. + /// + /// \sa [CloseServiceHandle function](https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-closeservicehandle) + /// + virtual ~sc_handle() + { + if (m_h != invalid) + free_internal(); + } + + protected: + /// + /// Closes an open object handle. + /// + /// \sa [CloseServiceHandle function](https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-closeservicehandle) + /// + void free_internal() noexcept override + { + CloseServiceHandle(m_h); + } + }; + /// @} }