Compare commits

...

2 Commits

Author SHA1 Message Date
9e992db24e Obsolete unnecessary function wrappers
Some checks failed
CodeQL / Analyze (cpp) (push) Has been cancelled
Doxygen Action / build (push) Has been cancelled
Let's keep our codebase minimal.

Signed-off-by: Simon Rozman <simon@rozman.si>
2025-07-08 10:39:40 +02:00
23b856f2e6 Common: Enforce explicit handle validation
Some invalid handle values are -1 or INVALID_HANDLE_VALUE, hence our
handle template has a specific invalid handle value parameter we should
always test against. Time and again, I find my code simply comparing
handle against zero.

Signed-off-by: Simon Rozman <simon@rozman.si>
2025-07-08 10:38:40 +02:00
5 changed files with 26 additions and 1 deletions

View File

@@ -914,6 +914,9 @@ namespace winstd
handle(_In_ const handle<handle_type, INVAL> &h) noexcept {};
handle<handle_type, INVAL>& operator=(_In_ const handle<handle_type, INVAL> &h) noexcept {};
// Force use of valid() method when testing handle.
operator bool() const;
public:
///
/// Attaches already available object handle.

View File

@@ -806,6 +806,7 @@ namespace winstd
///
/// \sa [CertGetCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376078.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL CertGetCertificateChain(_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, _Inout_ winstd::cert_chain_context &ctx)
{
PCCERT_CHAIN_CONTEXT pChainContext;
@@ -816,6 +817,7 @@ static BOOL CertGetCertificateChain(_In_opt_ HCERTCHAINENGINE hChainEngine, _In_
}
/// @copydoc CryptAcquireContextW()
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL CryptAcquireContextA(_Inout_ winstd::crypt_prov &prov, _In_opt_ LPCSTR szContainer, _In_opt_ LPCSTR szProvider, _In_ DWORD dwProvType, _In_ DWORD dwFlags)
{
HCRYPTPROV h;
@@ -830,6 +832,7 @@ static BOOL CryptAcquireContextA(_Inout_ winstd::crypt_prov &prov, _In_opt_ LPCS
///
/// \sa [CryptAcquireContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL CryptAcquireContextW(_Inout_ winstd::crypt_prov &prov, _In_opt_ LPCWSTR szContainer, _In_opt_ LPCWSTR szProvider, _In_ DWORD dwProvType, _In_ DWORD dwFlags)
{
HCRYPTPROV h;
@@ -844,6 +847,7 @@ static BOOL CryptAcquireContextW(_Inout_ winstd::crypt_prov &prov, _In_opt_ LPCW
///
/// \sa [CryptCreateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL CryptCreateHash(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ HCRYPTKEY hKey, _In_ DWORD dwFlags, _Inout_ winstd::crypt_hash &hash)
{
HCRYPTHASH h;
@@ -858,6 +862,7 @@ static BOOL CryptCreateHash(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ HCRYP
///
/// \sa [CryptGenKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379941.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL CryptGenKey(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ DWORD dwFlags, _Inout_ winstd::crypt_key &key)
{
HCRYPTKEY h;
@@ -872,6 +877,7 @@ static BOOL CryptGenKey(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ DWORD dwF
///
/// \sa [CryptImportKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380207.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static bool CryptImportKey(_In_ HCRYPTPROV hProv, __in_bcount(dwDataLen) LPCBYTE pbData, _In_ DWORD dwDataLen, _In_ HCRYPTKEY hPubKey, _In_ DWORD dwFlags, _Inout_ winstd::crypt_key &key)
{
HCRYPTKEY h;
@@ -886,6 +892,7 @@ static bool CryptImportKey(_In_ HCRYPTPROV hProv, __in_bcount(dwDataLen) LPCBYTE
///
/// \sa [CryptImportPublicKeyInfo function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380209.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static bool CryptImportPublicKeyInfo(_In_ HCRYPTPROV hCryptProv, _In_ DWORD dwCertEncodingType, _In_ PCERT_PUBLIC_KEY_INFO pInfo, _Inout_ winstd::crypt_key &key)
{
HCRYPTKEY h;
@@ -900,6 +907,7 @@ static bool CryptImportPublicKeyInfo(_In_ HCRYPTPROV hCryptProv, _In_ DWORD dwCe
///
/// \sa [CryptDeriveKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379916.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static bool CryptDeriveKey(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ HCRYPTHASH hBaseData, _In_ DWORD dwFlags, _Inout_ winstd::crypt_key &key)
{
HCRYPTKEY h;

View File

@@ -163,12 +163,15 @@ namespace winstd
/// \addtogroup WinStdWLANAPI
/// @{
#pragma warning(push)
#pragma warning(disable: 4505) // Don't warn on unused code
///
/// Opens a connection to the server.
///
/// \sa [WlanOpenHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706759.aspx)
///
#pragma warning(suppress: 4505) // Don't warn on unused code
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static DWORD WlanOpenHandle(
_In_ DWORD dwClientVersion,
_Reserved_ PVOID pReserved,
@@ -182,4 +185,6 @@ static DWORD WlanOpenHandle(
return dwResult;
}
#pragma warning(pop)
/// @}

View File

@@ -2054,6 +2054,7 @@ namespace winstd
#pragma warning(disable: 4505) // Don't warn on unused code
/// @copydoc RegCreateKeyExW()
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static LSTATUS RegCreateKeyExA(
_In_ HKEY hKey,
_In_ LPCSTR lpSubKey,
@@ -2077,6 +2078,7 @@ static LSTATUS RegCreateKeyExA(
///
/// \sa [RegCreateKeyEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724844.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static LSTATUS RegCreateKeyExW(
_In_ HKEY hKey,
_In_ LPCWSTR lpSubKey,
@@ -2096,6 +2098,7 @@ static LSTATUS RegCreateKeyExW(
}
/// @copydoc RegOpenKeyExW()
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static LSTATUS RegOpenKeyExA(
_In_ HKEY hKey,
_In_opt_ LPCSTR lpSubKey,
@@ -2115,6 +2118,7 @@ static LSTATUS RegOpenKeyExA(
///
/// \sa [RegOpenKeyEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724897.aspx)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static LSTATUS RegOpenKeyExW(
_In_ HKEY hKey,
_In_opt_ LPCWSTR lpSubKey,
@@ -2134,6 +2138,7 @@ static LSTATUS RegOpenKeyExW(
///
/// \sa [OpenProcessToken function](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocesstoken)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL OpenProcessToken(_In_ HANDLE ProcessHandle, _In_ DWORD DesiredAccess, _Inout_ winstd::win_handle<NULL> &TokenHandle)
{
HANDLE h;
@@ -2149,6 +2154,7 @@ static BOOL OpenProcessToken(_In_ HANDLE ProcessHandle, _In_ DWORD DesiredAccess
///
/// \sa [DuplicateTokenEx function](https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-duplicatetokenex)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL DuplicateTokenEx(_In_ HANDLE hExistingToken, _In_ DWORD dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpTokenAttributes, _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, _In_ TOKEN_TYPE TokenType, _Inout_ winstd::win_handle<NULL> &NewToken)
{
HANDLE h;
@@ -2164,6 +2170,7 @@ static BOOL DuplicateTokenEx(_In_ HANDLE hExistingToken, _In_ DWORD dwDesiredAcc
///
/// \sa [AllocateAndInitializeSid function](https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-allocateandinitializesid)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static BOOL AllocateAndInitializeSid(_In_ PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, _In_ BYTE nSubAuthorityCount, _In_ DWORD nSubAuthority0, _In_ DWORD nSubAuthority1, _In_ DWORD nSubAuthority2, _In_ DWORD nSubAuthority3, _In_ DWORD nSubAuthority4, _In_ DWORD nSubAuthority5, _In_ DWORD nSubAuthority6, _In_ DWORD nSubAuthority7, _Inout_ winstd::security_id& Sid)
{
PSID h;

View File

@@ -187,6 +187,7 @@ namespace winstd
#pragma warning(disable: 4505) // Don't warn on unused code
/// @copydoc GetAddrInfoW()
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static INT GetAddrInfoA(
_In_opt_ PCSTR pNodeName,
_In_opt_ PCSTR pServiceName,
@@ -205,6 +206,7 @@ static INT GetAddrInfoA(
///
/// \sa [GetAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfow)
///
[[deprecated("Use original function and have handle::handle_type* handle::operator&() set the handle")]]
static INT GetAddrInfoW(
_In_opt_ PCWSTR pNodeName,
_In_opt_ PCWSTR pServiceName,