Make code portable

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
2022-02-03 10:53:32 +01:00
parent 7882064e0b
commit 6e34783ed5
33 changed files with 803 additions and 1660 deletions

View File

@@ -159,6 +159,16 @@ namespace winstd
};
/// \cond internal
const char base64_enc::lookup[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
};
/// \endcond
///
/// Base64 decoding session
///
@@ -269,5 +279,28 @@ namespace winstd
/// \endcond
};
/// \cond internal
const unsigned char base64_dec::lookup[256] = {
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
/* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* 2 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
/* 3 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 64, 255, 255,
/* 4 */ 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
/* 5 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
/* 6 */ 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
/* 7 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 255, 255, 255, 255, 255,
/* 8 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* 9 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* A */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* B */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* C */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* D */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* E */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
/* F */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
};
/// \endcond
/// @}
}

View File

@@ -259,7 +259,11 @@ namespace winstd
///
/// \sa [SysFreeString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221481.aspx)
///
virtual ~bstr();
virtual ~bstr()
{
if (m_h != invalid)
SysFreeString(m_h);
}
///
/// Returns the length of the string
@@ -277,7 +281,10 @@ namespace winstd
///
/// \sa [SysFreeString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221481.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
SysFreeString(m_h);
}
///
/// Duplicates the string
@@ -288,7 +295,10 @@ namespace winstd
///
/// \sa [SysAllocString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms221458.aspx)
///
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
{
return SysAllocStringLen(h, SysStringLen(h));
}
};
@@ -522,7 +532,10 @@ namespace winstd
///
/// Destroys VARIANT
///
virtual ~variant();
virtual ~variant()
{
VariantClear(this);
}
///
/// Copy from another VARIANT
@@ -1081,7 +1094,11 @@ namespace winstd
///
/// \sa [CoUninitialize function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms688715.aspx)
///
virtual ~com_initializer();
virtual ~com_initializer()
{
if (SUCCEEDED(m_result))
CoUninitialize();
}
///

View File

