diff --git a/include/WinStd/Base64.h b/include/WinStd/Base64.h index dbef6eda..152e466f 100644 --- a/include/WinStd/Base64.h +++ b/include/WinStd/Base64.h @@ -51,7 +51,7 @@ namespace winstd /// /// Constructs blank encoding session /// - inline base64_enc() : num(0) + inline base64_enc() noexcept : num(0) { buf[0] = 0; buf[1] = 0; @@ -99,7 +99,7 @@ namespace winstd /// /// Resets encoding session /// - inline void clear() + inline void clear() noexcept { num = 0; } @@ -112,7 +112,7 @@ namespace winstd /// /// \returns Maximum number of bytes for the encoded data of `size` length /// - inline size_t enc_size(size_t size) const + inline size_t enc_size(size_t size) const noexcept { return ((num + size + 2)/3)*4; } @@ -182,7 +182,7 @@ namespace winstd /// /// Constructs blank decoding session /// - inline base64_dec() : num(0) + inline base64_dec() noexcept : num(0) { buf[0] = 0; buf[1] = 0; @@ -235,7 +235,7 @@ namespace winstd /// /// Resets decoding session /// - inline void clear() + inline void clear() noexcept { num = 0; } @@ -248,7 +248,7 @@ namespace winstd /// /// \returns Maximum number of bytes for the decoded data of `size` length /// - inline size_t dec_size(size_t size) const + inline size_t dec_size(size_t size) const noexcept { return ((num + size + 3)/4)*3; } diff --git a/include/WinStd/COM.h b/include/WinStd/COM.h index e165cb82..623ba8f2 100644 --- a/include/WinStd/COM.h +++ b/include/WinStd/COM.h @@ -78,16 +78,6 @@ namespace winstd inline com_runtime_error(_In_ error_type num, _In_opt_z_ const char *msg = nullptr) : num_runtime_error(num, msg) { } - - - /// - /// Copies an exception - /// - /// \param[in] other Exception to copy from - /// - inline com_runtime_error(const com_runtime_error &other) : num_runtime_error(other) - { - } }; /// @} @@ -102,7 +92,7 @@ namespace winstd /// /// Default constructor /// - CoTaskMemFree_delete() {} + CoTaskMemFree_delete() noexcept {} /// /// Delete a pointer @@ -223,7 +213,7 @@ namespace winstd /// /// \sa [IUnknown::Release method](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682317.aspx) /// - virtual void free_internal() + void free_internal() noexcept override { m_h->Release(); } @@ -238,7 +228,7 @@ namespace winstd /// /// \return Duplicated object handle /// - virtual handle_type duplicate_internal(_In_ handle_type h) const + handle_type duplicate_internal(_In_ handle_type h) const noexcept override { h->AddRef(); return h; @@ -257,7 +247,7 @@ namespace winstd /// /// Constructs BSTR from OLE string /// - inline bstr(_In_ LPCOLESTR src) + inline bstr(_In_ LPCOLESTR src) noexcept { m_h = SysAllocString(src); } @@ -265,7 +255,7 @@ namespace winstd /// /// Constructs BSTR from OLE string with length /// - inline bstr(_In_ LPCOLESTR src, _In_ UINT len) + inline bstr(_In_ LPCOLESTR src, _In_ UINT len) noexcept { m_h = SysAllocStringLen(src, len); } @@ -274,7 +264,7 @@ namespace winstd /// Constructs BSTR from std::basic_string /// template - inline bstr(_In_ const std::basic_string &src) + inline bstr(_In_ const std::basic_string &src) noexcept { m_h = SysAllocStringLen(src.c_str(), (UINT)src.length()); } @@ -291,7 +281,7 @@ namespace winstd /// /// \sa [SysStringLen function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221240.aspx) /// - inline UINT length() const + inline UINT length() const noexcept { return SysStringLen(m_h); } @@ -302,7 +292,7 @@ namespace winstd /// /// \sa [SysFreeString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221481.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; /// /// Duplicates the string @@ -313,20 +303,22 @@ namespace winstd /// /// \sa [SysAllocString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221458.aspx) /// - virtual handle_type duplicate_internal(_In_ handle_type h) const; + handle_type duplicate_internal(_In_ handle_type h) const noexcept override; }; /// /// VARIANT struct wrapper /// + #pragma warning(push) + #pragma warning(disable: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. class WINSTD_API variant : public VARIANT { public: /// /// Constructs blank VARIANT /// - inline variant() + inline variant() noexcept { VariantInit(this); } @@ -337,7 +329,7 @@ namespace winstd inline variant(_In_ const VARIANT& varSrc) { vt = VT_EMPTY; - HRESULT hr = VariantCopy(this, &varSrc); + const HRESULT hr = VariantCopy(this, &varSrc); if (FAILED(hr)) throw winstd::com_runtime_error(hr, "VariantCopy failed."); } @@ -346,7 +338,7 @@ namespace winstd /// Moves VARIANT from another /// #pragma warning(suppress: 26495) // vt member is initialized as a result of memcpy() - inline variant(_Inout_ VARIANT&& varSrc) + inline variant(_Inout_ VARIANT&& varSrc) noexcept { memcpy(this, &varSrc, sizeof(VARIANT)); varSrc.vt = VT_EMPTY; @@ -355,7 +347,7 @@ namespace winstd /// /// Constructs VARIANT from bool /// - inline variant(_In_ bool bSrc) + inline variant(_In_ bool bSrc) noexcept { vt = VT_BOOL; boolVal = bSrc ? VARIANT_TRUE : VARIANT_FALSE; @@ -364,7 +356,7 @@ namespace winstd /// /// Constructs VARIANT from character /// - inline variant(_In_ char cSrc) + inline variant(_In_ char cSrc) noexcept { vt = VT_I1; cVal = cSrc; @@ -373,7 +365,7 @@ namespace winstd /// /// Constructs VARIANT from byte /// - inline variant(_In_ unsigned char nSrc) + inline variant(_In_ unsigned char nSrc) noexcept { vt = VT_UI1; bVal = nSrc; @@ -382,7 +374,7 @@ namespace winstd /// /// Constructs VARIANT from short /// - inline variant(_In_ short nSrc) + inline variant(_In_ short nSrc) noexcept { vt = VT_I2; iVal = nSrc; @@ -391,7 +383,7 @@ namespace winstd /// /// Constructs VARIANT from unsigned short /// - inline variant(_In_ unsigned short nSrc) + inline variant(_In_ unsigned short nSrc) noexcept { vt = VT_UI2; uiVal = nSrc; @@ -400,7 +392,7 @@ namespace winstd /// /// Constructs VARIANT from integer /// - inline variant(_In_ int nSrc, _In_ VARTYPE vtSrc = VT_I4) + inline variant(_In_ int nSrc, _In_ VARTYPE vtSrc = VT_I4) noexcept { assert(vtSrc == VT_I4 || vtSrc == VT_INT); vt = vtSrc; @@ -410,7 +402,7 @@ namespace winstd /// /// Constructs VARIANT from unsigned integer /// - inline variant(_In_ unsigned int nSrc, _In_ VARTYPE vtSrc = VT_UI4) + inline variant(_In_ unsigned int nSrc, _In_ VARTYPE vtSrc = VT_UI4) noexcept { assert(vtSrc == VT_UI4 || vtSrc == VT_UINT); vt = vtSrc; @@ -420,7 +412,7 @@ namespace winstd /// /// Constructs VARIANT from long /// - inline variant(_In_ long nSrc, _In_ VARTYPE vtSrc = VT_I4) + inline variant(_In_ long nSrc, _In_ VARTYPE vtSrc = VT_I4) noexcept { assert(vtSrc == VT_I4 || vtSrc == VT_ERROR); vt = vtSrc; @@ -430,7 +422,7 @@ namespace winstd /// /// Constructs VARIANT from unsigned long /// - inline variant(_In_ unsigned long nSrc) + inline variant(_In_ unsigned long nSrc) noexcept { vt = VT_UI4; ulVal = nSrc; @@ -439,7 +431,7 @@ namespace winstd /// /// Constructs VARIANT from float /// - inline variant(_In_ float fltSrc) + inline variant(_In_ float fltSrc) noexcept { vt = VT_R4; fltVal = fltSrc; @@ -448,7 +440,7 @@ namespace winstd /// /// Constructs VARIANT from double or variant date /// - inline variant(_In_ double dblSrc, _In_ VARTYPE vtSrc = VT_R8) + inline variant(_In_ double dblSrc, _In_ VARTYPE vtSrc = VT_R8) noexcept { assert(vtSrc == VT_R8 || vtSrc == VT_DATE); vt = vtSrc; @@ -458,7 +450,7 @@ namespace winstd /// /// Constructs VARIANT from 64-bit integer /// - inline variant(_In_ long long nSrc) + inline variant(_In_ long long nSrc) noexcept { vt = VT_I8; llVal = nSrc; @@ -467,7 +459,7 @@ namespace winstd /// /// Constructs VARIANT from unsigned integer /// - inline variant(_In_ unsigned long long nSrc) + inline variant(_In_ unsigned long long nSrc) noexcept { vt = VT_UI8; ullVal = nSrc; @@ -476,7 +468,7 @@ namespace winstd /// /// Constructs VARIANT from CY (64-bit integer) /// - inline variant(_In_ CY cySrc) + inline variant(_In_ CY cySrc) noexcept { vt = VT_CY; cyVal.Hi = cySrc.Hi; @@ -486,7 +478,7 @@ namespace winstd /// /// Constructs VARIANT from OLE string /// - inline variant(_In_z_ LPCOLESTR lpszSrc) + inline variant(_In_z_ LPCOLESTR lpszSrc) noexcept { vt = VT_EMPTY; *this = lpszSrc; @@ -495,7 +487,7 @@ namespace winstd /// /// Constructs VARIANT from BSTR /// - inline variant(_In_z_ BSTR bstr) + inline variant(_In_z_ BSTR bstr) noexcept { vt = VT_EMPTY; *this = bstr; @@ -533,11 +525,11 @@ namespace winstd assert(pSrc != NULL); LPSAFEARRAY pCopy; - HRESULT hr = SafeArrayCopy((LPSAFEARRAY)pSrc, &pCopy); + const HRESULT hr = SafeArrayCopy(const_cast(pSrc), &pCopy); if (FAILED(hr)) throw winstd::com_runtime_error(hr, "SafeArrayCopy failed."); - SafeArrayGetVartype((LPSAFEARRAY)pSrc, &vt); + SafeArrayGetVartype(const_cast(pSrc), &vt); vt |= VT_ARRAY; parray = pCopy; } @@ -553,7 +545,7 @@ namespace winstd inline variant& operator=(_In_ const VARIANT& varSrc) { if (this != &varSrc) { - HRESULT hr = VariantCopy(this, &varSrc); + const HRESULT hr = VariantCopy(this, &varSrc); if (FAILED(hr)) throw winstd::com_runtime_error(hr, "VariantCopy failed."); } @@ -563,7 +555,7 @@ namespace winstd /// /// Moves from another VARIANT /// - inline variant& operator=(_Inout_ VARIANT&& varSrc) + inline variant& operator=(_Inout_ VARIANT&& varSrc) noexcept { if (this != &varSrc) { VariantClear(this); @@ -576,7 +568,7 @@ namespace winstd /// /// Copy from bool value /// - inline variant& operator=(_In_ bool bSrc) + inline variant& operator=(_In_ bool bSrc) noexcept { if (vt != VT_BOOL) { VariantClear(this); @@ -589,7 +581,7 @@ namespace winstd /// /// Copy from char value /// - inline variant& operator=(_In_ char cSrc) + inline variant& operator=(_In_ char cSrc) noexcept { if (vt != VT_I1) { VariantClear(this); @@ -602,7 +594,7 @@ namespace winstd /// /// Copy from unsigned char value /// - inline variant& operator=(_In_ unsigned char nSrc) + inline variant& operator=(_In_ unsigned char nSrc) noexcept { if (vt != VT_UI1) { VariantClear(this); @@ -615,7 +607,7 @@ namespace winstd /// /// Copy from short value /// - inline variant& operator=(_In_ short nSrc) + inline variant& operator=(_In_ short nSrc) noexcept { if (vt != VT_I2) { VariantClear(this); @@ -628,7 +620,7 @@ namespace winstd /// /// Copy from unsigned short value /// - inline variant& operator=(_In_ unsigned short nSrc) + inline variant& operator=(_In_ unsigned short nSrc) noexcept { if (vt != VT_UI2) { VariantClear(this); @@ -641,7 +633,7 @@ namespace winstd /// /// Copy from int value /// - inline variant& operator=(_In_ int nSrc) + inline variant& operator=(_In_ int nSrc) noexcept { if (vt != VT_I4) { VariantClear(this); @@ -654,7 +646,7 @@ namespace winstd /// /// Copy from unsigned int value /// - inline variant& operator=(_In_ unsigned int nSrc) + inline variant& operator=(_In_ unsigned int nSrc) noexcept { if (vt != VT_UI4) { VariantClear(this); @@ -667,7 +659,7 @@ namespace winstd /// /// Copy from long value /// - inline variant& operator=(_In_ long nSrc) + inline variant& operator=(_In_ long nSrc) noexcept { if (vt != VT_I4) { VariantClear(this); @@ -680,7 +672,7 @@ namespace winstd /// /// Copy from unsigned long value /// - inline variant& operator=(_In_ unsigned long nSrc) + inline variant& operator=(_In_ unsigned long nSrc) noexcept { if (vt != VT_UI4) { VariantClear(this); @@ -694,7 +686,7 @@ namespace winstd /// /// Copy from long long value /// - inline variant& operator=(_In_ long long nSrc) + inline variant& operator=(_In_ long long nSrc) noexcept { if (vt != VT_I8) { VariantClear(this); @@ -707,7 +699,7 @@ namespace winstd /// /// Copy from unsigned long long value /// - inline variant& operator=(_In_ unsigned long long nSrc) + inline variant& operator=(_In_ unsigned long long nSrc) noexcept { if (vt != VT_UI8) { VariantClear(this); @@ -721,7 +713,7 @@ namespace winstd /// /// Copy from float value /// - inline variant& operator=(_In_ float fltSrc) + inline variant& operator=(_In_ float fltSrc) noexcept { if (vt != VT_R4) { VariantClear(this); @@ -734,7 +726,7 @@ namespace winstd /// /// Copy from double value /// - inline variant& operator=(_In_ double dblSrc) + inline variant& operator=(_In_ double dblSrc) noexcept { if (vt != VT_R8) { VariantClear(this); @@ -747,7 +739,7 @@ namespace winstd /// /// Copy from CY value /// - inline variant& operator=(_In_ CY cySrc) + inline variant& operator=(_In_ CY cySrc) noexcept { if (vt != VT_CY) { VariantClear(this); @@ -761,7 +753,7 @@ namespace winstd /// /// Copy from OLE string value /// - inline variant& operator=(_In_z_ LPCOLESTR lpszSrc) + inline variant& operator=(_In_z_ LPCOLESTR lpszSrc) noexcept { VariantClear(this); vt = VT_BSTR; @@ -798,7 +790,7 @@ namespace winstd /// /// Copy from unsigned char reference /// - inline variant& operator=(_In_ unsigned char* pbSrc) + inline variant& operator=(_In_ unsigned char* pbSrc) noexcept { if (vt != (VT_UI1|VT_BYREF)) { VariantClear(this); @@ -811,7 +803,7 @@ namespace winstd /// /// Copy from short reference /// - inline variant& operator=(_In_ short* pnSrc) + inline variant& operator=(_In_ short* pnSrc) noexcept { if (vt != (VT_I2|VT_BYREF)) { VariantClear(this); @@ -824,7 +816,7 @@ namespace winstd /// /// Copy from unsigned short reference /// - inline variant& operator=(_In_ unsigned short* pnSrc) + inline variant& operator=(_In_ unsigned short* pnSrc) noexcept { if (vt != (VT_UI2|VT_BYREF)) { VariantClear(this); @@ -837,7 +829,7 @@ namespace winstd /// /// Copy from int reference /// - inline variant& operator=(_In_ int* pnSrc) + inline variant& operator=(_In_ int* pnSrc) noexcept { if (vt != (VT_I4|VT_BYREF)) { VariantClear(this); @@ -850,7 +842,7 @@ namespace winstd /// /// Copy from unsigned int reference /// - inline variant& operator=(_In_ unsigned int* pnSrc) + inline variant& operator=(_In_ unsigned int* pnSrc) noexcept { if (vt != (VT_UI4|VT_BYREF)) { VariantClear(this); @@ -863,7 +855,7 @@ namespace winstd /// /// Copy from long reference /// - inline variant& operator=(_In_ long* pnSrc) + inline variant& operator=(_In_ long* pnSrc) noexcept { if (vt != (VT_I4|VT_BYREF)) { VariantClear(this); @@ -876,7 +868,7 @@ namespace winstd /// /// Copy from unsigned long reference /// - inline variant& operator=(_In_ unsigned long* pnSrc) + inline variant& operator=(_In_ unsigned long* pnSrc) noexcept { if (vt != (VT_UI4|VT_BYREF)) { VariantClear(this); @@ -889,7 +881,7 @@ namespace winstd /// /// Copy from long long reference /// - inline variant& operator=(_In_ long long* pnSrc) + inline variant& operator=(_In_ long long* pnSrc) noexcept { if (vt != (VT_I8|VT_BYREF)) { VariantClear(this); @@ -902,7 +894,7 @@ namespace winstd /// /// Copy from unsigned long long reference /// - inline variant& operator=(_In_ unsigned long long* pnSrc) + inline variant& operator=(_In_ unsigned long long* pnSrc) noexcept { if (vt != (VT_UI8|VT_BYREF)) { VariantClear(this); @@ -915,7 +907,7 @@ namespace winstd /// /// Copy from float reference /// - inline variant& operator=(_In_ float* pfSrc) + inline variant& operator=(_In_ float* pfSrc) noexcept { if (vt != (VT_R4|VT_BYREF)) { VariantClear(this); @@ -928,7 +920,7 @@ namespace winstd /// /// Copy from double reference /// - inline variant& operator=(_In_ double* pfSrc) + inline variant& operator=(_In_ double* pfSrc) noexcept { if (vt != (VT_R8|VT_BYREF)) { VariantClear(this); @@ -941,15 +933,15 @@ namespace winstd /// /// Copy from SAFEARRAY /// - inline variant& operator=(_In_ const SAFEARRAY *pSrc) + inline variant& operator=(_In_ const SAFEARRAY *pSrc) noexcept { assert(pSrc != NULL); VariantClear(this); LPSAFEARRAY pCopy; - HRESULT hr = SafeArrayCopy((LPSAFEARRAY)pSrc, &pCopy); + const HRESULT hr = SafeArrayCopy(const_cast(pSrc), &pCopy); if (SUCCEEDED(hr)) { - SafeArrayGetVartype((LPSAFEARRAY)pSrc, &vt); + SafeArrayGetVartype(const_cast(pSrc), &vt); vt |= VT_ARRAY; parray = pCopy; } else @@ -967,7 +959,7 @@ namespace winstd /// - Non zero when variant is equal to \p varSrc; /// - Zero otherwise. /// - inline bool operator==(_In_ const VARIANT& varSrc) const + inline bool operator==(_In_ const VARIANT& varSrc) const noexcept { if (vt == VT_NULL && varSrc.vt == VT_NULL) return true; if (vt != varSrc.vt) return false; @@ -982,7 +974,7 @@ namespace winstd /// - Non zero when variant is not equal to \p varSrc; /// - Zero otherwise. /// - inline bool operator!=(_In_ const VARIANT& varSrc) const + inline bool operator!=(_In_ const VARIANT& varSrc) const noexcept { return !operator==(varSrc); } @@ -995,7 +987,7 @@ namespace winstd /// - Non zero when variant is less than \p varSrc; /// - Zero otherwise. /// - inline bool operator<(_In_ const VARIANT& varSrc) const + inline bool operator<(_In_ const VARIANT& varSrc) const noexcept { if (vt == VT_NULL && varSrc.vt == VT_NULL) return false; return compare(static_cast(*this), varSrc, LOCALE_USER_DEFAULT, 0)== static_cast(VARCMP_LT); @@ -1009,7 +1001,7 @@ namespace winstd /// - Non zero when variant is greater than \p varSrc; /// - Zero otherwise. /// - inline bool operator>(_In_ const VARIANT& varSrc) const + inline bool operator>(_In_ const VARIANT& varSrc) const noexcept { if (vt == VT_NULL && varSrc.vt == VT_NULL) return false; return compare(static_cast(*this), varSrc, LOCALE_USER_DEFAULT, 0)== static_cast(VARCMP_GT); @@ -1023,7 +1015,7 @@ namespace winstd /// - Non zero when variant is less than or equal to \p varSrc; /// - Zero otherwise. /// - inline bool operator<=(_In_ const VARIANT& varSrc) const + inline bool operator<=(_In_ const VARIANT& varSrc) const noexcept { return !operator>(varSrc); } @@ -1036,7 +1028,7 @@ namespace winstd /// - Non zero when variant is greater than or equal to \p varSrc; /// - Zero otherwise. /// - inline bool operator>=(_In_ const VARIANT& varSrc) const + inline bool operator>=(_In_ const VARIANT& varSrc) const noexcept { return !operator<(varSrc); } @@ -1046,14 +1038,14 @@ namespace winstd /// /// \sa [VariantChangeType function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221258.aspx) /// - inline HRESULT change_type(_In_ VARTYPE _vt, _In_opt_ USHORT wFlags = 0) + inline HRESULT change_type(_In_ VARTYPE _vt, _In_opt_ USHORT wFlags = 0) noexcept { return VariantChangeType(this, this, wFlags, _vt); } private: /// \cond internal - inline HRESULT compare(_In_ const VARIANT &varLeft, _In_ const VARIANT &varRight, _In_ LCID lcid, _In_ ULONG dwFlags) const + inline HRESULT compare(_In_ const VARIANT &varLeft, _In_ const VARIANT &varRight, _In_ LCID lcid, _In_ ULONG dwFlags) const noexcept { switch(vt) { case VT_I1: return varLeft.cVal == varRight.cVal ? VARCMP_EQ : varLeft.cVal > varRight.cVal ? VARCMP_GT : VARCMP_LT; @@ -1065,6 +1057,7 @@ namespace winstd } /// \endcond }; + #pragma warning(pop) /// @@ -1072,13 +1065,16 @@ namespace winstd /// class WINSTD_API com_initializer { + WINSTD_NONCOPYABLE(com_initializer) + WINSTD_NONMOVABLE(com_initializer) + public: /// /// Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA). /// /// \sa [CoInitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms678543.aspx) /// - inline com_initializer(_In_opt_ LPVOID pvReserved) + inline com_initializer(_In_opt_ LPVOID pvReserved) noexcept { m_result = CoInitialize(pvReserved); } @@ -1089,7 +1085,7 @@ namespace winstd /// /// \sa [CoInitializeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms695279.aspx) /// - inline com_initializer(_In_opt_ LPVOID pvReserved, _In_ DWORD dwCoInit) + inline com_initializer(_In_opt_ LPVOID pvReserved, _In_ DWORD dwCoInit) noexcept { m_result = CoInitializeEx(pvReserved, dwCoInit); } @@ -1108,7 +1104,7 @@ namespace winstd /// /// \sa [CoInitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms678543.aspx) /// - inline HRESULT status() const + inline HRESULT status() const noexcept { return m_result; } diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index b3e0902c..c1831e2a 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -105,16 +105,16 @@ /// #define WINSTD_NONCOPYABLE(C) \ private: \ - inline C (_In_ const C &h); \ - inline C& operator=(_In_ const C &h); + inline C (_In_ const C &h) noexcept; \ + inline C& operator=(_In_ const C &h) noexcept; /// /// Declares a class as non-movable /// #define WINSTD_NONMOVABLE(C) \ private: \ - inline C (_Inout_ C &&h); \ - inline C& operator=(_Inout_ C &&h); + inline C (_Inout_ C &&h) noexcept; \ + inline C& operator=(_Inout_ C &&h) noexcept; /// @} @@ -163,10 +163,10 @@ private: \ /// #define HANDLE_IMPL(C, INVAL) \ public: \ - inline C ( ) { } \ - inline C (_In_opt_ handle_type h) : handle( h ) { } \ + inline C ( ) noexcept { } \ + inline C (_In_opt_ handle_type h) noexcept : handle( h ) { } \ inline C (_Inout_ C &&h) noexcept : handle(std::move(h)) { } \ - inline C& operator=(_In_opt_ handle_type h) { handle::operator=( h ); return *this; } \ + inline C& operator=(_In_opt_ handle_type h) noexcept { handle::operator=( h ); return *this; } \ inline C& operator=(_Inout_ C &&h) noexcept { handle::operator=(std::move(h)); return *this; } \ WINSTD_NONCOPYABLE(C) @@ -175,12 +175,12 @@ WINSTD_NONCOPYABLE(C) /// #define DPLHANDLE_IMPL(C, INVAL) \ public: \ - inline C ( ) { } \ - inline C (_In_opt_ handle_type h) : dplhandle( h ) { } \ - inline C (_In_ const C &h) : dplhandle(duplicate_internal(h.m_h)) { } \ + inline C ( ) noexcept { } \ + inline C (_In_opt_ handle_type h) noexcept : dplhandle( h ) { } \ + inline C (_In_ const C &h) noexcept : dplhandle(duplicate_internal(h.m_h)) { } \ inline C (_Inout_ C &&h) noexcept : dplhandle(std::move (h )) { } \ - inline C& operator=(_In_opt_ handle_type h) { dplhandle::operator=( h ); return *this; } \ - inline C& operator=(_In_ const C &h) { dplhandle::operator=( h ); return *this; } \ + inline C& operator=(_In_opt_ handle_type h) noexcept { dplhandle::operator=( h ); return *this; } \ + inline C& operator=(_In_ const C &h) noexcept { dplhandle::operator=( h ); return *this; } \ inline C& operator=(_Inout_ C &&h) noexcept { dplhandle::operator=(std::move(h)); return *this; } \ private: @@ -234,7 +234,7 @@ namespace winstd /// /// \returns A helper wrapper class to handle returning a reference to the pointer /// - template inline ref_unique_ptr<_Ty, _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner); + template inline ref_unique_ptr<_Ty, _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) noexcept; /// /// Helper function template for returning pointers to std::unique_ptr @@ -244,7 +244,7 @@ namespace winstd /// /// \returns A helper wrapper class to handle returning a reference to the pointer /// - template inline ref_unique_ptr<_Ty[], _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner); + template inline ref_unique_ptr<_Ty[], _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) noexcept; /// @} @@ -374,7 +374,7 @@ inline int vsnprintf(_Out_z_cap_(capacity) char *str, _In_ size_t capacity, _In_ /// /// \returns Number of characters in result. /// -inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _In_z_ _Printf_format_string_ const wchar_t *format, _In_ va_list arg); +inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _In_z_ _Printf_format_string_ const wchar_t *format, _In_ va_list arg) noexcept; /// /// Formats string using `printf()`. @@ -491,12 +491,12 @@ namespace winstd /// /// Default construct /// - LocalFree_delete() {} + LocalFree_delete() noexcept {} /// /// Delete a pointer /// - void operator()(_Frees_ptr_opt_ _Ty *_Ptr) const + void operator()(_Frees_ptr_opt_ _Ty *_Ptr) const noexcept { LocalFree(_Ptr); } @@ -582,6 +582,8 @@ namespace winstd /// Helper class for returning pointers to std::unique_ptr /// (specialization for arrays) /// + #pragma warning(push) + #pragma warning(disable: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. template class ref_unique_ptr<_Ty[], _Dx> { @@ -591,11 +593,28 @@ namespace winstd /// /// \param[inout] owner Object to attach helper to /// - inline ref_unique_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) : + inline ref_unique_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) noexcept : m_own(owner), m_ptr(owner.release()) {} + /// + /// Takes ownership of the pointer + /// + /// \param[inout] owner Object to attach helper to + /// + /// \returns Reference to this object + /// + inline ref_unique_ptr& operator=(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) noexcept + { + if (this != &other) { + m_own = owner; + m_ptr = owner.release(); + } + + return *this; + } + /// /// Moves object /// @@ -608,10 +627,28 @@ namespace winstd other.m_ptr = nullptr; } + /// + /// Moves object + /// + /// \param[inout] other Source object + /// + /// \returns Reference to this object + /// + inline ref_unique_ptr& operator=(_Inout_ ref_unique_ptr<_Ty[], _Dx> &&other) + { + if (this != &other) { + m_own = other.m_own; + m_ptr = other.m_ptr; + other.m_ptr = nullptr; + } + + return *this; + } + /// /// Returns ownership of the pointer /// - inline ~ref_unique_ptr() + virtual ~ref_unique_ptr() { if (m_ptr != nullptr) m_own.reset(m_ptr); @@ -622,7 +659,7 @@ namespace winstd /// /// \return Pointer to the pointer /// - inline operator typename _Ty**() + inline operator typename _Ty**() noexcept { return &m_ptr; } @@ -641,15 +678,16 @@ namespace winstd std::unique_ptr<_Ty[], _Dx> &m_own; ///< Original owner of the pointer _Ty *m_ptr; ///< Pointer }; + #pragma warning(pop) template - inline ref_unique_ptr<_Ty, _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) + inline ref_unique_ptr<_Ty, _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) noexcept { return ref_unique_ptr<_Ty, _Dx>(owner); } template - inline ref_unique_ptr<_Ty[], _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) + inline ref_unique_ptr<_Ty[], _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) noexcept { return ref_unique_ptr<_Ty[], _Dx>(owner); } @@ -682,7 +720,7 @@ namespace winstd /// /// Initializes a new class instance with the object handle set to INVAL. /// - inline handle() : m_h(invalid) + inline handle() noexcept : m_h(invalid) { } @@ -691,7 +729,7 @@ namespace winstd /// /// \param[in] h Initial object handle value /// - inline handle(_In_opt_ handle_type h) : m_h(h) + inline handle(_In_opt_ handle_type h) noexcept : m_h(h) { } @@ -709,8 +747,8 @@ namespace winstd private: // This class is noncopyable. - handle(_In_ const handle &h); - handle& operator=(_In_ const handle &h); + inline handle(_In_ const handle &h) noexcept {}; + inline handle& operator=(_In_ const handle &h) noexcept {}; public: /// @@ -718,7 +756,7 @@ namespace winstd /// /// \param[in] h Object handle value /// - inline handle& operator=(_In_opt_ handle_type h) + inline handle& operator=(_In_opt_ handle_type h) noexcept { attach(h); return *this; @@ -729,6 +767,7 @@ namespace winstd /// /// \param[inout] h A rvalue reference of another object /// + #pragma warning(suppress: 26432) // Move constructor is also present, but not detected by code analysis somehow. inline handle& operator=(_Inout_ handle &&h) noexcept { if (this != std::addressof(h)) { @@ -880,7 +919,7 @@ namespace winstd /// /// \param[in] h New object handle /// - inline void attach(_In_opt_ handle_type h) + inline void attach(_In_opt_ handle_type h) noexcept { if (m_h != invalid) free_internal(); @@ -916,7 +955,7 @@ namespace winstd /// /// Abstract member function that must be implemented by child classes to do the actual object destruction. /// - virtual void free_internal() = 0; + virtual void free_internal() noexcept = 0; protected: handle_type m_h; ///< Object handle @@ -937,7 +976,7 @@ namespace winstd /// /// Initializes a new class instance with the object handle set to INVAL. /// - inline dplhandle() + inline dplhandle() noexcept { } @@ -946,7 +985,7 @@ namespace winstd /// /// \param[in] h Initial object handle value /// - inline dplhandle(_In_opt_ handle_type h) : handle(h) + inline dplhandle(_In_opt_ handle_type h) noexcept : handle(h) { } @@ -955,7 +994,7 @@ namespace winstd /// /// \param[inout] h A reference of another object /// - inline dplhandle(_In_ const dplhandle &h) : handle(internal_duplicate(h.m_h)) + inline dplhandle(_In_ const dplhandle &h) noexcept : handle(duplicate_internal(h.m_h)) { } @@ -973,7 +1012,7 @@ namespace winstd /// /// \param[in] h Object handle value /// - inline dplhandle& operator=(_In_opt_ handle_type h) + inline dplhandle& operator=(_In_opt_ handle_type h) noexcept { handle::operator=(h); return *this; @@ -984,7 +1023,7 @@ namespace winstd /// /// \param[in] h Object /// - inline dplhandle& operator=(_In_ const dplhandle &h) + inline dplhandle& operator=(_In_ const dplhandle &h) noexcept { if (this != std::addressof(h)) { if (h.m_h != invalid) { @@ -1011,6 +1050,7 @@ namespace winstd /// /// \param[inout] h A rvalue reference of another object /// + #pragma warning(disable: 26432) // Move constructor is also present, but not detected by code analysis somehow. inline dplhandle& operator=(_Inout_ dplhandle &&h) noexcept { handle::operator=(std::move(h)); @@ -1052,7 +1092,7 @@ namespace winstd /// /// \return Duplicated object handle /// - virtual handle_type duplicate_internal(_In_ handle_type h) const = 0; + virtual handle_type duplicate_internal(_In_ handle_type h) const noexcept = 0; }; /// @} @@ -1505,34 +1545,6 @@ namespace winstd } - /// - /// Copies an exception - /// - /// \param[in] other Exception to copy from - /// - inline num_runtime_error(const num_runtime_error<_Tn> &other) : - m_num(other.m_num), - runtime_error(other) - { - } - - - /// - /// Copies an exception - /// - /// \param[in] other Exception to copy from - /// - inline num_runtime_error& operator=(const num_runtime_error<_Tn> &other) - { - if (this != addressof(other)) { - *(runtime_error*)this = other; - m_num = other.m_num; - } - - return *this; - } - - /// /// Returns the Windows error number /// @@ -1594,16 +1606,6 @@ namespace winstd } - /// - /// Copies an exception - /// - /// \param[in] other Exception to copy from - /// - inline win_runtime_error(const win_runtime_error &other) : num_runtime_error(other) - { - } - - /// /// Returns a user-readable Windows error message /// @@ -1914,7 +1916,7 @@ namespace winstd /// /// Construct default allocator /// - inline sanitizing_allocator() : _Mybase() + inline sanitizing_allocator() noexcept : _Mybase() { } @@ -1931,7 +1933,7 @@ namespace winstd /// Construct from a related allocator /// template - inline sanitizing_allocator(_In_ const sanitizing_allocator<_Other> &_Othr) : _Mybase(_Othr) + inline sanitizing_allocator(_In_ const sanitizing_allocator<_Other> &_Othr) noexcept : _Mybase(_Othr) { } @@ -1939,7 +1941,7 @@ namespace winstd /// /// Deallocate object at _Ptr sanitizing its content first /// - inline void deallocate(_In_ pointer _Ptr, _In_ size_type _Size) + void deallocate(_In_ pointer _Ptr, _In_ size_type _Size) { // Sanitize then free. SecureZeroMemory(_Ptr, _Size); @@ -1996,7 +1998,7 @@ inline int vsnprintf(_Out_z_cap_(capacity) char *str, _In_ size_t capacity, _In_ #endif -inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _In_z_ _Printf_format_string_ const wchar_t *format, _In_ va_list arg) +inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _In_z_ _Printf_format_string_ const wchar_t *format, _In_ va_list arg) noexcept { return _vsnwprintf(str, capacity, format, arg); } @@ -2015,7 +2017,7 @@ inline int vsprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ } else { for (size_t capacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; capacity *= 2) { // Allocate on heap and retry. - std::unique_ptr<_Elem[]> buf_dyn(new _Elem[capacity]); + auto buf_dyn = std::make_unique<_Elem[]>(capacity); count = vsnprintf(buf_dyn.get(), capacity - 1, format, arg); if (count >= 0) { str.assign(buf_dyn.get(), count); @@ -2035,7 +2037,7 @@ inline int sprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _ { va_list arg; va_start(arg, format); - int res = vsprintf(str, format, arg); + const int res = vsprintf(str, format, arg); va_end(arg); return res; } diff --git a/include/WinStd/Cred.h b/include/WinStd/Cred.h index df62fd45..00865142 100644 --- a/include/WinStd/Cred.h +++ b/include/WinStd/Cred.h @@ -44,7 +44,7 @@ namespace winstd /// /// \sa [CredEnumerate function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374794.aspx) /// -inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr > &cCredentials); +inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr > &cCredentials) noexcept; /// @copydoc CredProtectW() template inline BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType); @@ -122,7 +122,7 @@ namespace winstd /// /// \sa [CredFree function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374796.aspx) /// - void operator()(_Ty *_Ptr) const + void operator()(_Ty *_Ptr) const noexcept { CredFree(_Ptr); } @@ -143,7 +143,7 @@ namespace winstd } -inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr > &cCredentials) +inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr > &cCredentials) noexcept { PCREDENTIAL *pCredentials; if (CredEnumerate(Filter, Flags, Count, &pCredentials)) { diff --git a/include/WinStd/Crypt.h b/include/WinStd/Crypt.h index a2d5c180..e7926d28 100644 --- a/include/WinStd/Crypt.h +++ b/include/WinStd/Crypt.h @@ -141,7 +141,7 @@ namespace winstd /// /// \sa [CertCreateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376033.aspx) /// - inline bool create(_In_ DWORD dwCertEncodingType, _In_ LPCBYTE pbCertEncoded, _In_ DWORD cbCertEncoded) + inline bool create(_In_ DWORD dwCertEncodingType, _In_ LPCBYTE pbCertEncoded, _In_ DWORD cbCertEncoded) noexcept { handle_type h = CertCreateCertificateContext(dwCertEncodingType, pbCertEncoded, cbCertEncoded); if (h != invalid) { @@ -159,7 +159,7 @@ namespace winstd /// - Non zero when certificate is equal to \p other; /// - Zero otherwise. /// - inline bool operator==(_In_ const handle_type &other) const + inline bool operator==(_In_ const handle_type &other) const noexcept { // TODO: [Crypto] Make constant time. return @@ -175,7 +175,7 @@ namespace winstd /// - Non zero when certificate is not equal to \p other; /// - Zero otherwise. /// - inline bool operator!=(_In_ const handle_type &other) const + inline bool operator!=(_In_ const handle_type &other) const noexcept { return !operator==(other); } @@ -188,10 +188,10 @@ namespace winstd /// - Non zero when certificate is less than \p other; /// - Zero otherwise. /// - inline bool operator<(_In_ const handle_type &other) const + inline bool operator<(_In_ const handle_type &other) const noexcept { // TODO: [Crypto] Make constant time. - int r = memcmp(m_h->pbCertEncoded, other->pbCertEncoded, std::min(m_h->cbCertEncoded, other->cbCertEncoded)); + const int r = memcmp(m_h->pbCertEncoded, other->pbCertEncoded, std::min(m_h->cbCertEncoded, other->cbCertEncoded)); return r < 0 || r == 0 && m_h->cbCertEncoded < other->cbCertEncoded; } @@ -203,10 +203,10 @@ namespace winstd /// - Non zero when certificate is greater than \p other; /// - Zero otherwise. /// - inline bool operator>(_In_ const handle_type &other) const + inline bool operator>(_In_ const handle_type &other) const noexcept { // TODO: [Crypto] Make constant time. - int r = memcmp(m_h->pbCertEncoded, other->pbCertEncoded, std::min(m_h->cbCertEncoded, other->cbCertEncoded)); + const int r = memcmp(m_h->pbCertEncoded, other->pbCertEncoded, std::min(m_h->cbCertEncoded, other->cbCertEncoded)); return r > 0 || r == 0 && m_h->cbCertEncoded > other->cbCertEncoded; } @@ -218,7 +218,7 @@ namespace winstd /// - Non zero when certificate is less than \p other; /// - Zero otherwise. /// - inline bool operator<=(_In_ const handle_type &other) const + inline bool operator<=(_In_ const handle_type &other) const noexcept { return !operator>(other); } @@ -231,7 +231,7 @@ namespace winstd /// - Non zero when certificate is greater than \p other; /// - Zero otherwise. /// - inline bool operator>=(_In_ const handle_type &other) const + inline bool operator>=(_In_ const handle_type &other) const noexcept { return !operator<(other); } @@ -242,7 +242,7 @@ namespace winstd /// /// \sa [CertFreeCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; /// /// Duplicates the certificate context. @@ -253,7 +253,7 @@ namespace winstd /// /// \sa [CertDuplicateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045.aspx) /// - virtual handle_type duplicate_internal(_In_ handle_type h) const; + handle_type duplicate_internal(_In_ handle_type h) const noexcept override; }; @@ -281,7 +281,7 @@ namespace winstd /// /// \sa [CertGetCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376078.aspx) /// - inline bool create(_In_opt_ HCERTCHAINENGINE hChainEngine, _In_ PCCERT_CONTEXT pCertContext, _In_opt_ LPFILETIME pTime, _In_opt_ HCERTSTORE hAdditionalStore, _In_ PCERT_CHAIN_PARA pChainPara, _In_ DWORD dwFlags, __reserved LPVOID pvReserved = NULL) + inline bool create(_In_opt_ HCERTCHAINENGINE hChainEngine, _In_ PCCERT_CONTEXT pCertContext, _In_opt_ LPFILETIME pTime, _In_opt_ HCERTSTORE hAdditionalStore, _In_ PCERT_CHAIN_PARA pChainPara, _In_ DWORD dwFlags, __reserved LPVOID pvReserved = NULL) noexcept { handle_type h; if (CertGetCertificateChain(hChainEngine, pCertContext, pTime, hAdditionalStore, pChainPara, dwFlags, pvReserved, &h)) { @@ -297,7 +297,7 @@ namespace winstd /// /// \sa [CertFreeCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; /// /// Duplicates the certificate chain context. @@ -308,7 +308,7 @@ namespace winstd /// /// \sa [CertDuplicateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045.aspx) /// - virtual handle_type duplicate_internal(_In_ handle_type h) const; + handle_type duplicate_internal(_In_ handle_type h) const noexcept override; }; @@ -336,7 +336,7 @@ namespace winstd /// /// \sa [CertOpenStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376559.aspx) /// - inline bool create(_In_ LPCSTR lpszStoreProvider, _In_ DWORD dwEncodingType, _In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_ DWORD dwFlags, _In_opt_ const void *pvPara) + inline bool create(_In_ LPCSTR lpszStoreProvider, _In_ DWORD dwEncodingType, _In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_ DWORD dwFlags, _In_opt_ const void *pvPara) noexcept { handle_type h = CertOpenStore(lpszStoreProvider, dwEncodingType, hCryptProv, dwFlags, pvPara); if (h != invalid) { @@ -355,7 +355,7 @@ namespace winstd /// /// \sa [CertOpenSystemStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376560.aspx) /// - inline bool create(_In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_z_ LPCTSTR szSubsystemProtocol) + inline bool create(_In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_z_ LPCTSTR szSubsystemProtocol) noexcept { handle_type h = CertOpenSystemStore(hCryptProv, szSubsystemProtocol); if (h != invalid) { @@ -371,7 +371,7 @@ namespace winstd /// /// \sa [CertCloseStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -399,7 +399,7 @@ namespace winstd /// /// \sa [CryptAcquireContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886.aspx) /// - inline bool create(_In_opt_z_ LPCTSTR szContainer, _In_opt_z_ LPCTSTR szProvider, _In_ DWORD dwProvType, _In_ DWORD dwFlags = 0) + inline bool create(_In_opt_z_ LPCTSTR szContainer, _In_opt_z_ LPCTSTR szProvider, _In_ DWORD dwProvType, _In_ DWORD dwFlags = 0) noexcept { handle_type h; if (CryptAcquireContext(&h, szContainer, szProvider, dwProvType, dwFlags)) { @@ -415,7 +415,7 @@ namespace winstd /// /// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -443,7 +443,7 @@ namespace winstd /// /// \sa [CryptCreateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908.aspx) /// - inline bool create(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_opt_ HCRYPTKEY hKey = NULL, _In_opt_ DWORD dwFlags = 0) + inline bool create(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_opt_ HCRYPTKEY hKey = NULL, _In_opt_ DWORD dwFlags = 0) noexcept { handle_type h; if (CryptCreateHash(hProv, Algid, hKey, dwFlags, &h)) { @@ -459,7 +459,7 @@ namespace winstd /// /// \sa [CryptDestroyHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; /// /// Duplicates the hash context. @@ -470,7 +470,7 @@ namespace winstd /// /// \sa [CryptDuplicateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379919.aspx) /// - virtual handle_type duplicate_internal(_In_ handle_type h) const; + handle_type duplicate_internal(_In_ handle_type h) const noexcept override; }; @@ -494,7 +494,7 @@ namespace winstd /// /// \sa [CryptGenKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379941.aspx) /// - inline bool generate(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ DWORD dwFlags) + inline bool generate(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ DWORD dwFlags) noexcept { handle_type h; if (CryptGenKey(hProv, Algid, dwFlags, &h)) { @@ -509,7 +509,7 @@ namespace winstd /// /// \sa [CryptImportKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380207.aspx) /// - inline bool import(_In_ HCRYPTPROV hProv, __in_bcount(dwDataLen) LPCBYTE pbData, _In_ DWORD dwDataLen, _In_ HCRYPTKEY hPubKey, _In_ DWORD dwFlags) + inline bool import(_In_ HCRYPTPROV hProv, __in_bcount(dwDataLen) LPCBYTE pbData, _In_ DWORD dwDataLen, _In_ HCRYPTKEY hPubKey, _In_ DWORD dwFlags) noexcept { handle_type h; if (CryptImportKey(hProv, pbData, dwDataLen, hPubKey, dwFlags, &h)) { @@ -524,7 +524,7 @@ namespace winstd /// /// \sa [CryptImportPublicKeyInfo function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380209.aspx) /// - inline bool import_public(_In_ HCRYPTPROV hCryptProv, _In_ DWORD dwCertEncodingType, _In_ PCERT_PUBLIC_KEY_INFO pInfo) + inline bool import_public(_In_ HCRYPTPROV hCryptProv, _In_ DWORD dwCertEncodingType, _In_ PCERT_PUBLIC_KEY_INFO pInfo) noexcept { handle_type h; if (CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo, &h)) { @@ -539,7 +539,7 @@ namespace winstd /// /// \sa [CryptDeriveKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379916.aspx) /// - inline bool derive(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ HCRYPTHASH hBaseData, _In_ DWORD dwFlags) + inline bool derive(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ HCRYPTHASH hBaseData, _In_ DWORD dwFlags) noexcept { handle_type h; if (CryptDeriveKey(hProv, Algid, hBaseData, dwFlags, &h)) { @@ -565,7 +565,7 @@ namespace winstd /// /// \sa [CryptDestroyKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; /// /// Duplicates the key. @@ -576,20 +576,21 @@ namespace winstd /// /// \sa [CryptDuplicateKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379920.aspx) /// - virtual handle_type duplicate_internal(_In_ handle_type h) const; + handle_type duplicate_internal(_In_ handle_type h) const noexcept override; }; - /// /// DATA_BLOB wrapper class /// + #pragma warning(push) + #pragma warning(disable: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. class WINSTD_API data_blob : public DATA_BLOB { public: /// /// Initializes an empty BLOB. /// - inline data_blob() + inline data_blob() noexcept { cbData = 0; pbData = NULL; @@ -598,7 +599,7 @@ namespace winstd /// /// Initializes a BLOB from existing data. /// - inline data_blob(_In_count_(size) BYTE *data, _In_ DWORD size) + inline data_blob(_In_count_(size) BYTE *data, _In_ DWORD size) noexcept { cbData = size; pbData = data; @@ -611,7 +612,7 @@ namespace winstd { cbData = other.cbData; if (cbData) { - pbData = (BYTE*)LocalAlloc(LMEM_FIXED, other.cbData); + pbData = static_cast(LocalAlloc(LMEM_FIXED, other.cbData)); if (!pbData) throw win_runtime_error("LocalAlloc failed."); memcpy(pbData, other.pbData, other.cbData); } else @@ -621,7 +622,7 @@ namespace winstd /// /// Move an existing BLOB. /// - inline data_blob(_Inout_ DATA_BLOB &&other) noexcept + inline data_blob(_Inout_ data_blob &&other) noexcept { cbData = other.cbData; pbData = other.pbData; @@ -644,7 +645,7 @@ namespace winstd if (pbData) LocalFree(pbData); if (cbData) { - pbData = (BYTE*)LocalAlloc(LMEM_FIXED, other.cbData); + pbData = static_cast(LocalAlloc(LMEM_FIXED, other.cbData)); if (!pbData) throw win_runtime_error("LocalAlloc failed."); memcpy(pbData, other.pbData, other.cbData); } else @@ -657,7 +658,7 @@ namespace winstd /// /// Move an existing BLOB. /// - inline data_blob& operator=(_Inout_ DATA_BLOB &&other) noexcept + inline data_blob& operator=(_Inout_ data_blob &&other) noexcept { if (this != &other) { cbData = other.cbData; @@ -674,7 +675,7 @@ namespace winstd /// /// Get BLOB size. /// - inline DWORD size() const + inline DWORD size() const noexcept { return cbData; } @@ -682,7 +683,7 @@ namespace winstd /// /// Get BLOB buffer. /// - inline const BYTE* data() const + inline const BYTE* data() const noexcept { return pbData; } @@ -690,11 +691,12 @@ namespace winstd /// /// Get BLOB buffer. /// - inline BYTE* data() + inline BYTE* data() noexcept { return pbData; } }; + #pragma warning(pop) /// @} } diff --git a/include/WinStd/EAP.h b/include/WinStd/EAP.h index cd465627..bcd0669e 100644 --- a/include/WinStd/EAP.h +++ b/include/WinStd/EAP.h @@ -84,7 +84,7 @@ namespace winstd /// - Non zero when \p a is equal to \p b; /// - Zero otherwise. /// -inline bool operator==(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b); +inline bool operator==(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b) noexcept; /// /// Are EAP method types non-equal? @@ -96,7 +96,7 @@ inline bool operator==(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE /// - Non zero when \p a is not equal to \p b; /// - Zero otherwise. /// -inline bool operator!=(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b); +inline bool operator!=(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b) noexcept; /// @} @@ -155,7 +155,7 @@ namespace winstd /// /// Default constructor /// - EapHostPeerFreeMemory_delete() {} + EapHostPeerFreeMemory_delete() noexcept {} /// /// Delete a pointer @@ -178,7 +178,7 @@ namespace winstd /// /// Default constructor /// - EapHostPeerFreeRuntimeMemory_delete() {} + EapHostPeerFreeRuntimeMemory_delete() noexcept {} /// /// Delete a pointer @@ -199,14 +199,14 @@ namespace winstd /// /// Default constructor /// - EapHostPeerFreeErrorMemory_delete() {} + EapHostPeerFreeErrorMemory_delete() noexcept {} /// /// Delete a pointer /// /// \sa [EapHostPeerFreeErrorMemory function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363557.aspx) /// - void operator()(EAP_ERROR *_Ptr) const + void operator()(EAP_ERROR *_Ptr) const noexcept { EapHostPeerFreeErrorMemory(_Ptr); } @@ -221,14 +221,14 @@ namespace winstd /// /// Default constructor /// - EapHostPeerFreeEapError_delete() {} + EapHostPeerFreeEapError_delete() noexcept {} /// /// Delete a pointer /// /// \sa [EapHostPeerFreeEapError function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363556.aspx) /// - void operator()(EAP_ERROR *_Ptr) const + void operator()(EAP_ERROR *_Ptr) const noexcept { EapHostPeerFreeEapError(_Ptr); } @@ -238,13 +238,15 @@ namespace winstd /// /// EAP_ATTRIBUTE wrapper class /// + #pragma warning(push) + #pragma warning(disable: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. class WINSTD_API WINSTD_NOVTABLE eap_attr : public EAP_ATTRIBUTE { public: /// /// Initializes a new EAP attribute set to eatReserved. /// - inline eap_attr() + inline eap_attr() noexcept { eaType = eatReserved; dwLength = 0; @@ -341,6 +343,7 @@ namespace winstd public: static const EAP_ATTRIBUTE blank; ///< Blank EAP attribute }; + #pragma warning(pop) /// @@ -355,7 +358,7 @@ namespace winstd /// \param[in] type EAP method property type /// \param[in] value Property value /// - inline eap_method_prop(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_ BOOL value) + inline eap_method_prop(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_ BOOL value) noexcept { eapMethodPropertyType = type; eapMethodPropertyValueType = empvtBool; @@ -370,7 +373,7 @@ namespace winstd /// \param[in] type EAP method property type /// \param[in] value Property value /// - inline eap_method_prop(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_ DWORD value) + inline eap_method_prop(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_ DWORD value) noexcept { eapMethodPropertyType = type; eapMethodPropertyValueType = empvtDword; @@ -385,12 +388,12 @@ namespace winstd /// \param[in] type EAP method property type /// \param[in] value Property value /// - inline eap_method_prop(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_z_ LPCWSTR value) + inline eap_method_prop(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_z_ LPCWSTR value) noexcept { eapMethodPropertyType = type; eapMethodPropertyValueType = empvtString; - eapMethodPropertyValue.empvString.length = (DWORD)(sizeof(WCHAR)*(wcslen(value) + 1)); - eapMethodPropertyValue.empvString.value = (BYTE*)value; + eapMethodPropertyValue.empvString.length = static_cast(sizeof(WCHAR)*(wcslen(value) + 1)); + eapMethodPropertyValue.empvString.value = const_cast(reinterpret_cast(value)); } }; @@ -422,15 +425,15 @@ namespace winstd /// - true when creation succeeds; /// - false when creation fails. For extended error information, call `GetLastError()`. /// - inline bool create(_In_ EapCode code, _In_ BYTE id, _In_ WORD size) + inline bool create(_In_ EapCode code, _In_ BYTE id, _In_ WORD size) noexcept { assert(size >= 4); // EAP packets must contain at least Code, Id, and Length fields: 4B. - handle_type h = (handle_type)HeapAlloc(GetProcessHeap(), 0, size); + handle_type h = static_cast(HeapAlloc(GetProcessHeap(), 0, size)); if (h != NULL) { - h->Code = (BYTE) code ; - h->Id = id ; - *(WORD*)h->Length = htons(size); + h->Code = static_cast(code); + h->Id = id; + *reinterpret_cast(h->Length) = htons(size); attach(h); return true; @@ -444,7 +447,7 @@ namespace winstd /// /// Returns total EAP packet size in bytes. /// - inline WORD size() const + inline WORD size() const noexcept { return m_h != NULL ? ntohs(*(WORD*)m_h->Length) : 0; } @@ -454,12 +457,12 @@ namespace winstd /// /// Destroys the EAP packet. /// - virtual void free_internal(); + void free_internal() noexcept override; /// /// Duplicates the EAP packet. /// - virtual handle_type duplicate_internal(_In_ handle_type h) const; + handle_type duplicate_internal(_In_ handle_type h) const noexcept override; }; @@ -474,7 +477,7 @@ namespace winstd /// /// Constructs an empty array /// - inline eap_method_info_array() + inline eap_method_info_array() noexcept { dwNumberOfMethods = 0; pEapMethods = NULL; @@ -518,8 +521,8 @@ namespace winstd protected: /// \cond internal - void free_internal(); - static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo); + void free_internal() noexcept; + static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept; /// \endcond }; @@ -580,7 +583,7 @@ namespace winstd /// /// Returns EAP method type /// - inline const EAP_METHOD_TYPE& type() const + inline const EAP_METHOD_TYPE& type() const noexcept { return m_type; } @@ -589,7 +592,7 @@ namespace winstd /// /// Returns the reason code for error /// - inline DWORD reason() const + inline DWORD reason() const noexcept { return m_reason; } @@ -598,7 +601,7 @@ namespace winstd /// /// Returns root cause ID /// - inline const GUID& root_cause_id() const + inline const GUID& root_cause_id() const noexcept { return m_root_cause_id; } @@ -607,7 +610,7 @@ namespace winstd /// /// Returns root cause ID /// - inline const wchar_t* root_cause() const + inline const wchar_t* root_cause() const noexcept { return m_root_cause_desc.c_str(); } @@ -616,7 +619,7 @@ namespace winstd /// /// Returns repair ID /// - inline const GUID& repair_id() const + inline const GUID& repair_id() const noexcept { return m_repair_id; } @@ -625,7 +628,7 @@ namespace winstd /// /// Returns root cause ID /// - inline const wchar_t* repair() const + inline const wchar_t* repair() const noexcept { return m_repair_desc.c_str(); } @@ -634,7 +637,7 @@ namespace winstd /// /// Returns help_link ID /// - inline const GUID& help_link_id() const + inline const GUID& help_link_id() const noexcept { return m_help_link_id; } @@ -657,7 +660,7 @@ namespace winstd } -inline bool operator==(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b) +inline bool operator==(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b) noexcept { return a.eapType.type == b.eapType.type && @@ -667,7 +670,7 @@ inline bool operator==(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE } -inline bool operator!=(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b) +inline bool operator!=(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE &b) noexcept { return !operator==(a, b); } diff --git a/include/WinStd/ETW.h b/include/WinStd/ETW.h index da3f9f5e..9fa1012c 100644 --- a/include/WinStd/ETW.h +++ b/include/WinStd/ETW.h @@ -613,7 +613,7 @@ namespace winstd /// /// \sa [EventUnregister function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363749.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; /// @@ -813,7 +813,7 @@ namespace winstd /// /// \sa [ControlTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363696.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; protected: std::unique_ptr m_prop; ///< Session properties @@ -861,7 +861,7 @@ namespace winstd /// /// \sa [CloseTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363686.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; diff --git a/include/WinStd/Hex.h b/include/WinStd/Hex.h index 30f87257..5ba80235 100644 --- a/include/WinStd/Hex.h +++ b/include/WinStd/Hex.h @@ -51,7 +51,7 @@ namespace winstd /// /// Constructs blank encoding session /// - inline hex_enc() + inline hex_enc() noexcept { } @@ -91,7 +91,7 @@ namespace winstd /// /// \returns Maximum number of bytes for the encoded data of `size` length /// - inline size_t enc_size(size_t size) const + inline size_t enc_size(size_t size) const noexcept { return size*2; } @@ -107,7 +107,7 @@ namespace winstd /// /// Constructs blank decoding session /// - inline hex_dec() : + inline hex_dec() noexcept : buf(0), num(0) { @@ -164,7 +164,7 @@ namespace winstd /// /// Resets decoding session /// - inline void clear() + inline void clear() noexcept { num = 0; } @@ -177,7 +177,7 @@ namespace winstd /// /// \returns Maximum number of bytes for the decoded data of `size` length /// - inline size_t dec_size(size_t size) const + inline size_t dec_size(size_t size) const noexcept { return (size + 1)/2; } diff --git a/include/WinStd/Sec.h b/include/WinStd/Sec.h index 881c1df6..152952f5 100644 --- a/include/WinStd/Sec.h +++ b/include/WinStd/Sec.h @@ -155,7 +155,7 @@ namespace winstd /// /// \sa [FreeCredentialsHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375417.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; public: TimeStamp m_expires; ///< Credentials expiration time @@ -270,7 +270,7 @@ namespace winstd /// /// \sa [DeleteSecurityContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375354.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; public: ULONG m_attrib; ///< Context attributes diff --git a/include/WinStd/SetupAPI.h b/include/WinStd/SetupAPI.h index f862178c..29cd5310 100644 --- a/include/WinStd/SetupAPI.h +++ b/include/WinStd/SetupAPI.h @@ -68,7 +68,7 @@ namespace winstd /// inline bool create( _In_opt_ const GUID * ClassGuid, - _In_opt_ HWND hwndParent) + _In_opt_ HWND hwndParent) noexcept { handle_type h = SetupDiCreateDeviceInfoList(ClassGuid, hwndParent); if (h != invalid) { @@ -95,7 +95,7 @@ namespace winstd _In_ DWORD Flags, _In_opt_ HDEVINFO DeviceInfoSet, _In_opt_ PCTSTR MachineName, - _Reserved_ PVOID Reserved) + _Reserved_ PVOID Reserved) noexcept { handle_type h = SetupDiGetClassDevsEx(ClassGuid, Enumerator, hwndParent, Flags, DeviceInfoSet, MachineName, Reserved); if (h != invalid) { @@ -112,7 +112,7 @@ namespace winstd /// /// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -121,6 +121,9 @@ namespace winstd /// class WINSTD_API setup_driver_info_list_builder { + WINSTD_NONCOPYABLE(setup_driver_info_list_builder) + WINSTD_NONMOVABLE(setup_driver_info_list_builder) + public: /// /// Construct the builder and builds a list of drivers that is associated with a specific device or with the global class driver list for a device information set. @@ -130,7 +133,7 @@ namespace winstd inline setup_driver_info_list_builder( _In_ HDEVINFO DeviceInfoSet, _Inout_opt_ PSP_DEVINFO_DATA DeviceInfoData, - _In_ DWORD DriverType) : + _In_ DWORD DriverType) noexcept : m_DeviceInfoSet (DeviceInfoSet), m_DeviceInfoData(DeviceInfoData), m_DriverType (DriverType) @@ -151,7 +154,7 @@ namespace winstd /// /// \sa [SetupDiBuildDriverInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdibuilddriverinfolist) /// - inline BOOL status() const + inline BOOL status() const noexcept { return m_result; } diff --git a/include/WinStd/WLAN.h b/include/WinStd/WLAN.h index 6620f99a..37b8c484 100644 --- a/include/WinStd/WLAN.h +++ b/include/WinStd/WLAN.h @@ -145,10 +145,10 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool open(_In_ DWORD dwClientVersion, _Out_ PDWORD pdwNegotiatedVersion) + inline bool open(_In_ DWORD dwClientVersion, _Out_ PDWORD pdwNegotiatedVersion) noexcept { handle_type h; - DWORD dwResult = WlanOpenHandle(dwClientVersion, 0, pdwNegotiatedVersion, &h); + const DWORD dwResult = WlanOpenHandle(dwClientVersion, 0, pdwNegotiatedVersion, &h); if (dwResult == ERROR_SUCCESS) { attach(h); return true; @@ -164,7 +164,7 @@ namespace winstd /// /// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; /// @} diff --git a/include/WinStd/Win.h b/include/WinStd/Win.h index cba5a913..78e1c4b6 100644 --- a/include/WinStd/Win.h +++ b/include/WinStd/Win.h @@ -54,47 +54,47 @@ namespace winstd /// @{ /// @copydoc GetModuleFileNameW() -template inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// /// Retrieves the fully qualified path for the file that contains the specified module and stores it in a std::wstring string. /// /// \sa [GetModuleFileName function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197.aspx) /// -template inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// @copydoc GetWindowTextW() -template inline _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// /// Copies the text of the specified window's title bar (if it has one) into a std::wstring string. /// /// \sa [GetWindowText function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633520.aspx) /// -template inline _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// @copydoc GetFileVersionInfoW() -template inline _Success_(return != 0) BOOL GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue); +template inline _Success_(return != 0) BOOL GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept; /// /// Retrieves version information for the specified file and stores it in a std::vector buffer. /// /// \sa [GetFileVersionInfo function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms647003.aspx) /// -template inline _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue); +template inline _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept; /// @copydoc ExpandEnvironmentStringsW() -template inline _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// /// Expands environment-variable strings, replaces them with the values defined for the current user, and stores it in a std::wstring string. /// /// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx) /// -template inline _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// @copydoc GuidToStringW() -template inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str); +template inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept; /// /// Formats GUID and stores it in a std::wstring string. @@ -102,7 +102,7 @@ template inline VOID GuidToStringA(_In_ L /// \param[in ] lpGuid Pointer to GUID /// \param[out] str String to store the result to /// -template inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str); +template inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept; /// @copydoc GuidToStringW() #ifdef _UNICODE #define GuidToString GuidToStringW @@ -111,7 +111,7 @@ template inline VOID GuidToStringW(_In_ L #endif /// @copydoc StringToGuidW() -_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL); +_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL) noexcept; /// /// Parses string with GUID and stores it to GUID @@ -124,7 +124,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP /// - `TRUE` if GUID successfuly parsed; /// - `FALSE` otherwise. /// -_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL); +_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL) noexcept; /// @copydoc StringToGuidW() #ifdef _UNICODE #define StringToGuid StringToGuidW @@ -150,7 +150,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L /// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx) /// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx) /// -template inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// /// Queries for a string value in the registry and stores it in a std::wstring string. @@ -170,29 +170,29 @@ template inline LSTATUS RegQueryStringVal /// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx) /// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx) /// -template inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; /// @copydoc RegQueryValueExW() -template inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData); +template inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData) noexcept; /// /// Retrieves the type and data for the specified value name associated with an open registry key and stores the data in a std::vector buffer. /// /// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx) /// -template inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData); +template inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData) noexcept; #if _WIN32_WINNT >= _WIN32_WINNT_VISTA /// @copydoc RegLoadMUIStringW() -template inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory); +template inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) noexcept; /// /// Loads the specified string from the specified key and subkey, and stores it in a std::wstring string. /// /// \sa [RegLoadMUIString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724890.aspx) /// -template inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory); +template inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) noexcept; #endif @@ -201,21 +201,21 @@ template inline LSTATUS RegLoadMUIStringW /// /// \sa [WideCharToMultiByte function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx) /// -template inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept; /// /// Maps a UTF-16 (wide character) string to a std::vector. The new character vector is not necessarily from a multibyte character set. /// /// \sa [WideCharToMultiByte function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx) /// -template inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept; /// /// Maps a UTF-16 (wide character) string to a std::string. The new character string is not necessarily from a multibyte character set. /// /// \sa [WideCharToMultiByte function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx) /// -template inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _Out_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _Out_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept; /// /// Maps a UTF-16 (wide character) string to a std::string. The new character string is not necessarily from a multibyte character set. @@ -224,7 +224,7 @@ template inline _Success /// /// \sa [WideCharToMultiByte function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx) /// -template inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept; /// /// Maps a UTF-16 (wide character) string to a std::vector. The new character vector is not necessarily from a multibyte character set. @@ -233,7 +233,7 @@ template inline _Success_(return != 0) int SecureWideC /// /// \sa [WideCharToMultiByte function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx) /// -template inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept; /// /// Maps a UTF-16 (wide character) string to a std::string. The new character string is not necessarily from a multibyte character set. @@ -242,28 +242,28 @@ template inline _Success_(return != 0) int SecureWideCharToMultiByte( /// /// \sa [WideCharToMultiByte function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130.aspx) /// -template inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _Out_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _Out_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept; /// /// Maps a character string to a UTF-16 (wide character) std::wstring. The character string is not necessarily from a multibyte character set. /// /// \sa [MultiByteToWideChar function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072.aspx) /// -template inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr); +template inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr) noexcept; /// /// Maps a character string to a UTF-16 (wide character) std::vector. The character vector is not necessarily from a multibyte character set. /// /// \sa [MultiByteToWideChar function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072.aspx) /// -template inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr); +template inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr) noexcept; /// /// Maps a character string to a UTF-16 (wide character) std::wstring. The character string is not necessarily from a multibyte character set. /// /// \sa [MultiByteToWideChar function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072.aspx) /// -template inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr); +template inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr) noexcept; /// /// Maps a character string to a UTF-16 (wide character) std::wstring. The character string is not necessarily from a multibyte character set. @@ -272,7 +272,7 @@ template inline _Success /// /// \sa [MultiByteToWideChar function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072.aspx) /// -template inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr); +template inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr) noexcept; /// /// Maps a character string to a UTF-16 (wide character) std::vector. The character vector is not necessarily from a multibyte character set. @@ -281,7 +281,7 @@ template inline _Success_(return != 0) int SecureMulti /// /// \sa [MultiByteToWideChar function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072.aspx) /// -template inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr); +template inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr) noexcept; /// /// Maps a character string to a UTF-16 (wide character) std::wstring. The character string is not necessarily from a multibyte character set. @@ -290,72 +290,72 @@ template inline _Success_(return != 0) int SecureMultiByteToWideChar( /// /// \sa [MultiByteToWideChar function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd319072.aspx) /// -template inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr); +template inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr) noexcept; /// @copydoc LoadStringW -template inline _Success_(return != 0) int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer); +template inline _Success_(return != 0) int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer) noexcept; /// /// Loads a string resource from the executable file associated with a specified module. /// /// \sa [LoadString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms647486.aspx) /// -template inline _Success_(return != 0) int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer); +template inline _Success_(return != 0) int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer) noexcept; /// /// Formats and sends a string to the debugger for display. /// /// \sa [OutputDebugString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363362.aspx) /// -inline VOID OutputDebugStrV(_In_z_ LPCSTR lpOutputString, _In_ va_list arg); +inline VOID OutputDebugStrV(_In_z_ LPCSTR lpOutputString, _In_ va_list arg) noexcept; /// /// Formats and sends a string to the debugger for display. /// /// \sa [OutputDebugString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363362.aspx) /// -inline VOID OutputDebugStrV(_In_z_ LPCWSTR lpOutputString, _In_ va_list arg); +inline VOID OutputDebugStrV(_In_z_ LPCWSTR lpOutputString, _In_ va_list arg) noexcept; /// /// Formats and sends a string to the debugger for display. /// /// \sa [OutputDebugString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363362.aspx) /// -inline VOID OutputDebugStr(_In_z_ LPCSTR lpOutputString, ...); +inline VOID OutputDebugStr(_In_z_ LPCSTR lpOutputString, ...) noexcept; /// /// Formats and sends a string to the debugger for display. /// /// \sa [OutputDebugString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363362.aspx) /// -inline VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...); +inline VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) noexcept; /// @copydoc GetDateFormatW() -template inline _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate); +template inline _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept; /// /// Formats a date as a date string for a locale specified by the locale identifier. The function formats either a specified date or the local system date. /// /// \sa [GetDateFormat function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd318086.aspx) /// -template inline _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate); +template inline _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept; /// @copydoc LookupAccountSidW() -template inline _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse); +template inline _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept; /// /// Retrieves the name of the account for this SID and the name of the first domain on which this SID is found. /// /// \sa [LookupAccountSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379166.aspx) /// -template inline _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse); +template inline _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept; /// /// Retrieves a specified type of information about an access token. The calling process must have appropriate access rights to obtain the information. /// /// \sa [GetTokenInformation function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa446671.aspx) /// -template inline _Success_(return != 0) BOOL GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation); +template inline _Success_(return != 0) BOOL GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation) noexcept; /// @} @@ -393,7 +393,7 @@ namespace winstd /// /// \sa [CloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211.aspx) /// - virtual void free_internal() + void free_internal() noexcept override { CloseHandle(m_h); } @@ -424,7 +424,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool load(_In_z_ LPCTSTR lpFileName, __reserved handle_type hFile, _In_ DWORD dwFlags) + inline bool load(_In_z_ LPCTSTR lpFileName, __reserved handle_type hFile, _In_ DWORD dwFlags) noexcept { handle_type h = LoadLibraryEx(lpFileName, hFile, dwFlags); if (h != invalid) { @@ -440,7 +440,7 @@ namespace winstd /// /// \sa [FreeLibrary function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683152.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -459,7 +459,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool open(_In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_ DWORD dwProcessId) + inline bool open(_In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_ DWORD dwProcessId) noexcept { handle_type h = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); if (h != invalid) { @@ -486,7 +486,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool create(_In_z_ LPCTSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_ DWORD dwCreationDisposition, _In_opt_ DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL, _In_opt_ HANDLE hTemplateFile = NULL) + inline bool create(_In_z_ LPCTSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_ DWORD dwCreationDisposition, _In_opt_ DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL, _In_opt_ HANDLE hTemplateFile = NULL) noexcept { handle_type h = CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); if (h != invalid) { @@ -513,7 +513,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool create(_In_ BOOL bManualReset, _In_ BOOL bInitialState, _In_opt_ LPSECURITY_ATTRIBUTES lpEventAttributes = NULL, _In_opt_z_ LPCTSTR lpName = NULL) + inline bool create(_In_ BOOL bManualReset, _In_ BOOL bInitialState, _In_opt_ LPSECURITY_ATTRIBUTES lpEventAttributes = NULL, _In_opt_z_ LPCTSTR lpName = NULL) noexcept { handle_type h = CreateEvent(lpEventAttributes, bManualReset, bInitialState, lpName); if (h != invalid) { @@ -532,7 +532,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool open(_In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_z_ LPCTSTR lpName) + inline bool open(_In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_z_ LPCTSTR lpName) noexcept { handle_type h = OpenEvent(dwDesiredAccess, bInheritHandle, lpName); if (h != invalid) { @@ -572,7 +572,7 @@ namespace winstd /// /// \return Pointer to critical section /// - inline operator LPCRITICAL_SECTION() + inline operator LPCRITICAL_SECTION() noexcept { return &m_data; } @@ -606,7 +606,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool find(_In_ LPCTSTR lpFileName, _Out_ LPWIN32_FIND_DATA lpFindFileData) + inline bool find(_In_ LPCTSTR lpFileName, _Out_ LPWIN32_FIND_DATA lpFindFileData) noexcept { handle_type h = FindFirstFile(lpFileName, lpFindFileData); if (h != invalid) { @@ -622,7 +622,7 @@ namespace winstd /// /// \sa [FindClose function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findclose) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -650,7 +650,7 @@ namespace winstd /// - \c true when succeeds; /// - \c false when fails. Use `GetLastError()` for failure reason. /// - inline bool create(_In_ DWORD flOptions, _In_ SIZE_T dwInitialSize, _In_ SIZE_T dwMaximumSize) + inline bool create(_In_ DWORD flOptions, _In_ SIZE_T dwInitialSize, _In_ SIZE_T dwMaximumSize) noexcept { handle_type h = HeapCreate(flOptions, dwInitialSize, dwMaximumSize); if (h != invalid) { @@ -667,7 +667,7 @@ namespace winstd /// - `true` if any blocks found; /// - `false` otherwise. /// - bool enumerate(); + bool enumerate() noexcept; protected: /// @@ -675,7 +675,7 @@ namespace winstd /// /// \sa [HeapDestroy function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366700.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -801,6 +801,9 @@ namespace winstd /// class WINSTD_API actctx_activator { + WINSTD_NONCOPYABLE(actctx_activator) + WINSTD_NONMOVABLE(actctx_activator) + public: /// /// Construct the activator and activates the given activation context @@ -809,7 +812,7 @@ namespace winstd /// /// \sa [ActivateActCtx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374151.aspx) /// - actctx_activator(_In_ HANDLE hActCtx); + actctx_activator(_In_ HANDLE hActCtx) noexcept; /// /// Deactivates activation context and destructs the activator @@ -828,6 +831,9 @@ namespace winstd /// class WINSTD_API user_impersonator { + WINSTD_NONCOPYABLE(user_impersonator) + WINSTD_NONMOVABLE(user_impersonator) + public: /// /// Construct the impersonator and impersonates the given user @@ -836,7 +842,7 @@ namespace winstd /// /// \sa [ImpersonateLoggedOnUser function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa378612.aspx) /// - user_impersonator(_In_opt_ HANDLE hToken); + user_impersonator(_In_opt_ HANDLE hToken) noexcept; /// /// Reverts to current user and destructs the impersonator @@ -855,6 +861,9 @@ namespace winstd /// class WINSTD_API console_ctrl_handler { + WINSTD_NONCOPYABLE(console_ctrl_handler) + WINSTD_NONMOVABLE(console_ctrl_handler) + public: /// /// Construct the console control handler object and pushes the given handler to the console control handler stack @@ -863,7 +872,7 @@ namespace winstd /// /// \sa [SetConsoleCtrlHandler function](https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler) /// - console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine); + console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept; /// /// Pops console control handler from the console control handler stack @@ -889,7 +898,7 @@ namespace winstd /// /// Initializes a new class instance with the memory handle set to INVAL. /// - inline vmemory() : m_proc(NULL) + inline vmemory() noexcept : m_proc(NULL) { } @@ -899,7 +908,7 @@ namespace winstd /// \param[in] proc Handle of process the memory belongs to /// \param[in] h Initial object handle value /// - inline vmemory(_In_ handle_type h, _In_ HANDLE proc) : + inline vmemory(_In_ handle_type h, _In_ HANDLE proc) noexcept : m_proc(proc), handle(h) { @@ -945,7 +954,7 @@ namespace winstd /// \param[in] proc Handle of process the memory belongs to /// \param[in] h Initial object handle value /// - inline void attach(_In_ HANDLE proc, _In_opt_ handle_type h) + inline void attach(_In_ HANDLE proc, _In_opt_ handle_type h) noexcept { m_proc = proc; if (m_h != invalid) @@ -966,8 +975,8 @@ namespace winstd _In_ HANDLE hProcess, _In_opt_ LPVOID lpAddress, _In_ SIZE_T dwSize, - _In_ DWORD flAllocationType, - _In_ DWORD flProtect) + _In_ DWORD flAllocationType, + _In_ DWORD flProtect) noexcept { handle_type h = VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect); if (h != invalid) { @@ -983,7 +992,7 @@ namespace winstd /// /// \sa [VirtualFreeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366894.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; protected: HANDLE m_proc; ///< Handle of memory's process @@ -1021,10 +1030,10 @@ namespace winstd _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL, - _Out_opt_ LPDWORD lpdwDisposition = NULL) + _Out_opt_ LPDWORD lpdwDisposition = NULL) noexcept { handle_type h; - LSTATUS s = RegCreateKeyEx(hKey, lpSubKey, 0, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition); + const LSTATUS s = RegCreateKeyEx(hKey, lpSubKey, 0, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition); if (s == ERROR_SUCCESS) { attach(h); return true; @@ -1047,10 +1056,10 @@ namespace winstd _In_ HKEY hKey, _In_opt_z_ LPCTSTR lpSubKey, _In_ DWORD ulOptions, - _In_ REGSAM samDesired) + _In_ REGSAM samDesired) noexcept { handle_type h; - LONG s = RegOpenKeyEx(hKey, lpSubKey, ulOptions, samDesired, &h); + const LONG s = RegOpenKeyEx(hKey, lpSubKey, ulOptions, samDesired, &h); if (s == ERROR_SUCCESS) { attach(h); return true; @@ -1066,7 +1075,7 @@ namespace winstd /// /// \sa [RegCloseKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724837.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -1091,7 +1100,7 @@ namespace winstd /// /// \sa [FreeSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa446631.aspx) /// - virtual void free_internal(); + void free_internal() noexcept override; }; @@ -1100,11 +1109,14 @@ namespace winstd /// class WINSTD_API process_information : public PROCESS_INFORMATION { + WINSTD_NONCOPYABLE(process_information) + WINSTD_NONMOVABLE(process_information) + public: /// /// Constructs blank PROCESS_INFORMATION /// - inline process_information() + inline process_information() noexcept { hProcess = INVALID_HANDLE_VALUE; hThread = INVALID_HANDLE_VALUE; @@ -1135,7 +1147,7 @@ namespace winstd template -inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { assert(0); // TODO: Test this code. @@ -1162,7 +1174,7 @@ inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_strin template -inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { _Elem szBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; @@ -1187,7 +1199,7 @@ inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_strin template -inline _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { assert(0); // TODO: Test this code. @@ -1216,7 +1228,7 @@ inline _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basi template -inline _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { assert(0); // TODO: Test this code. @@ -1245,7 +1257,7 @@ inline _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basi template -inline _Success_(return != 0) BOOL GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) +inline _Success_(return != 0) BOOL GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept { assert(0); // TODO: Test this code. @@ -1261,7 +1273,7 @@ inline _Success_(return != 0) BOOL GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilen template -inline _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) +inline _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept { assert(0); // TODO: Test this code. @@ -1277,7 +1289,7 @@ inline _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFile template -inline _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { assert(0); // TODO: Test this code. @@ -1301,7 +1313,7 @@ inline _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSr template -inline _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { for (DWORD dwSizeOut = (DWORD)wcslen(lpSrc) + 0x100;;) { DWORD dwSizeIn = dwSizeOut; @@ -1323,7 +1335,7 @@ inline _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpS template -inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) +inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept { assert(0); // TODO: Test this code. @@ -1337,7 +1349,7 @@ inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T template -inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) +inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept { assert(0); // TODO: Test this code. @@ -1351,7 +1363,7 @@ inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T template -inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { LSTATUS lResult; BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES]; @@ -1398,7 +1410,7 @@ inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ template -inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) +inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept { LSTATUS lResult; BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES]; @@ -1445,7 +1457,7 @@ inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ template -inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData) +inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData) noexcept { LSTATUS lResult; BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES]; @@ -1468,7 +1480,7 @@ inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, _ template -inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData) +inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData) noexcept { LSTATUS lResult; BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES]; @@ -1493,7 +1505,7 @@ inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, #if _WIN32_WINNT >= _WIN32_WINNT_VISTA template -inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) +inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) noexcept { // According to "Remarks" section in MSDN documentation of RegLoadMUIString(), // this function is defined but not implemented as ANSI variation. @@ -1503,7 +1515,7 @@ inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Ou template -inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) +inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) noexcept { LSTATUS lResult; _Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; @@ -1529,7 +1541,7 @@ inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _O template -inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) +inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept { CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(CHAR)]; @@ -1551,7 +1563,7 @@ inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ D template -inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) +inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept { CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(CHAR)]; @@ -1572,7 +1584,7 @@ inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ D template -inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) +inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept { CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(CHAR)]; @@ -1594,7 +1606,7 @@ inline _Success_(return != 0) int WideCharToMultiByte(_In_ UINT CodePage, _In_ D template -inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) +inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept { CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(CHAR)]; @@ -1619,7 +1631,7 @@ inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, template -inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) +inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::vector &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept { CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(CHAR)]; @@ -1642,7 +1654,7 @@ inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, template -inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) +inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ std::basic_string sWideCharStr, _Out_ std::basic_string &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept { CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(CHAR)]; @@ -1667,7 +1679,7 @@ inline _Success_(return != 0) int SecureWideCharToMultiByte(_In_ UINT CodePage, template -inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr) +inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr) noexcept { WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(WCHAR)]; @@ -1689,7 +1701,7 @@ inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ D template -inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr) +inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr) noexcept { WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(WCHAR)]; @@ -1710,7 +1722,7 @@ inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ D template -inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr) +inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr) noexcept { WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(WCHAR)]; @@ -1732,7 +1744,7 @@ inline _Success_(return != 0) int MultiByteToWideChar(_In_ UINT CodePage, _In_ D template -inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr) +inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string &sWideCharStr) noexcept { WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(WCHAR)]; @@ -1757,7 +1769,7 @@ inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, template -inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr) +inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::vector &sWideCharStr) noexcept { WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(WCHAR)]; @@ -1780,7 +1792,7 @@ inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, template -inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr) +inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string &sMultiByteStr, _Out_ std::basic_string &sWideCharStr) noexcept { WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(WCHAR)]; @@ -1805,7 +1817,7 @@ inline _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, template -inline _Success_(return != 0) int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer) +inline _Success_(return != 0) int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer) noexcept { // Get read-only pointer to string resource. LPCSTR pszStr; @@ -1819,7 +1831,7 @@ inline _Success_(return != 0) int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstanc template -inline _Success_(return != 0) int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer) +inline _Success_(return != 0) int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string &sBuffer) noexcept { // Get read-only pointer to string resource. LPCWSTR pszStr; @@ -1832,23 +1844,23 @@ inline _Success_(return != 0) int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstanc } -inline VOID OutputDebugStrV(_In_z_ LPCSTR lpOutputString, _In_ va_list arg) +inline VOID OutputDebugStrV(_In_z_ LPCSTR lpOutputString, _In_ va_list arg) noexcept { std::string str; - vsprintf(str, lpOutputString, arg); + try { vsprintf(str, lpOutputString, arg); } catch (...) { return; } OutputDebugStringA(str.c_str()); } -inline VOID OutputDebugStrV(_In_z_ LPCWSTR lpOutputString, _In_ va_list arg) +inline VOID OutputDebugStrV(_In_z_ LPCWSTR lpOutputString, _In_ va_list arg) noexcept { std::wstring str; - vsprintf(str, lpOutputString, arg); + try { vsprintf(str, lpOutputString, arg); } catch (...) { return; } OutputDebugStringW(str.c_str()); } -inline VOID OutputDebugStr(_In_z_ LPCSTR lpOutputString, ...) +inline VOID OutputDebugStr(_In_z_ LPCSTR lpOutputString, ...) noexcept { va_list arg; va_start(arg, lpOutputString); @@ -1857,7 +1869,7 @@ inline VOID OutputDebugStr(_In_z_ LPCSTR lpOutputString, ...) } -inline VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) +inline VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) noexcept { va_list arg; va_start(arg, lpOutputString); @@ -1866,7 +1878,7 @@ inline VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) } -template inline _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) +template inline _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept { int iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0); if (iResult) { @@ -1881,7 +1893,7 @@ template inline _Success_(return != 0) in } -template inline _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) +template inline _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept { int iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0); if (iResult) { @@ -1897,7 +1909,7 @@ template inline _Success_(return != 0) in template -inline _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) +inline _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept { assert(0); // TODO: Test this code. @@ -1932,7 +1944,7 @@ inline _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemN template -inline _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) +inline _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept { assert(0); // TODO: Test this code. @@ -1967,7 +1979,7 @@ inline _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystem template -inline _Success_(return != 0) BOOL GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation) +inline _Success_(return != 0) BOOL GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation) noexcept { BYTE szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(BYTE)]; DWORD dwSize; diff --git a/include/WinStd/WinSock2.h b/include/WinStd/WinSock2.h index 517945ef..31678fcb 100644 --- a/include/WinStd/WinSock2.h +++ b/include/WinStd/WinSock2.h @@ -93,16 +93,6 @@ namespace winstd } - /// - /// Copies an exception - /// - /// \param[in] other Exception to copy from - /// - inline ws2_runtime_error(const ws2_runtime_error &other) : num_runtime_error(other) - { - } - - /// /// Returns a user-readable Windows error message /// @@ -167,7 +157,7 @@ namespace winstd /// /// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow) /// - virtual void free_internal(); + void free_internal() noexcept override; }; #endif diff --git a/include/WinStd/WinTrust.h b/include/WinStd/WinTrust.h index d50bcfe9..5e94d5fa 100644 --- a/include/WinStd/WinTrust.h +++ b/include/WinStd/WinTrust.h @@ -47,6 +47,9 @@ namespace winstd /// class WINSTD_API wintrust { + WINSTD_NONCOPYABLE(wintrust) + WINSTD_NONMOVABLE(wintrust) + public: /// /// Initializes a new class instance. @@ -56,7 +59,7 @@ namespace winstd m_action(action), m_wtd(wtd) { - LONG lResult = WinVerifyTrust(m_hwnd, &m_action, &m_wtd); + const LONG lResult = WinVerifyTrust(m_hwnd, &m_action, &m_wtd); if (lResult != ERROR_SUCCESS) throw win_runtime_error(lResult, "WinVerifyTrust failed."); } diff --git a/src/COM.cpp b/src/COM.cpp index b96681fb..99daacdf 100644 --- a/src/COM.cpp +++ b/src/COM.cpp @@ -32,13 +32,13 @@ winstd::bstr::~bstr() } -void winstd::bstr::free_internal() +void winstd::bstr::free_internal() noexcept { SysFreeString(m_h); } -winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) const +winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) const noexcept { return SysAllocStringLen(h, SysStringLen(h)); } @@ -48,6 +48,7 @@ winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) c // winstd::variant ////////////////////////////////////////////////////////////////////// +#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. winstd::variant::~variant() { VariantClear(this); diff --git a/src/Crypt.cpp b/src/Crypt.cpp index f28a3d4d..a388d923 100644 --- a/src/Crypt.cpp +++ b/src/Crypt.cpp @@ -34,13 +34,13 @@ winstd::cert_context::~cert_context() } -void winstd::cert_context::free_internal() +void winstd::cert_context::free_internal() noexcept { CertFreeCertificateContext(m_h); } -winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_ handle_type h) const +winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_ handle_type h) const noexcept { return CertDuplicateCertificateContext(h); } @@ -57,13 +57,13 @@ winstd::cert_chain_context::~cert_chain_context() } -void winstd::cert_chain_context::free_internal() +void winstd::cert_chain_context::free_internal() noexcept { CertFreeCertificateChain(m_h); } -winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_internal(_In_ handle_type h) const +winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_internal(_In_ handle_type h) const noexcept { return CertDuplicateCertificateChain(h); } @@ -80,7 +80,7 @@ winstd::cert_store::~cert_store() } -void winstd::cert_store::free_internal() +void winstd::cert_store::free_internal() noexcept { CertCloseStore(m_h, 0); } @@ -97,7 +97,7 @@ winstd::crypt_prov::~crypt_prov() } -void winstd::crypt_prov::free_internal() +void winstd::crypt_prov::free_internal() noexcept { CryptReleaseContext(m_h, 0); } @@ -114,13 +114,13 @@ winstd::crypt_hash::~crypt_hash() } -void winstd::crypt_hash::free_internal() +void winstd::crypt_hash::free_internal() noexcept { CryptDestroyHash(m_h); } -winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const +winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const noexcept { handle_type hNew = invalid; return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : invalid; @@ -155,7 +155,7 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec) // Get the byte length of the key. size_t - size_key = *(DWORD*)&key_blob[12]/8, + size_key = *reinterpret_cast(&key_blob[12])/8, size_prime = size_key/2; // Modify the Exponent in Key BLOB format @@ -163,7 +163,7 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec) // Convert pubexp in rsapubkey to 1 LPBYTE ptr = &key_blob[16]; - *(DWORD*)ptr = 1; + *reinterpret_cast(ptr) = 1; ptr += sizeof(DWORD); // Skip modulus, prime1, prime2 @@ -189,7 +189,7 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec) memset(ptr + 1, 0, size_key - 1); // Import the exponent-of-one private key. - if (CryptImportKey(hProv, key_blob.data(), (DWORD)key_blob.size(), 0, 0, &h)) { + if (CryptImportKey(hProv, key_blob.data(), static_cast(key_blob.size()), 0, 0, &h)) { attach(h); return true; } @@ -201,13 +201,13 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec) } -void winstd::crypt_key::free_internal() +void winstd::crypt_key::free_internal() noexcept { CryptDestroyKey(m_h); } -winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const +winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const noexcept { handle_type hNew = invalid; return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : invalid; @@ -218,6 +218,7 @@ winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle // winstd::data_blob ////////////////////////////////////////////////////////////////////// +#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. winstd::data_blob::~data_blob() { if (pbData != NULL) diff --git a/src/EAP.cpp b/src/EAP.cpp index c08547b6..54cc1731 100644 --- a/src/EAP.cpp +++ b/src/EAP.cpp @@ -27,17 +27,18 @@ // winstd::eap_attr ////////////////////////////////////////////////////////////////////// +#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference. winstd::eap_attr::~eap_attr() { if (pValue) - delete []pValue; + delete [] pValue; } void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize) { - BYTE nPaddingLength = (BYTE)((16 - (1 + (DWORD)nKeySize)) % 16); - DWORD dwLengthNew = + const BYTE nPaddingLength = static_cast((16 - (1 + static_cast(nKeySize))) % 16); + const DWORD dwLengthNew = 4 + // Vendor-Id 1 + // Vendor type 1 + // Vendor length @@ -54,7 +55,7 @@ void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKey p[2] = 0x01; // --| p[3] = 0x37; // --^ p[4] = bVendorType; // Vendor type - p[5] = (BYTE)(dwLengthNew - 4); // Vendor length + p[5] = static_cast(dwLengthNew - 4); // Vendor length p[6] = 0x00; // Salt p[7] = 0x00; // --^ p[8] = nKeySize; // Key-Length @@ -65,6 +66,7 @@ void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKey if (pValue) delete [] pValue; + #pragma warning(suppress: 26812) // EAP_ATTRIBUTE_TYPE is unscoped. eaType = eatVendorSpecific; dwLength = dwLengthNew; pValue = p; @@ -85,16 +87,16 @@ winstd::eap_packet::~eap_packet() } -void winstd::eap_packet::free_internal() +void winstd::eap_packet::free_internal() noexcept { HeapFree(GetProcessHeap(), 0, m_h); } -winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const +winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const noexcept { - WORD n = ntohs(*(WORD*)h->Length); - handle_type h2 = (handle_type)HeapAlloc(GetProcessHeap(), 0, n); + const WORD n = ntohs(*reinterpret_cast(h->Length)); + handle_type h2 = static_cast(HeapAlloc(GetProcessHeap(), 0, n)); if (h2 == invalid) { SetLastError(ERROR_OUTOFMEMORY); return invalid; @@ -119,22 +121,22 @@ winstd::eap_method_info_array::~eap_method_info_array() /// \cond internal -void winstd::eap_method_info_array::free_internal() +void winstd::eap_method_info_array::free_internal() noexcept { for (DWORD i = 0; i < dwNumberOfMethods; i++) free_internal(pEapMethods + i); - EapHostPeerFreeMemory((BYTE*)pEapMethods); + EapHostPeerFreeMemory(reinterpret_cast(pEapMethods)); } -void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) +void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept { if (pMethodInfo->pInnerMethodInfo) free_internal(pMethodInfo->pInnerMethodInfo); - EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszAuthorName); - EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszFriendlyName); + EapHostPeerFreeMemory(reinterpret_cast(pMethodInfo->pwszAuthorName)); + EapHostPeerFreeMemory(reinterpret_cast(pMethodInfo->pwszFriendlyName)); } /// \endcond diff --git a/src/ETW.cpp b/src/ETW.cpp index 42973080..f9aa7b7f 100644 --- a/src/ETW.cpp +++ b/src/ETW.cpp @@ -123,7 +123,7 @@ winstd::event_provider::~event_provider() } -void winstd::event_provider::free_internal() +void winstd::event_provider::free_internal() noexcept { EventUnregister(m_h); } @@ -160,7 +160,7 @@ winstd::event_session::~event_session() } -void winstd::event_session::free_internal() +void winstd::event_session::free_internal() noexcept { ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP); } @@ -197,7 +197,7 @@ winstd::event_trace::~event_trace() } -void winstd::event_trace::free_internal() +void winstd::event_trace::free_internal() noexcept { CloseTrace(m_h); } diff --git a/src/Sec.cpp b/src/Sec.cpp index fa15b314..622c7583 100644 --- a/src/Sec.cpp +++ b/src/Sec.cpp @@ -36,7 +36,7 @@ winstd::sec_credentials::~sec_credentials() } -void winstd::sec_credentials::free_internal() +void winstd::sec_credentials::free_internal() noexcept { FreeCredentialsHandle(m_h); delete m_h; @@ -56,7 +56,7 @@ winstd::sec_context::~sec_context() } -void winstd::sec_context::free_internal() +void winstd::sec_context::free_internal() noexcept { DeleteSecurityContext(m_h); delete m_h; diff --git a/src/SetupAPI.cpp b/src/SetupAPI.cpp index dfd99b88..ba4c80a6 100644 --- a/src/SetupAPI.cpp +++ b/src/SetupAPI.cpp @@ -34,7 +34,7 @@ winstd::setup_device_info_list::~setup_device_info_list() } -void winstd::setup_device_info_list::free_internal() +void winstd::setup_device_info_list::free_internal() noexcept { SetupDiDestroyDeviceInfoList(m_h); } diff --git a/src/WLAN.cpp b/src/WLAN.cpp index 8b0e8bb2..66db76e2 100644 --- a/src/WLAN.cpp +++ b/src/WLAN.cpp @@ -32,7 +32,7 @@ winstd::wlan_handle::~wlan_handle() } -void winstd::wlan_handle::free_internal() +void winstd::wlan_handle::free_internal() noexcept { WlanCloseHandle(m_h, NULL); } diff --git a/src/Win.cpp b/src/Win.cpp index e24fbdaf..cfe42e24 100644 --- a/src/Win.cpp +++ b/src/Win.cpp @@ -25,7 +25,7 @@ // StringToGuidA ////////////////////////////////////////////////////////////////////// -_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd) +_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd) noexcept { GUID g; LPSTR lpszEnd; @@ -44,7 +44,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP ulTmp = strtoul(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE; - g.Data2 = (unsigned short)ulTmp; + g.Data2 = static_cast(ulTmp); lpszGuid = lpszEnd; if (*lpszGuid != '-') return FALSE; @@ -52,7 +52,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP ulTmp = strtoul(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE; - g.Data3 = (unsigned short)ulTmp; + g.Data3 = static_cast(ulTmp); lpszGuid = lpszEnd; if (*lpszGuid != '-') return FALSE; @@ -60,8 +60,8 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP ulTmp = strtoul(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE; - g.Data4[0] = (unsigned char)((ulTmp >> 8) & 0xff); - g.Data4[1] = (unsigned char)( ulTmp & 0xff); + g.Data4[0] = static_cast((ulTmp >> 8) & 0xff); + g.Data4[1] = static_cast( ulTmp & 0xff); lpszGuid = lpszEnd; if (*lpszGuid != '-') return FALSE; @@ -69,12 +69,12 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE; - g.Data4[2] = (unsigned char)((ullTmp >> 40) & 0xff); - g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff); - g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff); - g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff); - g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff); - g.Data4[7] = (unsigned char)( ullTmp & 0xff); + g.Data4[2] = static_cast((ullTmp >> 40) & 0xff); + g.Data4[3] = static_cast((ullTmp >> 32) & 0xff); + g.Data4[4] = static_cast((ullTmp >> 24) & 0xff); + g.Data4[5] = static_cast((ullTmp >> 16) & 0xff); + g.Data4[6] = static_cast((ullTmp >> 8) & 0xff); + g.Data4[7] = static_cast( ullTmp & 0xff); lpszGuid = lpszEnd; if (*lpszGuid != '}') return FALSE; @@ -88,7 +88,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP } -_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd) +_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd) noexcept { GUID g; LPWSTR lpszEnd; @@ -107,7 +107,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L ulTmp = wcstoul(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE; - g.Data2 = (unsigned short)ulTmp; + g.Data2 = static_cast(ulTmp); lpszGuid = lpszEnd; if (*lpszGuid != '-') return FALSE; @@ -115,7 +115,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L ulTmp = wcstoul(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE; - g.Data3 = (unsigned short)ulTmp; + g.Data3 = static_cast(ulTmp); lpszGuid = lpszEnd; if (*lpszGuid != '-') return FALSE; @@ -123,8 +123,8 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L ulTmp = wcstoul(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE; - g.Data4[0] = (unsigned char)((ulTmp >> 8) & 0xff); - g.Data4[1] = (unsigned char)( ulTmp & 0xff); + g.Data4[0] = static_cast((ulTmp >> 8) & 0xff); + g.Data4[1] = static_cast( ulTmp & 0xff); lpszGuid = lpszEnd; if (*lpszGuid != '-') return FALSE; @@ -132,12 +132,12 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16); if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE; - g.Data4[2] = (unsigned char)((ullTmp >> 40) & 0xff); - g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff); - g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff); - g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff); - g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff); - g.Data4[7] = (unsigned char)( ullTmp & 0xff); + g.Data4[2] = static_cast((ullTmp >> 40) & 0xff); + g.Data4[3] = static_cast((ullTmp >> 32) & 0xff); + g.Data4[4] = static_cast((ullTmp >> 24) & 0xff); + g.Data4[5] = static_cast((ullTmp >> 16) & 0xff); + g.Data4[6] = static_cast((ullTmp >> 8) & 0xff); + g.Data4[7] = static_cast( ullTmp & 0xff); lpszGuid = lpszEnd; if (*lpszGuid != '}') return FALSE; @@ -162,7 +162,7 @@ winstd::library::~library() } -void winstd::library::free_internal() +void winstd::library::free_internal() noexcept { FreeLibrary(m_h); } @@ -174,7 +174,11 @@ void winstd::library::free_internal() winstd::critical_section::critical_section() { - InitializeCriticalSection(&m_data); + __try { + InitializeCriticalSection(&m_data); + } __except(EXCEPTION_EXECUTE_HANDLER) { + throw std::runtime_error("InitializeCriticalSection failed"); + } } @@ -196,7 +200,7 @@ winstd::find_file::~find_file() } -void winstd::find_file::free_internal() +void winstd::find_file::free_internal() noexcept { FindClose(m_h); } @@ -215,7 +219,7 @@ winstd::heap::~heap() } -bool winstd::heap::enumerate() +bool winstd::heap::enumerate() noexcept { assert(m_h != invalid); @@ -243,7 +247,7 @@ bool winstd::heap::enumerate() } } - DWORD dwResult = GetLastError(); + const DWORD dwResult = GetLastError(); if (dwResult != ERROR_NO_MORE_ITEMS) OutputDebugStr(_T("HeapWalk failed (error %u).\n"), dwResult); @@ -254,7 +258,7 @@ bool winstd::heap::enumerate() } -void winstd::heap::free_internal() +void winstd::heap::free_internal() noexcept { enumerate(); HeapDestroy(m_h); @@ -265,7 +269,7 @@ void winstd::heap::free_internal() // winstd::actctx_activator ////////////////////////////////////////////////////////////////////// -winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx) +winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx) noexcept { if (!ActivateActCtx(hActCtx, &m_cookie)) m_cookie = 0; @@ -283,7 +287,7 @@ winstd::actctx_activator::~actctx_activator() // winstd::user_impersonator ////////////////////////////////////////////////////////////////////// -winstd::user_impersonator::user_impersonator(_In_opt_ HANDLE hToken) +winstd::user_impersonator::user_impersonator(_In_opt_ HANDLE hToken) noexcept { m_cookie = hToken && ImpersonateLoggedOnUser(hToken); } @@ -300,7 +304,7 @@ winstd::user_impersonator::~user_impersonator() // winstd::console_ctrl_handler ////////////////////////////////////////////////////////////////////// -winstd::console_ctrl_handler::console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) : +winstd::console_ctrl_handler::console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept : m_handler(HandlerRoutine) { m_cookie = SetConsoleCtrlHandler(m_handler, TRUE); @@ -325,7 +329,7 @@ winstd::vmemory::~vmemory() } -void winstd::vmemory::free_internal() +void winstd::vmemory::free_internal() noexcept { VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE); } @@ -342,7 +346,7 @@ winstd::reg_key::~reg_key() } -void winstd::reg_key::free_internal() +void winstd::reg_key::free_internal() noexcept { RegCloseKey(m_h); } @@ -359,7 +363,7 @@ winstd::security_id::~security_id() } -void winstd::security_id::free_internal() +void winstd::security_id::free_internal() noexcept { FreeSid(m_h); } diff --git a/src/WinSock2.cpp b/src/WinSock2.cpp index 3981a3fe..71966512 100644 --- a/src/WinSock2.cpp +++ b/src/WinSock2.cpp @@ -34,7 +34,7 @@ winstd::addrinfo::~addrinfo() } -void winstd::addrinfo::free_internal() +void winstd::addrinfo::free_internal() noexcept { FreeAddrInfo(m_h); } diff --git a/src/WinTrust.cpp b/src/WinTrust.cpp index f40dc872..4043a076 100644 --- a/src/WinTrust.cpp +++ b/src/WinTrust.cpp @@ -30,5 +30,5 @@ winstd::wintrust::~wintrust() { m_wtd.dwStateAction = WTD_STATEACTION_CLOSE; - WinVerifyTrust(m_hwnd, (GUID*)&m_action, &m_wtd); + WinVerifyTrust(m_hwnd, &m_action, &m_wtd); }