Remove deprecated methods

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2022-03-03 10:00:54 +01:00
parent 266996bd67
commit ad76305ce9
7 changed files with 56 additions and 614 deletions

View File

@ -77,23 +77,14 @@ namespace winstd
/// ///
/// COM object wrapper template /// COM object wrapper template
/// ///
/// \sa [CoCreateInstance function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615.aspx)
///
template <class T> template <class T>
class com_obj : public dplhandle<T*, NULL> class com_obj : public dplhandle<T*, NULL>
{ {
WINSTD_DPLHANDLE_IMPL(com_obj, NULL) WINSTD_DPLHANDLE_IMPL(com_obj, NULL)
public: 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 /// Queries the object for another interface and creates new class with it
/// ///
@ -126,21 +117,6 @@ namespace winstd
free_internal(); 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 /// Queries the object for another interface
/// ///

View File

@ -248,6 +248,8 @@ namespace winstd
/// ///
/// PCCERT_CONTEXT wrapper class /// PCCERT_CONTEXT wrapper class
/// ///
/// \sa [CertCreateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376033.aspx)
///
class cert_context : public dplhandle<PCCERT_CONTEXT, NULL> class cert_context : public dplhandle<PCCERT_CONTEXT, NULL>
{ {
WINSTD_DPLHANDLE_IMPL(cert_context, NULL) WINSTD_DPLHANDLE_IMPL(cert_context, NULL)
@ -264,26 +266,6 @@ namespace winstd
free_internal(); 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? /// Is certificate equal to?
/// ///
@ -398,6 +380,8 @@ namespace winstd
/// ///
/// PCCERT_CHAIN_CONTEXT wrapper class /// 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<PCCERT_CHAIN_CONTEXT, NULL> class cert_chain_context : public dplhandle<PCCERT_CHAIN_CONTEXT, NULL>
{ {
WINSTD_DPLHANDLE_IMPL(cert_chain_context, NULL) WINSTD_DPLHANDLE_IMPL(cert_chain_context, NULL)
@ -414,26 +398,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Destroys the certificate chain context. /// Destroys the certificate chain context.
@ -463,6 +427,9 @@ namespace winstd
/// ///
/// HCERTSTORE wrapper class /// 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<HCERTSTORE, NULL> class cert_store : public handle<HCERTSTORE, NULL>
{ {
WINSTD_HANDLE_IMPL(cert_store, NULL) WINSTD_HANDLE_IMPL(cert_store, NULL)
@ -479,46 +446,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Closes the certificate store. /// Closes the certificate store.
@ -534,6 +461,8 @@ namespace winstd
/// ///
/// HCRYPTPROV wrapper class /// HCRYPTPROV wrapper class
/// ///
/// \sa [CryptAcquireContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886.aspx)
///
class crypt_prov : public handle<HCRYPTPROV, NULL> class crypt_prov : public handle<HCRYPTPROV, NULL>
{ {
WINSTD_HANDLE_IMPL(crypt_prov, NULL) WINSTD_HANDLE_IMPL(crypt_prov, NULL)
@ -550,26 +479,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Releases the cryptographic context. /// Releases the cryptographic context.
@ -585,6 +494,8 @@ namespace winstd
/// ///
/// HCRYPTHASH wrapper class /// HCRYPTHASH wrapper class
/// ///
/// \sa [CryptCreateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908.aspx)
///
class crypt_hash : public dplhandle<HCRYPTHASH, NULL> class crypt_hash : public dplhandle<HCRYPTHASH, NULL>
{ {
WINSTD_DPLHANDLE_IMPL(crypt_hash, NULL) WINSTD_DPLHANDLE_IMPL(crypt_hash, NULL)
@ -601,26 +512,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Destroys the hash context. /// Destroys the hash context.
@ -651,6 +542,11 @@ namespace winstd
/// ///
/// HCRYPTKEY wrapper class /// 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<HCRYPTKEY, NULL> class crypt_key : public dplhandle<HCRYPTKEY, NULL>
{ {
WINSTD_DPLHANDLE_IMPL(crypt_key, NULL) WINSTD_DPLHANDLE_IMPL(crypt_key, NULL)
@ -667,70 +563,6 @@ namespace winstd
free_internal(); 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 /// Creates Exponent-of-one key
/// ///

View File

@ -901,6 +901,8 @@ namespace winstd
/// ///
/// ETW trace /// ETW trace
/// ///
/// \sa [OpenTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364089.aspx)
///
class event_trace : public handle<TRACEHANDLE, INVALID_PROCESSTRACE_HANDLE> class event_trace : public handle<TRACEHANDLE, INVALID_PROCESSTRACE_HANDLE>
{ {
WINSTD_HANDLE_IMPL(event_trace, INVALID_PROCESSTRACE_HANDLE) WINSTD_HANDLE_IMPL(event_trace, INVALID_PROCESSTRACE_HANDLE)
@ -917,26 +919,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Closes the trace. /// Closes the trace.

View File

@ -20,6 +20,9 @@ namespace winstd
/// ///
/// HDEVINFO wrapper class /// 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<HDEVINFO, INVALID_HANDLE_VALUE> class setup_device_info_list : public handle<HDEVINFO, INVALID_HANDLE_VALUE>
{ {
WINSTD_HANDLE_IMPL(setup_device_info_list, INVALID_HANDLE_VALUE) WINSTD_HANDLE_IMPL(setup_device_info_list, INVALID_HANDLE_VALUE)
@ -36,57 +39,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Frees the device information set. /// Frees the device information set.

View File

@ -124,6 +124,8 @@ namespace winstd
/// ///
/// WLAN handle wrapper /// WLAN handle wrapper
/// ///
/// \sa [WlanOpenHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706759.aspx)
///
class wlan_handle : public handle<HANDLE, NULL> class wlan_handle : public handle<HANDLE, NULL>
{ {
WINSTD_HANDLE_IMPL(wlan_handle, NULL) WINSTD_HANDLE_IMPL(wlan_handle, NULL)
@ -140,29 +142,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Closes a connection to the server. /// Closes a connection to the server.

View File

@ -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<INVAL>( h ) { } \
C (_Inout_ C &&h) noexcept : win_handle<INVAL>(std::move(h)) { } \
C& operator=(_In_opt_ handle_type h) noexcept { win_handle<INVAL>::operator=( h ); return *this; } \
C& operator=(_Inout_ C &&h) noexcept { win_handle<INVAL>::operator=(std::move(h)); return *this; } \
WINSTD_NONCOPYABLE(C)
/// @copydoc GetModuleFileNameW() /// @copydoc GetModuleFileNameW()
template<class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept
@ -1386,6 +1374,8 @@ namespace winstd
/// ///
/// Module handle wrapper /// Module handle wrapper
/// ///
/// \sa [LoadLibraryEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684179.aspx)
///
class library : public handle<HMODULE, NULL> class library : public handle<HMODULE, NULL>
{ {
WINSTD_HANDLE_IMPL(library, NULL) WINSTD_HANDLE_IMPL(library, NULL)
@ -1402,26 +1392,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Frees the module. /// Frees the module.
@ -1437,31 +1407,9 @@ namespace winstd
/// ///
/// Process handle wrapper /// Process handle wrapper
/// ///
class process : public win_handle<NULL> /// \sa [OpenProcess function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684320.aspx)
{ ///
WINSTD_WINHANDLE_IMPL(process, NULL) typedef win_handle<NULL> process;
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;
}
};
/// ///
/// Thread handle wrapper /// Thread handle wrapper
@ -1480,60 +1428,16 @@ namespace winstd
/// ///
/// File handle wrapper /// File handle wrapper
/// ///
class file : public win_handle<INVALID_HANDLE_VALUE> /// \sa [CreateFile function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx)
{ ///
WINSTD_WINHANDLE_IMPL(file, INVALID_HANDLE_VALUE) typedef win_handle<INVALID_HANDLE_VALUE> file;
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;
}
};
/// ///
/// File mapping /// File mapping
/// ///
class file_mapping : public win_handle<NULL> /// \sa [CreateFileMapping function](https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw)
{ ///
WINSTD_WINHANDLE_IMPL(file_mapping, NULL) typedef win_handle<NULL> file_mapping;
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;
}
};
/// ///
/// Deleter for unique_ptr using UnmapViewOfFile /// Deleter for unique_ptr using UnmapViewOfFile
@ -1597,51 +1501,10 @@ namespace winstd
/// ///
/// Event handle wrapper /// Event handle wrapper
/// ///
class event : public win_handle<NULL> /// \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)
WINSTD_WINHANDLE_IMPL(event, NULL) ///
typedef win_handle<NULL> event;
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;
}
};
/// ///
/// Critical section wrapper /// Critical section wrapper
@ -1693,6 +1556,8 @@ namespace winstd
/// ///
/// Find-file handle wrapper /// 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<HANDLE, INVALID_HANDLE_VALUE> class find_file : public handle<HANDLE, INVALID_HANDLE_VALUE>
{ {
WINSTD_HANDLE_IMPL(find_file, INVALID_HANDLE_VALUE) WINSTD_HANDLE_IMPL(find_file, INVALID_HANDLE_VALUE)
@ -1709,26 +1574,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Closes a file search handle. /// Closes a file search handle.
@ -1744,6 +1589,8 @@ namespace winstd
/// ///
/// Heap handle wrapper /// Heap handle wrapper
/// ///
/// \sa [HeapCreate function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366599.aspx)
///
class heap : public handle<HANDLE, NULL> class heap : public handle<HANDLE, NULL>
{ {
WINSTD_HANDLE_IMPL(heap, NULL) WINSTD_HANDLE_IMPL(heap, NULL)
@ -1760,26 +1607,6 @@ namespace winstd
free_internal(); 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()` /// 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<HKEY, NULL> class reg_key : public handle<HKEY, NULL>
{ {
@ -2201,63 +2031,6 @@ namespace winstd
free_internal(); 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. /// Deletes the specified registry subkey.
/// ///
@ -2393,6 +2166,8 @@ namespace winstd
/// ///
/// Event log handle wrapper /// 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<HANDLE, NULL> class event_log : public handle<HANDLE, NULL>
{ {
WINSTD_HANDLE_IMPL(event_log, NULL) WINSTD_HANDLE_IMPL(event_log, NULL)
@ -2409,26 +2184,6 @@ namespace winstd
free_internal(); 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: protected:
/// ///
/// Closes an event log handle. /// Closes an event log handle.

View File

@ -90,34 +90,17 @@ namespace winstd
/// ///
/// SID wrapper class /// SID wrapper class
/// ///
/// \sa [GetAddrInfoA function](https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo)
///
class addrinfo : public handle<PADDRINFOA, NULL> class addrinfo : public handle<PADDRINFOA, NULL>
{ {
WINSTD_HANDLE_IMPL(addrinfo, NULL) WINSTD_HANDLE_IMPL(addrinfo, NULL)
public: 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 /// 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() virtual ~addrinfo()
{ {
@ -129,7 +112,7 @@ namespace winstd
/// ///
/// Frees address information /// 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 void free_internal() noexcept override
{ {
@ -140,30 +123,13 @@ namespace winstd
/// ///
/// SID wrapper class /// SID wrapper class
/// ///
/// \sa [GetAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfow)
///
class waddrinfo : public handle<PADDRINFOW, NULL> class waddrinfo : public handle<PADDRINFOW, NULL>
{ {
WINSTD_HANDLE_IMPL(waddrinfo, NULL) WINSTD_HANDLE_IMPL(waddrinfo, NULL)
public: 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 /// Frees address information
/// ///