@@ -116,7 +116,11 @@ namespace winstd
///
/// \sa [CertFreeCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075.aspx)
///
virtual ~cert_context();
virtual ~cert_context()
{
if (m_h != invalid)
CertFreeCertificateContext(m_h);
}
///
/// Creates the certificate context.
@@ -228,7 +232,10 @@ namespace winstd
///
/// \sa [CertFreeCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CertFreeCertificateContext(m_h);
}
///
/// Duplicates the certificate context.
@@ -239,7 +246,10 @@ namespace winstd
///
/// \sa [CertDuplicateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045.aspx)
///
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
{
return CertDuplicateCertificateContext(h);
}
};
@@ -256,7 +266,11 @@ namespace winstd
///
/// \sa [CertFreeCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073.aspx)
///
virtual ~cert_chain_context();
virtual ~cert_chain_context()
{
if (m_h != invalid)
CertFreeCertificateChain(m_h);
}
///
/// Creates the certificate chain context.
@@ -283,7 +297,10 @@ namespace winstd
///
/// \sa [CertFreeCertificateChain function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CertFreeCertificateChain(m_h);
}
///
/// Duplicates the certificate chain context.
@@ -294,7 +311,10 @@ namespace winstd
///
/// \sa [CertDuplicateCertificateContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045.aspx)
///
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
{
return CertDuplicateCertificateChain(h);
}
};
@@ -311,7 +331,11 @@ namespace winstd
///
/// \sa [CertCloseStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026.aspx)
///
virtual ~cert_store();
virtual ~cert_store()
{
if (m_h != invalid)
CertCloseStore(m_h, 0);
}
///
/// Opens the certificate store.
@@ -357,7 +381,10 @@ namespace winstd
///
/// \sa [CertCloseStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CertCloseStore(m_h, 0);
}
};
@@ -374,7 +401,11 @@ namespace winstd
///
/// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx)
///
virtual ~crypt_prov();
virtual ~crypt_prov()
{
if (m_h != invalid)
CryptReleaseContext(m_h, 0);
}
///
/// Acquires the cryptographic context.
@@ -401,7 +432,10 @@ namespace winstd
///
/// \sa [CryptReleaseContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CryptReleaseContext(m_h, 0);
}
};
@@ -418,7 +452,11 @@ namespace winstd
///
/// \sa [CryptDestroyHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917.aspx)
///
virtual ~crypt_hash();
virtual ~crypt_hash()
{
if (m_h != invalid)
CryptDestroyHash(m_h);
}
///
/// Creates the hash context.
@@ -445,7 +483,10 @@ namespace winstd
///
/// \sa [CryptDestroyHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CryptDestroyHash(m_h);
}
///
/// Duplicates the hash context.
@@ -456,7 +497,11 @@ namespace winstd
///
/// \sa [CryptDuplicateHash function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379919.aspx)
///
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
{
handle_type hNew = invalid;
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : invalid;
}
};
@@ -473,7 +518,11 @@ namespace winstd
///
/// \sa [CryptDestroyKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918.aspx)
///
virtual ~crypt_key();
virtual ~crypt_key()
{
if (m_h != invalid)
CryptDestroyKey(m_h);
}
///
/// Generates the key.
@@ -543,7 +592,67 @@ namespace winstd
/// \param[in] hProv Handle of cryptographics provider to use
/// \param[in] dwKeySpec Key specification (`AT_KEYEXCHANGE` or `AT_SIGNATURE`)
///
bool create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec);
bool create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
{
if (dwKeySpec != AT_KEYEXCHANGE && dwKeySpec != AT_SIGNATURE) {
SetLastError(ERROR_INVALID_PARAMETER);
return false;
}
// Generate the private key.
handle_type h;
if (CryptGenKey(hProv, dwKeySpec, CRYPT_EXPORTABLE, &h)) {
// Export the private key, we'll convert it to a private exponent of one key.
std::vector<BYTE, sanitizing_allocator<BYTE>> key_blob;
if (CryptExportKey(h, 0, PRIVATEKEYBLOB, 0, key_blob)) {
CryptDestroyKey(h);
// Get the byte length of the key.
size_t
size_key = *reinterpret_cast<DWORD*>(&key_blob[12])/8,
size_prime = size_key/2;
// Modify the Exponent in Key BLOB format
// Key BLOB format is documented in SDK
// Convert pubexp in rsapubkey to 1
LPBYTE ptr = &key_blob[16];
*reinterpret_cast<DWORD*>(ptr) = 1;
ptr += sizeof(DWORD);
// Skip modulus, prime1, prime2
ptr += size_key;
ptr += size_prime;
ptr += size_prime;
// Convert exponent1 to 1
ptr[0] = 1;
memset(ptr + 1, 0, size_prime - 1);
ptr += size_prime;
// Convert exponent2 to 1
ptr[0] = 1;
memset(ptr + 1, 0, size_prime - 1);
ptr += size_prime;
// Skip coefficient
ptr += size_prime;
// Convert privateExponent to 1
ptr[0] = 1;
memset(ptr + 1, 0, size_key - 1);
// Import the exponent-of-one private key.
if (CryptImportKey(hProv, key_blob.data(), static_cast<DWORD>(key_blob.size()), 0, 0, &h)) {
attach(h);
return true;
}
} else
CryptDestroyKey(h);
}
return false;
}
protected:
///
@@ -551,7 +660,10 @@ namespace winstd
///
/// \sa [CryptDestroyKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CryptDestroyKey(m_h);
}
///
/// Duplicates the key.
@@ -562,7 +674,11 @@ namespace winstd
///
/// \sa [CryptDuplicateKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379920.aspx)
///
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
{
handle_type hNew = invalid;
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : invalid;
}
};
///
@@ -619,7 +735,11 @@ namespace winstd
///
/// Destroys the BLOB.
///
virtual ~data_blob();
virtual ~data_blob()
{
if (pbData != NULL)
LocalFree(pbData);
}
///
/// Copy an existing BLOB.

View File

