From ad76305ce9448249ab665bfca644a32600457e54 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 3 Mar 2022 10:00:54 +0100 Subject: [PATCH] Remove deprecated methods Signed-off-by: Simon Rozman --- include/WinStd/COM.h | 28 +--- include/WinStd/Crypt.h | 200 +++----------------------- include/WinStd/ETW.h | 22 +-- include/WinStd/SetupAPI.h | 54 +------ include/WinStd/WLAN.h | 25 +--- include/WinStd/Win.h | 295 ++++---------------------------------- include/WinStd/WinSock2.h | 46 +----- 7 files changed, 56 insertions(+), 614 deletions(-) diff --git a/include/WinStd/COM.h b/include/WinStd/COM.h index c6fc14ae..edbfb73e 100644 --- a/include/WinStd/COM.h +++ b/include/WinStd/COM.h @@ -77,23 +77,14 @@ namespace winstd /// /// COM object wrapper template /// + /// \sa [CoCreateInstance function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615.aspx) + /// template class com_obj : public dplhandle { WINSTD_DPLHANDLE_IMPL(com_obj, NULL) public: - /// - /// Constructs a new object and creates a new class with it - /// - /// \sa [CoCreateInstance function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615.aspx) - /// - __declspec(deprecated("Use CoCreateInstance")) - com_obj(_In_ REFCLSID rclsid, _In_opt_ LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) - { - CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (LPVOID*)&m_h); - } - /// /// Queries the object for another interface and creates new class with it /// @@ -126,21 +117,6 @@ namespace winstd free_internal(); } - /// - /// Creates a new object - /// - /// \sa [CoCreateInstance function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615.aspx) - /// - __declspec(deprecated("Use CoCreateInstance")) - HRESULT create(_In_ REFCLSID rclsid, _In_opt_ LPUNKNOWN pUnkOuter = NULL, _In_ DWORD dwClsContext = CLSCTX_ALL) - { - handle_type h; - HRESULT hr = CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&h); - if (SUCCEEDED(hr)) - attach(h); - return hr; - } - /// /// Queries the object for another interface /// diff --git a/include/WinStd/Crypt.h b/include/WinStd/Crypt.h index f96afe86..e15916d3 100644 --- a/include/WinStd/Crypt.h +++ b/include/WinStd/Crypt.h @@ -248,6 +248,8 @@ namespace winstd /// /// PCCERT_CONTEXT wrapper class /// + /// \sa [CertCreateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376033.aspx) + /// class cert_context : public dplhandle { WINSTD_DPLHANDLE_IMPL(cert_context, NULL) @@ -264,26 +266,6 @@ namespace winstd free_internal(); } - /// - /// Creates the certificate context. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [CertCreateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376033.aspx) - /// - __declspec(deprecated("Use CertCreateCertificateContext")) - bool create(_In_ DWORD dwCertEncodingType, _In_ LPCBYTE pbCertEncoded, _In_ DWORD cbCertEncoded) noexcept - { - handle_type h = CertCreateCertificateContext(dwCertEncodingType, pbCertEncoded, cbCertEncoded); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - /// /// Is certificate equal to? /// @@ -398,6 +380,8 @@ namespace winstd /// /// PCCERT_CHAIN_CONTEXT wrapper class /// + /// \sa [CertGetCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376078.aspx) + /// class cert_chain_context : public dplhandle { WINSTD_DPLHANDLE_IMPL(cert_chain_context, NULL) @@ -414,26 +398,6 @@ namespace winstd free_internal(); } - /// - /// Creates the certificate chain context. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [CertGetCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376078.aspx) - /// - __declspec(deprecated("Use CertGetCertificateChain")) - 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)) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Destroys the certificate chain context. @@ -463,6 +427,9 @@ namespace winstd /// /// HCERTSTORE wrapper class /// + /// \sa [CertOpenStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376559.aspx) + /// \sa [CertOpenSystemStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376560.aspx) + /// class cert_store : public handle { WINSTD_HANDLE_IMPL(cert_store, NULL) @@ -479,46 +446,6 @@ namespace winstd free_internal(); } - /// - /// Opens the certificate store. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [CertOpenStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376559.aspx) - /// - __declspec(deprecated("Use CertOpenStore")) - 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) { - attach(h); - return true; - } else - return false; - } - - /// - /// Opens the most common system certificate store. To open certificate stores with more complex requirements, such as file-based or memory-based stores, use `create()`. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [CertOpenSystemStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376560.aspx) - /// - __declspec(deprecated("Use CertOpenSystemStore")) - bool create(_In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_z_ LPCTSTR szSubsystemProtocol) noexcept - { - handle_type h = CertOpenSystemStore(hCryptProv, szSubsystemProtocol); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Closes the certificate store. @@ -534,6 +461,8 @@ namespace winstd /// /// HCRYPTPROV wrapper class /// + /// \sa [CryptAcquireContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886.aspx) + /// class crypt_prov : public handle { WINSTD_HANDLE_IMPL(crypt_prov, NULL) @@ -550,26 +479,6 @@ namespace winstd free_internal(); } - /// - /// Acquires the cryptographic context. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [CryptAcquireContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886.aspx) - /// - __declspec(deprecated("Use CryptAcquireContext")) - 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)) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Releases the cryptographic context. @@ -585,6 +494,8 @@ namespace winstd /// /// HCRYPTHASH wrapper class /// + /// \sa [CryptCreateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908.aspx) + /// class crypt_hash : public dplhandle { WINSTD_DPLHANDLE_IMPL(crypt_hash, NULL) @@ -601,26 +512,6 @@ namespace winstd free_internal(); } - /// - /// Creates the hash context. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [CryptCreateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908.aspx) - /// - __declspec(deprecated("Use CryptCreateHash")) - 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)) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Destroys the hash context. @@ -651,6 +542,11 @@ namespace winstd /// /// HCRYPTKEY wrapper class /// + /// \sa [CryptGenKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379941.aspx) + /// \sa [CryptImportKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380207.aspx) + /// \sa [CryptImportPublicKeyInfo function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380209.aspx) + /// \sa [CryptDeriveKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379916.aspx) + /// class crypt_key : public dplhandle { WINSTD_DPLHANDLE_IMPL(crypt_key, NULL) @@ -667,70 +563,6 @@ namespace winstd free_internal(); } - /// - /// Generates the key. - /// - /// \sa [CryptGenKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379941.aspx) - /// - __declspec(deprecated("Use CryptGenKey")) - bool generate(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ DWORD dwFlags) noexcept - { - handle_type h; - if (CryptGenKey(hProv, Algid, dwFlags, &h)) { - attach(h); - return true; - } else - return false; - } - - /// - /// Imports the key. - /// - /// \sa [CryptImportKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380207.aspx) - /// - __declspec(deprecated("Use CryptImportKey")) - 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)) { - attach(h); - return true; - } else - return false; - } - - /// - /// Imports the public key. - /// - /// \sa [CryptImportPublicKeyInfo function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380209.aspx) - /// - __declspec(deprecated("Use CryptImportPublicKeyInfo")) - 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)) { - attach(h); - return true; - } else - return false; - } - - /// - /// Generates cryptographic session keys derived from a base data value. - /// - /// \sa [CryptDeriveKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379916.aspx) - /// - __declspec(deprecated("Use CryptDeriveKey")) - 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)) { - attach(h); - return true; - } else - return false; - } - /// /// Creates Exponent-of-one key /// diff --git a/include/WinStd/ETW.h b/include/WinStd/ETW.h index 3fe99424..c1bb02d0 100644 --- a/include/WinStd/ETW.h +++ b/include/WinStd/ETW.h @@ -901,6 +901,8 @@ namespace winstd /// /// ETW trace /// + /// \sa [OpenTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364089.aspx) + /// class event_trace : public handle { WINSTD_HANDLE_IMPL(event_trace, INVALID_PROCESSTRACE_HANDLE) @@ -917,26 +919,6 @@ namespace winstd free_internal(); } - /// - /// Opens a real-time trace session or log file for consuming. - /// - /// \return - /// - `ERROR_SUCCESS` when creation succeeds; - /// - error code otherwise. - /// - /// \sa [OpenTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364089.aspx) - /// - __declspec(deprecated("Use OpenTrace")) - bool create(_Inout_ PEVENT_TRACE_LOGFILE Logfile) - { - handle_type h = OpenTrace(Logfile); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Closes the trace. diff --git a/include/WinStd/SetupAPI.h b/include/WinStd/SetupAPI.h index 0182d55e..b96dcc7d 100644 --- a/include/WinStd/SetupAPI.h +++ b/include/WinStd/SetupAPI.h @@ -20,6 +20,9 @@ namespace winstd /// /// HDEVINFO wrapper class /// + /// \sa [SetupDiCreateDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdicreatedeviceinfolist) + /// \sa [SetupDiGetClassDevsExW function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdigetclassdevsexw) + /// class setup_device_info_list : public handle { WINSTD_HANDLE_IMPL(setup_device_info_list, INVALID_HANDLE_VALUE) @@ -36,57 +39,6 @@ namespace winstd free_internal(); } - /// - /// Creates an empty device information set and optionally associates the set with a device setup class and a top-level window. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [SetupDiCreateDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdicreatedeviceinfolist) - /// - __declspec(deprecated("Use SetupDiCreateDeviceInfoList")) - bool create( - _In_opt_ const GUID * ClassGuid, - _In_opt_ HWND hwndParent) noexcept - { - handle_type h = SetupDiCreateDeviceInfoList(ClassGuid, hwndParent); - if (h != invalid) { - attach(h); - return true; - } - else - return false; - } - - /// - /// Creates a device information set that contains requested device information elements for a local or a remote computer. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [SetupDiGetClassDevsExW function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdigetclassdevsexw) - /// - __declspec(deprecated("Use SetupDiGetClassDevsEx")) - bool create( - _In_opt_ const GUID * ClassGuid, - _In_opt_ PCTSTR Enumerator, - _In_opt_ HWND hwndParent, - _In_ DWORD Flags, - _In_opt_ HDEVINFO DeviceInfoSet, - _In_opt_ PCTSTR MachineName, - _Reserved_ PVOID Reserved) noexcept - { - handle_type h = SetupDiGetClassDevsEx(ClassGuid, Enumerator, hwndParent, Flags, DeviceInfoSet, MachineName, Reserved); - if (h != invalid) { - attach(h); - return true; - } - else - return false; - } - protected: /// /// Frees the device information set. diff --git a/include/WinStd/WLAN.h b/include/WinStd/WLAN.h index 246c959a..f2f0aafa 100644 --- a/include/WinStd/WLAN.h +++ b/include/WinStd/WLAN.h @@ -124,6 +124,8 @@ namespace winstd /// /// WLAN handle wrapper /// + /// \sa [WlanOpenHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706759.aspx) + /// class wlan_handle : public handle { WINSTD_HANDLE_IMPL(wlan_handle, NULL) @@ -140,29 +142,6 @@ namespace winstd free_internal(); } - /// - /// Opens a connection to the server. - /// - /// \sa [WlanOpenHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706759.aspx) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use WlanOpenHandle - mind it returns error number rather than SetLastError")) - bool open(_In_ DWORD dwClientVersion, _Out_ PDWORD pdwNegotiatedVersion) noexcept - { - handle_type h; - const DWORD dwResult = WlanOpenHandle(dwClientVersion, 0, pdwNegotiatedVersion, &h); - if (dwResult == ERROR_SUCCESS) { - attach(h); - return true; - } else { - SetLastError(dwResult); - return false; - } - } - protected: /// /// Closes a connection to the server. diff --git a/include/WinStd/Win.h b/include/WinStd/Win.h index f4e1a358..0f57ca4d 100644 --- a/include/WinStd/Win.h +++ b/include/WinStd/Win.h @@ -19,18 +19,6 @@ /// /// @{ -/// -/// Implements default constructors and operators to prevent their auto-generation by compiler. -/// -#define WINSTD_WINHANDLE_IMPL(C, INVAL) \ -public: \ - C ( ) noexcept { } \ - C (_In_opt_ handle_type h) noexcept : win_handle( h ) { } \ - C (_Inout_ C &&h) noexcept : win_handle(std::move(h)) { } \ - C& operator=(_In_opt_ handle_type h) noexcept { win_handle::operator=( h ); return *this; } \ - C& operator=(_Inout_ C &&h) noexcept { win_handle::operator=(std::move(h)); return *this; } \ -WINSTD_NONCOPYABLE(C) - /// @copydoc GetModuleFileNameW() template static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string &sValue) noexcept @@ -1386,6 +1374,8 @@ namespace winstd /// /// Module handle wrapper /// + /// \sa [LoadLibraryEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179.aspx) + /// class library : public handle { WINSTD_HANDLE_IMPL(library, NULL) @@ -1402,26 +1392,6 @@ namespace winstd free_internal(); } - /// - /// Loads the specified module into the address space of the calling process. - /// - /// \sa [LoadLibraryEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179.aspx) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use LoadLibraryEx")) - bool load(_In_z_ LPCTSTR lpFileName, __reserved handle_type hFile, _In_ DWORD dwFlags) noexcept - { - handle_type h = LoadLibraryEx(lpFileName, hFile, dwFlags); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Frees the module. @@ -1437,31 +1407,9 @@ namespace winstd /// /// Process handle wrapper /// - class process : public win_handle - { - WINSTD_WINHANDLE_IMPL(process, NULL) - - public: - /// - /// Opens process handle. - /// - /// \sa [OpenProcess function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320.aspx) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use OpenProcess")) - bool open(_In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_ DWORD dwProcessId) noexcept - { - handle_type h = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - }; + /// \sa [OpenProcess function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320.aspx) + /// + typedef win_handle process; /// /// Thread handle wrapper @@ -1480,60 +1428,16 @@ namespace winstd /// /// File handle wrapper /// - class file : public win_handle - { - WINSTD_WINHANDLE_IMPL(file, INVALID_HANDLE_VALUE) - - public: - /// - /// Opens file handle. - /// - /// \sa [CreateFile function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use CreateFile")) - 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) { - attach(h); - return true; - } else - return false; - } - }; + /// \sa [CreateFile function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx) + /// + typedef win_handle file; /// /// File mapping /// - class file_mapping : public win_handle - { - WINSTD_WINHANDLE_IMPL(file_mapping, NULL) - - public: - /// - /// Creates or opens a named or unnamed file mapping object for a specified file. - /// - /// \sa [CreateFileMapping function](https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use CreateFileMapping")) - bool create(_In_ HANDLE hFile, _In_ DWORD flProtect, _In_ DWORD dwMaximumSizeHigh, _In_ DWORD dwMaximumSizeLow, _In_opt_ LPSECURITY_ATTRIBUTES lpFileMappingAttributes = NULL, _In_opt_ LPCTSTR lpName = NULL) noexcept - { - handle_type h = CreateFileMapping(hFile, lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - }; + /// \sa [CreateFileMapping function](https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw) + /// + typedef win_handle file_mapping; /// /// Deleter for unique_ptr using UnmapViewOfFile @@ -1597,51 +1501,10 @@ namespace winstd /// /// Event handle wrapper /// - class event : public win_handle - { - WINSTD_WINHANDLE_IMPL(event, NULL) - - public: - /// - /// Creates or opens a named or unnamed event object. - /// - /// \sa [CreateEventW function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-createeventw) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use CreateEvent")) - 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) { - attach(h); - return true; - } else - return false; - } - - /// - /// Opens an existing named event object. - /// - /// \sa [OpenEventW function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-openeventw) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use OpenEvent")) - bool open(_In_ DWORD dwDesiredAccess, _In_ BOOL bInheritHandle, _In_z_ LPCTSTR lpName) noexcept - { - handle_type h = OpenEvent(dwDesiredAccess, bInheritHandle, lpName); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - }; + /// \sa [CreateEventW function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-createeventw) + /// \sa [OpenEventW function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-openeventw) + /// + typedef win_handle event; /// /// Critical section wrapper @@ -1693,6 +1556,8 @@ namespace winstd /// /// Find-file handle wrapper /// + /// \sa [FindFirstFile function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilew) + /// class find_file : public handle { WINSTD_HANDLE_IMPL(find_file, INVALID_HANDLE_VALUE) @@ -1709,26 +1574,6 @@ namespace winstd free_internal(); } - /// - /// Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used). - /// - /// \sa [FindFirstFile function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilew) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use FindFirstFile")) - bool find(_In_ LPCTSTR lpFileName, _Out_ LPWIN32_FIND_DATA lpFindFileData) noexcept - { - handle_type h = FindFirstFile(lpFileName, lpFindFileData); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Closes a file search handle. @@ -1744,6 +1589,8 @@ namespace winstd /// /// Heap handle wrapper /// + /// \sa [HeapCreate function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366599.aspx) + /// class heap : public handle { WINSTD_HANDLE_IMPL(heap, NULL) @@ -1760,26 +1607,6 @@ namespace winstd free_internal(); } - /// - /// Creates the heap. - /// - /// \sa [HeapCreate function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366599.aspx) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use HeapCreate")) - bool create(_In_ DWORD flOptions, _In_ SIZE_T dwInitialSize, _In_ SIZE_T dwMaximumSize) noexcept - { - handle_type h = HeapCreate(flOptions, dwInitialSize, dwMaximumSize); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - /// /// Enumerates allocated heap blocks using `OutputDebugString()` /// @@ -2183,7 +2010,10 @@ namespace winstd }; /// - /// Registry wrapper class + /// Registry key wrapper class + /// + /// \sa [RegCreateKeyEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724844.aspx) + /// \sa [RegOpenKeyEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724897.aspx) /// class reg_key : public handle { @@ -2201,63 +2031,6 @@ namespace winstd free_internal(); } - /// - /// Creates the specified registry key. If the key already exists, the function opens it. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [RegCreateKeyEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724844.aspx) - /// - __declspec(deprecated("Use RegCreateKeyEx - mind it returns error number rather than SetLastError")) - bool create( - _In_ HKEY hKey, - _In_z_ LPCTSTR lpSubKey, - _In_opt_ LPTSTR lpClass, - _In_ DWORD dwOptions, - _In_ REGSAM samDesired, - _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL, - _Out_opt_ LPDWORD lpdwDisposition = NULL) noexcept - { - handle_type h; - const LSTATUS s = RegCreateKeyEx(hKey, lpSubKey, 0, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition); - if (s == ERROR_SUCCESS) { - attach(h); - return true; - } else { - SetLastError(s); - return false; - } - } - - /// - /// Opens the specified registry key. - /// - /// \return - /// - true when creation succeeds; - /// - false when creation fails. For extended error information, call `GetLastError()`. - /// - /// \sa [RegOpenKeyEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724897.aspx) - /// - __declspec(deprecated("Use RegOpenKeyEx - mind it returns error number rather than SetLastError")) - bool open( - _In_ HKEY hKey, - _In_opt_z_ LPCTSTR lpSubKey, - _In_ DWORD ulOptions, - _In_ REGSAM samDesired) noexcept - { - handle_type h; - const LSTATUS s = RegOpenKeyEx(hKey, lpSubKey, ulOptions, samDesired, &h); - if (s == ERROR_SUCCESS) { - attach(h); - return true; - } else { - SetLastError(s); - return false; - } - } - /// /// Deletes the specified registry subkey. /// @@ -2393,6 +2166,8 @@ namespace winstd /// /// Event log handle wrapper /// + /// \sa [RegisterEventSource function](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-registereventsourcew) + /// class event_log : public handle { WINSTD_HANDLE_IMPL(event_log, NULL) @@ -2409,26 +2184,6 @@ namespace winstd free_internal(); } - /// - /// Retrieves a registered handle to the specified event log. - /// - /// \sa [RegisterEventSource function](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-registereventsourcew) - /// - /// \return - /// - \c true when succeeds; - /// - \c false when fails. Use `GetLastError()` for failure reason. - /// - __declspec(deprecated("Use RegisterEventSource")) - bool open(_In_z_ LPCTSTR lpUNCServerName, _In_z_ LPCTSTR lpSourceName) noexcept - { - handle_type h = RegisterEventSource(lpUNCServerName, lpSourceName); - if (h != invalid) { - attach(h); - return true; - } else - return false; - } - protected: /// /// Closes an event log handle. diff --git a/include/WinStd/WinSock2.h b/include/WinStd/WinSock2.h index eef088d8..675d7fd7 100644 --- a/include/WinStd/WinSock2.h +++ b/include/WinStd/WinSock2.h @@ -90,34 +90,17 @@ namespace winstd /// /// SID wrapper class /// + /// \sa [GetAddrInfoA function](https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo) + /// class addrinfo : public handle { WINSTD_HANDLE_IMPL(addrinfo, NULL) public: - /// - /// Provides protocol-independent translation from a host name to an address. - /// - /// \sa [GetAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfow) - /// - __declspec(deprecated("Use GetAddrInfoA")) - bool get( - _In_opt_ PCSTR pNodeName, - _In_opt_ PCSTR pServiceName, - _In_opt_ const ADDRINFOA *pHints) - { - handle_type h; - if (GetAddrInfoA(pNodeName, pServiceName, pHints, &h) == 0) { - attach(h); - return true; - } else - return false; - } - /// /// Frees address information /// - /// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow) + /// \sa [FreeAddrInfoA function](https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-freeaddrinfo) /// virtual ~addrinfo() { @@ -129,7 +112,7 @@ namespace winstd /// /// Frees address information /// - /// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow) + /// \sa [FreeAddrInfoA function](https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-freeaddrinfo) /// void free_internal() noexcept override { @@ -140,30 +123,13 @@ namespace winstd /// /// SID wrapper class /// + /// \sa [GetAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfow) + /// class waddrinfo : public handle { WINSTD_HANDLE_IMPL(waddrinfo, NULL) public: - /// - /// Provides protocol-independent translation from a host name to an address. - /// - /// \sa [GetAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfow) - /// - __declspec(deprecated("Use GetAddrInfoW")) - bool get( - _In_opt_ PCWSTR pNodeName, - _In_opt_ PCWSTR pServiceName, - _In_opt_ const ADDRINFOW *pHints) - { - handle_type h; - if (GetAddrInfoW(pNodeName, pServiceName, pHints, &h) == 0) { - attach(h); - return true; - } else - return false; - } - /// /// Frees address information ///