@@ -271,7 +271,11 @@ namespace winstd
///
/// Destroys the EAP attribute.
///
~eap_attr();
~eap_attr()
{
if (pValue)
delete [] pValue;
}
///
/// Copies an existing EAP attribute.
@@ -323,13 +327,50 @@ namespace winstd
/// \sa [MS-MPPE-Send-Key](https://tools.ietf.org/html/rfc2548#section-2.4.2)
/// \sa [MS-MPPE-Recv-Key](https://tools.ietf.org/html/rfc2548#section-2.4.3)
///
void create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize);
void create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize)
{
const BYTE nPaddingLength = static_cast<BYTE>((16 - (1 + static_cast<DWORD>(nKeySize))) % 16);
const DWORD dwLengthNew =
4 + // Vendor-Id
1 + // Vendor type
1 + // Vendor length
2 + // Salt
1 + // Key-Length
nKeySize + // Key
nPaddingLength; // Padding
#pragma warning(push)
#pragma warning(disable: 6386)
LPBYTE p = new BYTE[dwLengthNew];
p[0] = 0x00; // Vendor-Id (0x137 = 311 = Microsoft)
p[1] = 0x00; // --|
p[2] = 0x01; // --|
p[3] = 0x37; // --^
p[4] = bVendorType; // Vendor type
p[5] = static_cast<BYTE>(dwLengthNew - 4); // Vendor length
p[6] = 0x00; // Salt
p[7] = 0x00; // --^
p[8] = nKeySize; // Key-Length
#pragma warning(pop)
memcpy(p + 9, pbKey, nKeySize); // Key
memset(p + 9 + nKeySize, 0, nPaddingLength); // Padding
if (pValue)
delete [] pValue;
#pragma warning(suppress: 26812) // EAP_ATTRIBUTE_TYPE is unscoped.
eaType = eatVendorSpecific;
dwLength = dwLengthNew;
pValue = p;
}
public:
static const EAP_ATTRIBUTE blank; ///< Blank EAP attribute
};
#pragma warning(pop)
const EAP_ATTRIBUTE eap_attr::blank = {};
///
/// EAP_METHOD_PROPERTY wrapper class
@@ -394,7 +435,11 @@ namespace winstd
///
/// Destroys the EAP packet.
///
virtual ~eap_packet();
virtual ~eap_packet()
{
if (m_h != invalid)
HeapFree(GetProcessHeap(), 0, m_h);
}
///
@@ -442,12 +487,25 @@ namespace winstd
///
/// Destroys the EAP packet.
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
HeapFree(GetProcessHeap(), 0, m_h);
}
///
/// Duplicates the EAP packet.
///
handle_type duplicate_internal(_In_ handle_type h) const noexcept override;
handle_type duplicate_internal(_In_ handle_type h) const noexcept override
{
const WORD n = ntohs(*reinterpret_cast<WORD*>(h->Length));
handle_type h2 = static_cast<handle_type>(HeapAlloc(GetProcessHeap(), 0, n));
if (h2 == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}
memcpy(h2, h, n);
return h2;
}
};
@@ -484,7 +542,11 @@ namespace winstd
///
/// Destructor
///
~eap_method_info_array();
~eap_method_info_array()
{
if (pEapMethods)
free_internal();
}
///
/// Move assignment
@@ -506,8 +568,24 @@ namespace winstd
protected:
/// \cond internal
void free_internal() noexcept;
static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept;
void free_internal() noexcept
{
for (DWORD i = 0; i < dwNumberOfMethods; i++)
free_internal(pEapMethods + i);
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pEapMethods));
}
static void free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept
{
if (pMethodInfo->pInnerMethodInfo)
free_internal(pMethodInfo->pInnerMethodInfo);
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszAuthorName));
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszFriendlyName));
}
/// \endcond
};

View File

@@ -258,6 +258,8 @@ namespace winstd
static const event_data blank;
};
const event_data event_data::blank;
///
/// EVENT_RECORD wrapper
@@ -312,7 +314,14 @@ namespace winstd
///
/// Destroys event record data and frees the allocated memory.
///
~event_rec();
~event_rec()
{
if (ExtendedData)
delete reinterpret_cast<unsigned char*>(ExtendedData);
if (UserData)
delete reinterpret_cast<unsigned char*>(UserData);
}
///
@@ -371,7 +380,13 @@ namespace winstd
/// \param[in] count \p data size (in number of elements)
/// \param[in] data Record extended data
///
void set_extended_data(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data);
void set_extended_data(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
{
if (ExtendedData)
delete reinterpret_cast<unsigned char*>(ExtendedData);
set_extended_data_internal(count, data);
}
///
@@ -380,7 +395,13 @@ namespace winstd
/// \param[in] size \p data size (in bytes)
/// \param[in] data Record user data
///
void set_user_data(_In_ USHORT size, _In_bytecount_(size) LPCVOID data);
void set_user_data(_In_ USHORT size, _In_bytecount_(size) LPCVOID data)
{
if (UserData)
delete reinterpret_cast<unsigned char*>(UserData);
set_user_data_internal(size, data);
}
protected:
///
@@ -389,7 +410,37 @@ namespace winstd
/// \param[in] count \p data size (in number of elements)
/// \param[in] data Record extended data
///
void set_extended_data_internal(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data);
void set_extended_data_internal(_In_ USHORT count, _In_count_(count) const EVENT_HEADER_EXTENDED_DATA_ITEM *data)
{
if (count) {
assert(data);
// Count the total required memory.
size_t data_size = 0;
for (size_t i = 0; i < count; i++)
data_size += data[i].DataSize;
// Allocate memory for extended data.
ExtendedData = reinterpret_cast<EVENT_HEADER_EXTENDED_DATA_ITEM*>(new unsigned char[sizeof(EVENT_HEADER_EXTENDED_DATA_ITEM)*count + data_size]);
// Bulk-copy extended data descriptors.
memcpy(ExtendedData, data, sizeof(EVENT_HEADER_EXTENDED_DATA_ITEM) * count);
// Copy the data.
unsigned char *ptr = reinterpret_cast<unsigned char*>(ExtendedData + count);
for (size_t i = 0; i < count; i++) {
if (data[i].DataSize) {
memcpy(ptr, (void*)(data[i].DataPtr), data[i].DataSize);
ExtendedData[i].DataPtr = (ULONGLONG)ptr;
ptr += data[i].DataSize;
} else
ExtendedData[i].DataPtr = NULL;
}
} else
ExtendedData = NULL;
ExtendedDataCount = count;
}
///
/// Sets event record user data.
@@ -397,7 +448,21 @@ namespace winstd
/// \param[in] size \p data size (in bytes)
/// \param[in] data Record user data
///
void set_user_data_internal(_In_ USHORT size, _In_bytecount_(size) LPCVOID data);
void set_user_data_internal(_In_ USHORT size, _In_bytecount_(size) LPCVOID data)
{
if (size) {
assert(data);
// Allocate memory for user data.
UserData = new unsigned char[size];
// Copy user data.
memcpy(UserData, data, size);
} else
UserData = NULL;
UserDataLength = size;
}
};
@@ -414,7 +479,11 @@ namespace winstd
///
/// \sa [EventUnregister function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363749.aspx)
///
virtual ~event_provider();
virtual ~event_provider()
{
if (m_h != invalid)
EventUnregister(m_h);
}
///
@@ -599,7 +668,10 @@ namespace winstd
///
/// \sa [EventUnregister function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363749.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
EventUnregister(m_h);
}
///
@@ -607,7 +679,15 @@ namespace winstd
///
/// \sa [EnableCallback callback function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363707.aspx)
///
virtual void enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData);
virtual void enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData)
{
UNREFERENCED_PARAMETER(SourceId);
UNREFERENCED_PARAMETER(IsEnabled);
UNREFERENCED_PARAMETER(Level);
UNREFERENCED_PARAMETER(MatchAnyKeyword);
UNREFERENCED_PARAMETER(MatchAllKeyword);
UNREFERENCED_PARAMETER(FilterData);
}
///
@@ -615,7 +695,13 @@ namespace winstd
///
/// \sa [EnableCallback callback function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363707.aspx)
///
static VOID NTAPI enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _Inout_opt_ PVOID CallbackContext);
static VOID NTAPI enable_callback(_In_ LPCGUID SourceId, _In_ ULONG IsEnabled, _In_ UCHAR Level, _In_ ULONGLONG MatchAnyKeyword, _In_ ULONGLONG MatchAllKeyword, _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData, _Inout_opt_ PVOID CallbackContext)
{
if (CallbackContext)
static_cast<event_provider*>(CallbackContext)->enable_callback(SourceId, IsEnabled, Level, MatchAnyKeyword, MatchAllKeyword, FilterData);
else
assert(0); // Where did the "this" pointer get lost?
}
};
@@ -666,7 +752,11 @@ namespace winstd
///
/// \sa [ControlTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363696.aspx)
///
virtual ~event_session();
virtual ~event_session()
{
if (m_h != invalid)
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
}
///
@@ -799,7 +889,10 @@ namespace winstd
///
/// \sa [ControlTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363696.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
}
protected:
std::unique_ptr<EVENT_TRACE_PROPERTIES> m_prop; ///< Session properties
@@ -819,7 +912,11 @@ namespace winstd
///
/// \sa [CloseTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363686.aspx)
///
virtual ~event_trace();
virtual ~event_trace()
{
if (m_h != invalid)
CloseTrace(m_h);
}
///
@@ -847,7 +944,10 @@ namespace winstd
///
/// \sa [CloseTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363686.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
CloseTrace(m_h);
}
};
@@ -944,7 +1044,20 @@ namespace winstd
///
/// \sa [EnableTraceEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363711.aspx)
///
virtual ~event_trace_enabler();
virtual ~event_trace_enabler()
{
if (m_status == ERROR_SUCCESS)
EnableTraceEx(
m_provider_id,
m_source_id,
m_trace_handle,
EVENT_CONTROL_CODE_DISABLE_PROVIDER,
m_level,
m_match_any_keyword,
m_match_all_keyword,
m_enable_property,
m_enable_filter_desc);
}
protected:
ULONG m_status; ///< Result of EnableTraceEx call

View File

@@ -73,7 +73,11 @@ namespace winstd
///
/// \sa [DeleteDC function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc)
///
virtual ~dc();
virtual ~dc()
{
if (m_h != invalid)
DeleteDC(m_h);
}
protected:
///
@@ -81,7 +85,10 @@ namespace winstd
///
/// \sa [DeleteDC function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
DeleteDC(m_h);
}
};
@@ -120,7 +127,11 @@ namespace winstd
///
/// \sa [ReleaseDC function](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc)
///
virtual ~window_dc();
virtual ~window_dc()
{
if (m_h != invalid)
ReleaseDC(m_hwnd, m_h);
}
protected:
///
@@ -128,7 +139,10 @@ namespace winstd
///
/// \sa [ReleaseDC function](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-releasedc)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
ReleaseDC(m_hwnd, m_h);
}
protected:
HWND m_hwnd; ///< Window handle
@@ -161,7 +175,11 @@ namespace winstd
///
/// \sa [SelectObject function](https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject)
///
virtual ~dc_selector();
virtual ~dc_selector()
{
if (m_orig)
SelectObject(m_hdc, m_orig);
}
///

View File

@@ -90,7 +90,13 @@ namespace winstd
///
/// \sa [FreeCredentialsHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375417.aspx)
///
virtual ~sec_credentials();
virtual ~sec_credentials()
{
if (m_h != invalid) {
FreeCredentialsHandle(m_h);
delete m_h;
}
}
///
/// Move assignment
@@ -141,7 +147,11 @@ namespace winstd
///
/// \sa [FreeCredentialsHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375417.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
FreeCredentialsHandle(m_h);
delete m_h;
}
public:
TimeStamp m_expires; ///< Credentials expiration time
@@ -181,7 +191,13 @@ namespace winstd
///
/// \sa [DeleteSecurityContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375354.aspx)
///
virtual ~sec_context();
virtual ~sec_context()
{
if (m_h != invalid) {
DeleteSecurityContext(m_h);
delete m_h;
}
}
///
/// Move assignment
@@ -256,7 +272,11 @@ namespace winstd
///
/// \sa [DeleteSecurityContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375354.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
DeleteSecurityContext(m_h);
delete m_h;
}
public:
ULONG m_attrib; ///< Context attributes
@@ -285,7 +305,13 @@ namespace winstd
///
/// \sa [FreeContextBuffer function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375416.aspx)
///
virtual ~sec_buffer_desc();
virtual ~sec_buffer_desc()
{
for (ULONG i = 0; i < cBuffers; i++) {
if (pBuffers[i].pvBuffer)
FreeContextBuffer(pBuffers[i].pvBuffer);
}
}
};
/// @}

View File

@@ -41,7 +41,11 @@ namespace winstd
///
/// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist)
///
virtual ~setup_device_info_list();
virtual ~setup_device_info_list()
{
if (m_h != invalid)
SetupDiDestroyDeviceInfoList(m_h);
}
///
/// Creates an empty device information set and optionally associates the set with a device setup class and a top-level window.
@@ -98,7 +102,10 @@ namespace winstd
///
/// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
SetupDiDestroyDeviceInfoList(m_h);
}
};
@@ -132,7 +139,11 @@ namespace winstd
///
/// \sa [SetupDiDestroyDriverInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydriverinfolist)
///
virtual ~setup_driver_info_list_builder();
virtual ~setup_driver_info_list_builder()
{
if (m_result)
SetupDiDestroyDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
}
///

View File

@@ -120,7 +120,11 @@ namespace winstd
///
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
///
virtual ~wlan_handle();
virtual ~wlan_handle()
{
if (m_h != invalid)
WlanCloseHandle(m_h, NULL);
}
///
/// Opens a connection to the server.
@@ -150,7 +154,10 @@ namespace winstd
///
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
WlanCloseHandle(m_h, NULL);
}
};
/// @}

View File

@@ -96,7 +96,7 @@ template<class _Elem, class _Traits, class _Ax> inline VOID GuidToStringW(_In_ L
#endif
/// @copydoc StringToGuidW()
_Success_(return) BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL) noexcept;
_Success_(return) static BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL) noexcept;
///
/// Parses string with GUID and stores it to GUID
@@ -109,7 +109,7 @@ _Success_(return) BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid
/// - `TRUE` if GUID successfuly parsed;
/// - `FALSE` otherwise.
///
_Success_(return) BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL) noexcept;
_Success_(return) static BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL) noexcept;
/// @copydoc StringToGuidW()
#ifdef _UNICODE
@@ -429,7 +429,11 @@ namespace winstd
///
/// \sa [FreeLibrary function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683152.aspx)
///
virtual ~library();
virtual ~library()
{
if (m_h != invalid)
FreeLibrary(m_h);
}
///
/// Loads the specified module into the address space of the calling process.
@@ -456,7 +460,10 @@ namespace winstd
///
/// \sa [FreeLibrary function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683152.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
FreeLibrary(m_h);
}
};
@@ -574,14 +581,24 @@ namespace winstd
///
/// \sa [InitializeCriticalSection function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-initializecriticalsection)
///
critical_section();
critical_section()
{
__try {
InitializeCriticalSection(&m_data);
} __except(EXCEPTION_EXECUTE_HANDLER) {
throw std::runtime_error("InitializeCriticalSection failed");
}
}
///
/// Releases all resources used by an unowned critical section object.
///
/// \sa [DeleteCriticalSection function](https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-deletecriticalsection)
///
virtual ~critical_section();
virtual ~critical_section()
{
DeleteCriticalSection(&m_data);
}
///
/// Auto-typecasting operator
@@ -611,7 +628,12 @@ namespace winstd
///
/// \sa [FindClose function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findclose)
///
virtual ~find_file();
virtual ~find_file()
{
if (m_h != invalid) {
FindClose(m_h);
}
}
///
/// Searches a directory for a file or subdirectory with a name that matches a specific name (or partial name if wildcards are used).
@@ -638,7 +660,10 @@ namespace winstd
///
/// \sa [FindClose function](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findclose)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
FindClose(m_h);
}
};
@@ -655,7 +680,13 @@ namespace winstd
///
/// \sa [HeapDestroy function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366700.aspx)
///
virtual ~heap();
virtual ~heap()
{
if (m_h != invalid) {
enumerate();
HeapDestroy(m_h);
}
}
///
/// Creates the heap.
@@ -683,7 +714,43 @@ namespace winstd
/// - `true` if any blocks found;
/// - `false` otherwise.
///
bool enumerate() noexcept;
bool enumerate() noexcept
{
assert(m_h != invalid);
bool found = false;
// Lock the heap for exclusive access.
HeapLock(m_h);
PROCESS_HEAP_ENTRY e;
e.lpData = NULL;
while (HeapWalk(m_h, &e) != FALSE) {
if ((e.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
OutputDebugStr(
_T("Allocated block%s%s\n")
_T(" Data portion begins at: %#p\n Size: %d bytes\n")
_T(" Overhead: %d bytes\n Region index: %d\n"),
(e.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0 ? tstring_printf(_T(", movable with HANDLE %#p"), e.Block.hMem).c_str() : _T(""),
(e.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0 ? _T(", DDESHARE") : _T(""),
e.lpData,
e.cbData,
e.cbOverhead,
e.iRegionIndex);
found = true;
}
}
const DWORD dwResult = GetLastError();
if (dwResult != ERROR_NO_MORE_ITEMS)
OutputDebugStr(_T("HeapWalk failed (error %u).\n"), dwResult);
// Unlock the heap.
HeapUnlock(m_h);
return found;
}
protected:
///
@@ -691,7 +758,11 @@ namespace winstd
///
/// \sa [HeapDestroy function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366700.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
enumerate();
HeapDestroy(m_h);
}
};
@@ -828,14 +899,22 @@ namespace winstd
///
/// \sa [ActivateActCtx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374151.aspx)
///
actctx_activator(_In_ HANDLE hActCtx) noexcept;
actctx_activator(_In_ HANDLE hActCtx) noexcept
{
if (!ActivateActCtx(hActCtx, &m_cookie))
m_cookie = 0;
}
///
/// Deactivates activation context and destructs the activator
///
/// \sa [DeactivateActCtx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375140.aspx)
///
virtual ~actctx_activator();
virtual ~actctx_activator()
{
if (m_cookie)
DeactivateActCtx(0, m_cookie);
}
protected:
ULONG_PTR m_cookie; ///< Cookie for context deactivation
@@ -858,14 +937,21 @@ namespace winstd
///
/// \sa [ImpersonateLoggedOnUser function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa378612.aspx)
///
user_impersonator(_In_opt_ HANDLE hToken) noexcept;
user_impersonator(_In_opt_ HANDLE hToken) noexcept
{
m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
}
///
/// Reverts to current user and destructs the impersonator
///
/// \sa [RevertToSelf function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379317.aspx)
///
virtual ~user_impersonator();
virtual ~user_impersonator()
{
if (m_cookie)
RevertToSelf();
}
protected:
BOOL m_cookie; ///< Did impersonation succeed?
@@ -888,14 +974,21 @@ namespace winstd
///
/// \sa [SetConsoleCtrlHandler function](https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler)
///
console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept;
console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept : m_handler(HandlerRoutine)
{
m_cookie = SetConsoleCtrlHandler(m_handler, TRUE);
}
///
/// Pops console control handler from the console control handler stack
///
/// \sa [SetConsoleCtrlHandler function](https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler)
///
virtual ~console_ctrl_handler();
virtual ~console_ctrl_handler()
{
if (m_cookie)
SetConsoleCtrlHandler(m_handler, FALSE);
}
protected:
BOOL m_cookie; ///< Did pushing the console control handler succeed?
@@ -946,7 +1039,11 @@ namespace winstd
///
/// \sa [VirtualFreeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366894.aspx)
///
virtual ~vmemory();
virtual ~vmemory()
{
if (m_h != invalid)
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
}
///
/// Move assignment
@@ -1008,7 +1105,10 @@ namespace winstd
///
/// \sa [VirtualFreeEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366894.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
}
protected:
HANDLE m_proc; ///< Handle of memory's process
@@ -1028,7 +1128,11 @@ namespace winstd
///
/// \sa [RegCloseKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724837.aspx)
///
virtual ~reg_key();
virtual ~reg_key()
{
if (m_h != invalid)
RegCloseKey(m_h);
}
///
/// Creates the specified registry key. If the key already exists, the function opens it.
@@ -1094,7 +1198,41 @@ namespace winstd
/// - true when creation succeeds;
/// - false when creation fails. For extended error information, call `GetLastError()`.
///
bool delete_subkey(_In_z_ LPCTSTR szSubkey);
bool delete_subkey(_In_z_ LPCTSTR szSubkey)
{
LSTATUS s;
s = RegDeleteKey(m_h, szSubkey);
if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
return true;
{
reg_key k;
if (!k.open(m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS))
return false;
for (;;) {
TCHAR szName[MAX_PATH];
DWORD dwSize = _countof(szName);
s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
if (s == ERROR_SUCCESS)
k.delete_subkey(szName);
else if (s == ERROR_NO_MORE_ITEMS)
break;
else {
SetLastError(s);
return false;
}
}
}
s = RegDeleteKey(m_h, szSubkey);
if (s == ERROR_SUCCESS)
return true;
else {
SetLastError(s);
return false;
}
}
protected:
///
@@ -1102,7 +1240,10 @@ namespace winstd
///
/// \sa [RegCloseKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724837.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
RegCloseKey(m_h);
}
};
@@ -1119,7 +1260,11 @@ namespace winstd
///
/// \sa [FreeSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa446631.aspx)
///
virtual ~security_id();
virtual ~security_id()
{
if (m_h != invalid)
FreeSid(m_h);
}
protected:
///
@@ -1127,7 +1272,10 @@ namespace winstd
///
/// \sa [FreeSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa446631.aspx)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
FreeSid(m_h);
}
};
@@ -1389,6 +1537,132 @@ inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T
}
_Success_(return) static BOOL StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd) noexcept
{
GUID g;
LPSTR lpszEnd;
unsigned long ulTmp;
unsigned long long ullTmp;
if (!lpszGuid || !lpGuid || *lpszGuid != '{') return FALSE;
lpszGuid++;
g.Data1 = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE) return FALSE;
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data2 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data3 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '}') return FALSE;
lpszGuid++;
if (lpszGuidEnd)
*lpszGuidEnd = lpszGuid;
*lpGuid = g;
return TRUE;
}
_Success_(return) static BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd) noexcept
{
GUID g;
LPWSTR lpszEnd;
unsigned long ulTmp;
unsigned long long ullTmp;
if (!lpszGuid || !lpGuid || *lpszGuid != '{') return FALSE;
lpszGuid++;
g.Data1 = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE) return FALSE;
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data2 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data3 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
lpszGuid++;
ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '}') return FALSE;
lpszGuid++;
if (lpszGuidEnd)
*lpszGuidEnd = lpszGuid;
*lpGuid = g;
return TRUE;
}
template<class _Elem, class _Traits, class _Ax>
inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept
{

View File

@@ -135,7 +135,12 @@ namespace winstd
///
/// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow)
///
virtual ~addrinfo();
virtual ~addrinfo()
{
if (m_h != invalid)
FreeAddrInfo(m_h);
}
protected:
///
@@ -143,7 +148,10 @@ namespace winstd
///
/// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow)
///
void free_internal() noexcept override;
void free_internal() noexcept override
{
FreeAddrInfo(m_h);
}
};
#endif

View File

@@ -53,7 +53,11 @@ namespace winstd
///
/// Destroys the WinTrust context.
///
virtual ~wintrust();
virtual ~wintrust()
{
m_wtd.dwStateAction = WTD_STATEACTION_CLOSE;
WinVerifyTrust(m_hwnd, &m_action, &m_wtd);
}
protected:
HWND m_hwnd;