Use explicit char/wchar_t type for ...A/W Win32 API

Using template type for string type could potentially allow mixup of
MBCS and UCS-2/UTF-16 strings. Fortunately, MSVC errors where char*/
wchar_t* are not aligned with LPSTR/LPWSTR.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2022-02-04 09:54:01 +01:00
parent 04c2f9b9c3
commit e513782854
7 changed files with 223 additions and 223 deletions

View File

@ -33,28 +33,28 @@ namespace winstd
static BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr<PCREDENTIAL[], winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials) noexcept; static BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr<PCREDENTIAL[], winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials) noexcept;
/// @copydoc CredProtectW() /// @copydoc CredProtectW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType); static BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType);
/// ///
/// Encrypts the specified credentials so that only the current security context can decrypt them. /// Encrypts the specified credentials so that only the current security context can decrypt them.
/// ///
/// \sa [CredProtect function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374803.aspx) /// \sa [CredProtect function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374803.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType); static BOOL CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType);
/// @copydoc CredUnprotectW() /// @copydoc CredUnprotectW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials); static BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sCredentials);
/// ///
/// Decrypts credentials that were previously encrypted by using the CredProtect function. /// Decrypts credentials that were previously encrypted by using the CredProtect function.
/// ///
/// \sa [CredUnprotect function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375186.aspx) /// \sa [CredUnprotect function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa375186.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials); static BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sCredentials);
/// @} /// @}
@ -149,10 +149,10 @@ static BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ D
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType) static BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType)
{ {
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char buf[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(buf); DWORD dwSize = _countof(buf);
// Try with the stack buffer first. // Try with the stack buffer first.
@ -162,7 +162,7 @@ static BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR ps
return TRUE; return TRUE;
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]); std::unique_ptr<char[]> buf(new char[dwSize]);
if (CredProtectA(fAsSelf, const_cast<LPSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) { if (CredProtectA(fAsSelf, const_cast<LPSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
sProtectedCredentials.assign(buf.get(), dwSize - 1); sProtectedCredentials.assign(buf.get(), dwSize - 1);
return TRUE; return TRUE;
@ -173,10 +173,10 @@ static BOOL CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR ps
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType) static BOOL CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType)
{ {
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t buf[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(buf); DWORD dwSize = _countof(buf);
// Try with the stack buffer first. // Try with the stack buffer first.
@ -186,7 +186,7 @@ static BOOL CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR p
return TRUE; return TRUE;
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]); std::unique_ptr<wchar_t[]> buf(new wchar_t[dwSize]);
if (CredProtectW(fAsSelf, const_cast<LPWSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) { if (CredProtectW(fAsSelf, const_cast<LPWSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
sProtectedCredentials.assign(buf.get(), dwSize - 1); sProtectedCredentials.assign(buf.get(), dwSize - 1);
return TRUE; return TRUE;
@ -197,10 +197,10 @@ static BOOL CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR p
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials) static BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sCredentials)
{ {
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char buf[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(buf); DWORD dwSize = _countof(buf);
// Try with the stack buffer first. // Try with the stack buffer first.
@ -210,7 +210,7 @@ static BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR
return TRUE; return TRUE;
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]); std::unique_ptr<char[]> buf(new char[dwSize]);
if (CredUnprotectA(fAsSelf, const_cast<LPSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) { if (CredUnprotectA(fAsSelf, const_cast<LPSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
sCredentials.assign(buf.get(), dwSize); sCredentials.assign(buf.get(), dwSize);
return TRUE; return TRUE;
@ -221,10 +221,10 @@ static BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials) static BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sCredentials)
{ {
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t buf[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(buf); DWORD dwSize = _countof(buf);
// Try with the stack buffer first. // Try with the stack buffer first.
@ -234,7 +234,7 @@ static BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR
return TRUE; return TRUE;
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]); std::unique_ptr<wchar_t[]> buf(new wchar_t[dwSize]);
if (CredUnprotectW(fAsSelf, const_cast<LPWSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) { if (CredUnprotectW(fAsSelf, const_cast<LPWSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
sCredentials.assign(buf.get(), dwSize); sCredentials.assign(buf.get(), dwSize);
return TRUE; return TRUE;

View File

@ -31,16 +31,16 @@ namespace winstd
/// @{ /// @{
/// @copydoc CertGetNameStringW() /// @copydoc CertGetNameStringW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sNameString); static DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<char, _Traits, _Ax> &sNameString);
/// ///
/// Obtains the subject or issuer name from a certificate [CERT_CONTEXT](https://msdn.microsoft.com/en-us/library/windows/desktop/aa377189.aspx) structure and stores it in a std::wstring string. /// Obtains the subject or issuer name from a certificate [CERT_CONTEXT](https://msdn.microsoft.com/en-us/library/windows/desktop/aa377189.aspx) structure and stores it in a std::wstring string.
/// ///
/// \sa [CertGetNameString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086.aspx) /// \sa [CertGetNameString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sNameString); static DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sNameString);
/// ///
/// Retrieves the information contained in an extended property of a certificate context. /// Retrieves the information contained in an extended property of a certificate context.
@ -817,28 +817,28 @@ namespace winstd
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sNameString) static DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<char, _Traits, _Ax> &sNameString)
{ {
// Query the final string length first. // Query the final string length first.
DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0); DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize]); std::unique_ptr<char[]> szBuffer(new char[dwSize]);
dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize); dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize);
sNameString.assign(szBuffer.get(), dwSize - 1); sNameString.assign(szBuffer.get(), dwSize - 1);
return dwSize; return dwSize;
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sNameString) static DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_opt_ void *pvTypePara, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sNameString)
{ {
// Query the final string length first. // Query the final string length first.
DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0); DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[dwSize]);
dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize); dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize);
sNameString.assign(szBuffer.get(), dwSize - 1); sNameString.assign(szBuffer.get(), dwSize - 1);
return dwSize; return dwSize;

View File

@ -20,40 +20,40 @@
/// @{ /// @{
/// @copydoc MsiGetPropertyW() /// @copydoc MsiGetPropertyW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue);
/// ///
/// Gets the value for an installer property and stores it in a std::wstring string. /// Gets the value for an installer property and stores it in a std::wstring string.
/// ///
/// \sa [MsiGetProperty function](https://msdn.microsoft.com/en-us/library/aa370134.aspx) /// \sa [MsiGetProperty function](https://msdn.microsoft.com/en-us/library/aa370134.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue);
/// @copydoc MsiRecordGetStringW() /// @copydoc MsiRecordGetStringW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue);
/// ///
/// Returns the string value of a record field and stores it in a std::wstring string. /// Returns the string value of a record field and stores it in a std::wstring string.
/// ///
/// \sa [MsiRecordGetString function](https://msdn.microsoft.com/en-us/library/aa370368.aspx) /// \sa [MsiRecordGetString function](https://msdn.microsoft.com/en-us/library/aa370368.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue);
/// @copydoc MsiFormatRecordW() /// @copydoc MsiFormatRecordW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue);
/// ///
/// Formats record field data and properties using a format string and stores it in a std::wstring string. /// Formats record field data and properties using a format string and stores it in a std::wstring string.
/// ///
/// \sa [MsiFormatRecord function](https://msdn.microsoft.com/en-us/library/aa370109.aspx) /// \sa [MsiFormatRecord function](https://msdn.microsoft.com/en-us/library/aa370109.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue);
/// ///
/// Reads bytes from a record stream field into a std::vector buffer. /// Reads bytes from a record stream field into a std::vector buffer.
@ -64,40 +64,40 @@ template<class _Ty, class _Ax>
static UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::vector<_Ty, _Ax> &binData); static UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::vector<_Ty, _Ax> &binData);
/// @copydoc MsiGetTargetPathW() /// @copydoc MsiGetTargetPathW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue);
/// ///
/// Returns the full target path for a folder in the Directory table and stores it in a std::wstring string. /// Returns the full target path for a folder in the Directory table and stores it in a std::wstring string.
/// ///
/// \sa [MsiGetTargetPath function](https://msdn.microsoft.com/en-us/library/aa370303.aspx) /// \sa [MsiGetTargetPath function](https://msdn.microsoft.com/en-us/library/aa370303.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue);
/// @copydoc MsiGetComponentPathW() /// @copydoc MsiGetComponentPathW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue);
/// ///
/// Returns the full path to an installed component. If the key path for the component is a registry key then the registry key is returned. /// Returns the full path to an installed component. If the key path for the component is a registry key then the registry key is returned.
/// ///
/// \sa [MsiGetComponentPath function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa370112.aspx) /// \sa [MsiGetComponentPath function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa370112.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue); static INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue);
/// @} /// @}
#pragma once #pragma once
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -109,7 +109,7 @@ static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inou
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to read the string data into and read it. // Allocate buffer on heap to read the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<char[]> szBuffer(new char[++dwSize]);
uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer.get(), &dwSize); uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -120,10 +120,10 @@ static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inou
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -135,7 +135,7 @@ static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Ino
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to read the string data into and read it. // Allocate buffer on heap to read the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[++dwSize]);
uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer.get(), &dwSize); uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -146,12 +146,12 @@ static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Ino
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -163,7 +163,7 @@ static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to read the string data into and read it. // Allocate buffer on heap to read the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<char[]> szBuffer(new char[++dwSize]);
uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer.get(), &dwSize); uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -174,10 +174,10 @@ static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -189,7 +189,7 @@ static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to read the string data into and read it. // Allocate buffer on heap to read the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[++dwSize]);
uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer.get(), &dwSize); uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -200,12 +200,12 @@ static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -217,7 +217,7 @@ static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _I
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<char[]> szBuffer(new char[++dwSize]);
uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer.get(), &dwSize); uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -228,10 +228,10 @@ static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _I
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -243,7 +243,7 @@ static UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _I
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[++dwSize]);
uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer.get(), &dwSize); uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -274,12 +274,12 @@ static UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Out_ std::basic_string<char, _Traits, _Ax> &sValue)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -291,7 +291,7 @@ static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<char[]> szBuffer(new char[++dwSize]);
uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer.get(), &dwSize); uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -302,10 +302,10 @@ static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
UINT uiResult; UINT uiResult;
@ -317,7 +317,7 @@ static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder,
return ERROR_SUCCESS; return ERROR_SUCCESS;
} else if (uiResult == ERROR_MORE_DATA) { } else if (uiResult == ERROR_MORE_DATA) {
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[++dwSize]);
uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer.get(), &dwSize); uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0); sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
return uiResult; return uiResult;
@ -328,10 +328,10 @@ static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder,
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
INSTALLSTATE state; INSTALLSTATE state;
@ -343,7 +343,7 @@ static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR
return state; return state;
} else if (state == INSTALLSTATE_MOREDATA) { } else if (state == INSTALLSTATE_MOREDATA) {
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<char[]> szBuffer(new char[++dwSize]);
state = ::MsiGetComponentPathA(szProduct, szComponent, szBuffer.get(), &dwSize); state = ::MsiGetComponentPathA(szProduct, szComponent, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0); sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
return state; return state;
@ -354,10 +354,10 @@ static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue) static INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
INSTALLSTATE state; INSTALLSTATE state;
@ -369,7 +369,7 @@ static INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWST
return state; return state;
} else if (state == INSTALLSTATE_MOREDATA) { } else if (state == INSTALLSTATE_MOREDATA) {
// Allocate buffer on heap to format the string data into and read it. // Allocate buffer on heap to format the string data into and read it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[++dwSize]);
state = ::MsiGetComponentPathW(szProduct, szComponent, szBuffer.get(), &dwSize); state = ::MsiGetComponentPathW(szProduct, szComponent, szBuffer.get(), &dwSize);
sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0); sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
return state; return state;

View File

@ -29,16 +29,16 @@ namespace winstd
/// @{ /// @{
/// @copydoc GetUserNameExW() /// @copydoc GetUserNameExW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName); static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<char, _Traits, _Ax> &sName);
/// ///
/// Retrieves the name of the user or other security principal associated with the calling thread and stores it in a std::wstring string. /// Retrieves the name of the user or other security principal associated with the calling thread and stores it in a std::wstring string.
/// ///
/// \sa [GetUserNameEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435.aspx) /// \sa [GetUserNameEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName); static BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sName);
#endif #endif
@ -370,12 +370,12 @@ namespace winstd
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) #if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL)
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName) static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<char, _Traits, _Ax> &sName)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
ULONG ulSize = _countof(szStackBuffer); ULONG ulSize = _countof(szStackBuffer);
// Try with stack buffer first. // Try with stack buffer first.
@ -386,7 +386,7 @@ static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std:
} else { } else {
if (::GetLastError() == ERROR_MORE_DATA) { if (::GetLastError() == ERROR_MORE_DATA) {
// Allocate buffer on heap and retry. // Allocate buffer on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[ulSize]); std::unique_ptr<char[]> szBuffer(new char[ulSize]);
if (::GetUserNameExA(NameFormat, szBuffer.get(), &ulSize)) { if (::GetUserNameExA(NameFormat, szBuffer.get(), &ulSize)) {
sName.assign(szBuffer.get(), ulSize); sName.assign(szBuffer.get(), ulSize);
return TRUE; return TRUE;
@ -398,12 +398,12 @@ static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std:
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName) static BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sName)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
ULONG ulSize = _countof(szStackBuffer); ULONG ulSize = _countof(szStackBuffer);
// Try with stack buffer first. // Try with stack buffer first.
@ -414,7 +414,7 @@ static BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std:
} else { } else {
if (::GetLastError() == ERROR_MORE_DATA) { if (::GetLastError() == ERROR_MORE_DATA) {
// Allocate buffer on heap and retry. // Allocate buffer on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[ulSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[ulSize]);
if (::GetUserNameExW(NameFormat, szBuffer.get(), &ulSize)) { if (::GetUserNameExW(NameFormat, szBuffer.get(), &ulSize)) {
sName.assign(szBuffer.get(), ulSize); sName.assign(szBuffer.get(), ulSize);
return TRUE; return TRUE;

View File

@ -18,41 +18,41 @@
/// @{ /// @{
/// @copydoc PathCanonicalizeW() /// @copydoc PathCanonicalizeW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL PathCanonicalizeA(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath); static BOOL PathCanonicalizeA(_Inout_ std::basic_string<char, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath);
/// ///
/// Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path, and stores it in a std::wstring string. /// Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path, and stores it in a std::wstring string.
/// ///
/// \sa [PathCanonicalize function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569.aspx) /// \sa [PathCanonicalize function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL PathCanonicalizeW(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath); static BOOL PathCanonicalizeW(_Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath);
/// @} /// @}
#pragma once #pragma once
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL PathCanonicalizeA(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath) static BOOL PathCanonicalizeA(_Inout_ std::basic_string<char, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
// Allocate buffer on heap and read into it. // Allocate buffer on heap and read into it.
_Elem szBuffer[MAX_PATH + 1]; char szBuffer[MAX_PATH + 1];
BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath); BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath);
sValue.assign(szBuffer, bResult ? MAX_PATH : 0); sValue.assign(szBuffer, bResult ? MAX_PATH : 0);
return bResult; return bResult;
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static BOOL PathCanonicalizeW(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath) static BOOL PathCanonicalizeW(_Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath)
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szBuffer[MAX_PATH + 1]; wchar_t szBuffer[MAX_PATH + 1];
BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath); BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath);
sValue.assign(szBuffer, bResult ? MAX_PATH : 0); sValue.assign(szBuffer, bResult ? MAX_PATH : 0);
return bResult; return bResult;

View File

@ -37,8 +37,8 @@ namespace winstd {
/// Since Wlanapi.dll is not always present, the `pfnWlanReasonCodeToString` pointer to `WlanReasonCodeToString()` /// Since Wlanapi.dll is not always present, the `pfnWlanReasonCodeToString` pointer to `WlanReasonCodeToString()`
/// function must be loaded dynamically. /// function must be loaded dynamically.
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved); static DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue, __reserved PVOID pReserved);
/// @} /// @}
@ -165,8 +165,8 @@ namespace winstd
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved) static DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue, __reserved PVOID pReserved)
{ {
DWORD dwSize = 0; DWORD dwSize = 0;
@ -176,7 +176,7 @@ static DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_
for (;;) { for (;;) {
// Increment size and allocate buffer. // Increment size and allocate buffer.
dwSize += 1024; dwSize += 1024;
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[dwSize]);
// Try! // Try!
DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer.get(), pReserved); DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer.get(), pReserved);

View File

@ -38,28 +38,28 @@ namespace winstd
/// @{ /// @{
/// @copydoc GetModuleFileNameW() /// @copydoc GetModuleFileNameW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept;
/// ///
/// Retrieves the fully qualified path for the file that contains the specified module and stores it in a std::wstring string. /// Retrieves the fully qualified path for the file that contains the specified module and stores it in a std::wstring string.
/// ///
/// \sa [GetModuleFileName function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197.aspx) /// \sa [GetModuleFileName function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept;
/// @copydoc GetWindowTextW() /// @copydoc GetWindowTextW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept;
/// ///
/// Copies the text of the specified window's title bar (if it has one) into a std::wstring string. /// Copies the text of the specified window's title bar (if it has one) into a std::wstring string.
/// ///
/// \sa [GetWindowText function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633520.aspx) /// \sa [GetWindowText function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633520.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept;
/// @copydoc GetFileVersionInfoW() /// @copydoc GetFileVersionInfoW()
template<class _Ty, class _Ax> template<class _Ty, class _Ax>
@ -74,20 +74,20 @@ template<class _Ty, class _Ax>
static _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept; static _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept;
/// @copydoc ExpandEnvironmentStringsW() /// @copydoc ExpandEnvironmentStringsW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept;
/// ///
/// Expands environment-variable strings, replaces them with the values defined for the current user, and stores it in a std::wstring string. /// Expands environment-variable strings, replaces them with the values defined for the current user, and stores it in a std::wstring string.
/// ///
/// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx) /// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept;
/// @copydoc GuidToStringW() /// @copydoc GuidToStringW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept; static VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<char, _Traits, _Ax> &str) noexcept;
/// ///
/// Formats GUID and stores it in a std::wstring string. /// Formats GUID and stores it in a std::wstring string.
@ -95,8 +95,8 @@ static VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T
/// \param[in ] lpGuid Pointer to GUID /// \param[in ] lpGuid Pointer to GUID
/// \param[out] str String to store the result to /// \param[out] str String to store the result to
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept; static VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &str) noexcept;
/// @copydoc GuidToStringW() /// @copydoc GuidToStringW()
#ifdef _UNICODE #ifdef _UNICODE
@ -146,8 +146,8 @@ static _Success_(return) BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUI
/// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx) /// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx)
/// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx) /// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept;
/// ///
/// Queries for a string value in the registry and stores it in a std::wstring string. /// Queries for a string value in the registry and stores it in a std::wstring string.
@ -167,8 +167,8 @@ static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_
/// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx) /// \sa [RegQueryValueEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911.aspx)
/// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx) /// \sa [ExpandEnvironmentStrings function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept; static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept;
/// @copydoc RegQueryValueExW() /// @copydoc RegQueryValueExW()
template<class _Ty, class _Ax> template<class _Ty, class _Ax>
@ -185,16 +185,16 @@ static LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName,
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA #if _WIN32_WINNT >= _WIN32_WINNT_VISTA
/// @copydoc RegLoadMUIStringW() /// @copydoc RegLoadMUIStringW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) noexcept; static LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<char, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) noexcept;
/// ///
/// Loads the specified string from the specified key and subkey, and stores it in a std::wstring string. /// Loads the specified string from the specified key and subkey, and stores it in a std::wstring string.
/// ///
/// \sa [RegLoadMUIString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724890.aspx) /// \sa [RegLoadMUIString function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724890.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) noexcept; static LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) noexcept;
#endif #endif
@ -363,28 +363,28 @@ static VOID OutputDebugStr(_In_z_ LPCSTR lpOutputString, ...) noexcept;
static VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) noexcept; static VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) noexcept;
/// @copydoc GetDateFormatW() /// @copydoc GetDateFormatW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept; static _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<char, _Traits, _Ax> &sDate) noexcept;
/// ///
/// Formats a date as a date string for a locale specified by the locale identifier. The function formats either a specified date or the local system date. /// Formats a date as a date string for a locale specified by the locale identifier. The function formats either a specified date or the local system date.
/// ///
/// \sa [GetDateFormat function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd318086.aspx) /// \sa [GetDateFormat function](https://msdn.microsoft.com/en-us/library/windows/desktop/dd318086.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept; static _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sDate) noexcept;
/// @copydoc LookupAccountSidW() /// @copydoc LookupAccountSidW()
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept; static _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<char, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<char, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept;
/// ///
/// Retrieves the name of the account for this SID and the name of the first domain on which this SID is found. /// Retrieves the name of the account for this SID and the name of the first domain on which this SID is found.
/// ///
/// \sa [LookupAccountSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379166.aspx) /// \sa [LookupAccountSid function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379166.aspx)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept; static _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<wchar_t, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<wchar_t, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept;
/// ///
/// Retrieves a specified type of information about an access token. The calling process must have appropriate access rights to obtain the information. /// Retrieves a specified type of information about an access token. The calling process must have appropriate access rights to obtain the information.
@ -399,16 +399,16 @@ static _Success_(return != 0) BOOL GetTokenInformation(_In_ HANDLE TokenHandle,
/// ///
/// \sa [QueryFullProcessImageNameA function](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamea) /// \sa [QueryFullProcessImageNameA function](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamea)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<_Elem, _Traits, _Ax>& sExeName); static _Success_(return != 0) BOOL QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<char, _Traits, _Ax>& sExeName);
/// ///
/// Retrieves the full name of the executable image for the specified process. /// Retrieves the full name of the executable image for the specified process.
/// ///
/// \sa [QueryFullProcessImageNameW function](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamew) /// \sa [QueryFullProcessImageNameW function](https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamew)
/// ///
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<_Elem, _Traits, _Ax>& sExeName); static _Success_(return != 0) BOOL QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<wchar_t, _Traits, _Ax>& sExeName);
/// @} /// @}
@ -1358,12 +1358,12 @@ namespace winstd
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4505) // Don't warn on unused code #pragma warning(disable: 4505) // Don't warn on unused code
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
// Try with stack buffer first. // Try with stack buffer first.
DWORD dwResult = ::GetModuleFileNameA(hModule, szStackBuffer, _countof(szStackBuffer)); DWORD dwResult = ::GetModuleFileNameA(hModule, szStackBuffer, _countof(szStackBuffer));
@ -1372,9 +1372,9 @@ static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_strin
sValue.assign(szStackBuffer, dwResult); sValue.assign(szStackBuffer, dwResult);
return dwResult; return dwResult;
} else { } else {
for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; dwCapacity *= 2) { for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(char);; dwCapacity *= 2) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwCapacity]); std::unique_ptr<char[]> szBuffer(new char[dwCapacity]);
dwResult = ::GetModuleFileNameA(hModule, szBuffer.get(), dwCapacity); dwResult = ::GetModuleFileNameA(hModule, szBuffer.get(), dwCapacity);
if (dwResult < dwCapacity) { if (dwResult < dwCapacity) {
sValue.assign(szBuffer.get(), dwResult); sValue.assign(szBuffer.get(), dwResult);
@ -1385,10 +1385,10 @@ static DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_strin
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
// Try with stack buffer first. // Try with stack buffer first.
DWORD dwResult = ::GetModuleFileNameW(hModule, szStackBuffer, _countof(szStackBuffer)); DWORD dwResult = ::GetModuleFileNameW(hModule, szStackBuffer, _countof(szStackBuffer));
@ -1397,9 +1397,9 @@ static DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_strin
sValue.assign(szStackBuffer, dwResult); sValue.assign(szStackBuffer, dwResult);
return dwResult; return dwResult;
} else { } else {
for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; dwCapacity *= 2) { for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t);; dwCapacity *= 2) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwCapacity]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[dwCapacity]);
dwResult = ::GetModuleFileNameW(hModule, szBuffer.get(), dwCapacity); dwResult = ::GetModuleFileNameW(hModule, szBuffer.get(), dwCapacity);
if (dwResult < dwCapacity) { if (dwResult < dwCapacity) {
sValue.assign(szBuffer.get(), dwResult); sValue.assign(szBuffer.get(), dwResult);
@ -1410,8 +1410,8 @@ static DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_strin
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
@ -1420,14 +1420,14 @@ static _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basi
// Query the final string length first. // Query the final string length first.
iResult = ::GetWindowTextLengthA(hWnd); iResult = ::GetWindowTextLengthA(hWnd);
if (iResult > 0) { if (iResult > 0) {
if (++iResult < WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)) { if (++iResult < WINSTD_STACK_BUFFER_BYTES/sizeof(char)) {
// Read string data to stack. // Read string data to stack.
_Elem szBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; char szBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
iResult = ::GetWindowTextA(hWnd, szBuffer, _countof(szBuffer)); iResult = ::GetWindowTextA(hWnd, szBuffer, _countof(szBuffer));
sValue.assign(szBuffer, iResult); sValue.assign(szBuffer, iResult);
} else { } else {
// Allocate buffer on heap and read the string data into it. // Allocate buffer on heap and read the string data into it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++iResult]); std::unique_ptr<char[]> szBuffer(new char[++iResult]);
iResult = ::GetWindowTextA(hWnd, szBuffer.get(), iResult); iResult = ::GetWindowTextA(hWnd, szBuffer.get(), iResult);
sValue.assign(szBuffer.get(), iResult); sValue.assign(szBuffer.get(), iResult);
} }
@ -1439,8 +1439,8 @@ static _Success_(return != 0) int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basi
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
@ -1449,14 +1449,14 @@ static _Success_(return != 0) int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basi
// Query the final string length first. // Query the final string length first.
iResult = ::GetWindowTextLengthW(hWnd); iResult = ::GetWindowTextLengthW(hWnd);
if (iResult > 0) { if (iResult > 0) {
if (++iResult < WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)) { if (++iResult < WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)) {
// Read string data to stack. // Read string data to stack.
_Elem szBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
iResult = ::GetWindowTextW(hWnd, szBuffer, _countof(szBuffer)); iResult = ::GetWindowTextW(hWnd, szBuffer, _countof(szBuffer));
sValue.assign(szBuffer, iResult); sValue.assign(szBuffer, iResult);
} else { } else {
// Allocate buffer on heap and read the string data into it. // Allocate buffer on heap and read the string data into it.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++iResult]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[++iResult]);
iResult = ::GetWindowTextW(hWnd, szBuffer.get(), iResult); iResult = ::GetWindowTextW(hWnd, szBuffer.get(), iResult);
sValue.assign(szBuffer.get(), iResult); sValue.assign(szBuffer.get(), iResult);
} }
@ -1500,14 +1500,14 @@ static _Success_(return != 0) BOOL GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFile
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
for (DWORD dwSizeOut = (DWORD)strlen(lpSrc) + 0x100;;) { for (DWORD dwSizeOut = (DWORD)strlen(lpSrc) + 0x100;;) {
DWORD dwSizeIn = dwSizeOut; DWORD dwSizeIn = dwSizeOut;
std::unique_ptr<_Elem[]> szBuffer(new _Elem[(size_t)dwSizeIn + 2]); // Note: ANSI version requires one extra char. std::unique_ptr<char[]> szBuffer(new char[(size_t)dwSizeIn + 2]); // Note: ANSI version requires one extra char.
dwSizeOut = ::ExpandEnvironmentStringsA(lpSrc, szBuffer.get(), dwSizeIn); dwSizeOut = ::ExpandEnvironmentStringsA(lpSrc, szBuffer.get(), dwSizeIn);
if (dwSizeOut == 0) { if (dwSizeOut == 0) {
// Error or zero-length input. // Error or zero-length input.
@ -1524,12 +1524,12 @@ static _Success_(return != 0) DWORD ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSr
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept
{ {
for (DWORD dwSizeOut = (DWORD)wcslen(lpSrc) + 0x100;;) { for (DWORD dwSizeOut = (DWORD)wcslen(lpSrc) + 0x100;;) {
DWORD dwSizeIn = dwSizeOut; DWORD dwSizeIn = dwSizeOut;
std::unique_ptr<_Elem[]> szBuffer(new _Elem[(size_t)dwSizeIn + 1]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[(size_t)dwSizeIn + 1]);
dwSizeOut = ::ExpandEnvironmentStringsW(lpSrc, szBuffer.get(), dwSizeIn); dwSizeOut = ::ExpandEnvironmentStringsW(lpSrc, szBuffer.get(), dwSizeIn);
if (dwSizeOut == 0) { if (dwSizeOut == 0) {
// Error or zero-length input. // Error or zero-length input.
@ -1546,8 +1546,8 @@ static _Success_(return != 0) DWORD ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpS
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept static VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<char, _Traits, _Ax> &str) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
@ -1560,8 +1560,8 @@ static VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str) noexcept static VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &str) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
@ -1700,8 +1700,8 @@ static _Success_(return) BOOL StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUI
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<char, _Traits, _Ax> &sValue) noexcept
{ {
LSTATUS lResult; LSTATUS lResult;
BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES]; BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES];
@ -1747,8 +1747,8 @@ static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue) noexcept static LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue) noexcept
{ {
LSTATUS lResult; LSTATUS lResult;
BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES]; BYTE aStackBuffer[WINSTD_STACK_BUFFER_BYTES];
@ -1842,8 +1842,8 @@ static LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName,
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA #if _WIN32_WINNT >= _WIN32_WINNT_VISTA
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) noexcept static LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<char, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory) noexcept
{ {
// According to "Remarks" section in MSDN documentation of RegLoadMUIString(), // According to "Remarks" section in MSDN documentation of RegLoadMUIString(),
// this function is defined but not implemented as ANSI variation. // this function is defined but not implemented as ANSI variation.
@ -1852,11 +1852,11 @@ static LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Ou
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) noexcept static LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory) noexcept
{ {
LSTATUS lResult; LSTATUS lResult;
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
DWORD dwSize; DWORD dwSize;
Flags &= ~REG_MUI_STRING_TRUNCATE; Flags &= ~REG_MUI_STRING_TRUNCATE;
@ -1865,11 +1865,11 @@ static LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _O
lResult = RegLoadMUIStringW(hKey, pszValue, szStackBuffer, sizeof(szStackBuffer), &dwSize, Flags, pszDirectory); lResult = RegLoadMUIStringW(hKey, pszValue, szStackBuffer, sizeof(szStackBuffer), &dwSize, Flags, pszDirectory);
if (lResult == ERROR_SUCCESS) { if (lResult == ERROR_SUCCESS) {
// Copy from stack buffer. // Copy from stack buffer.
sOut.assign(szStackBuffer, wcsnlen(szStackBuffer, dwSize/sizeof(_Elem))); sOut.assign(szStackBuffer, wcsnlen(szStackBuffer, dwSize/sizeof(wchar_t)));
} else if (lResult == ERROR_MORE_DATA) { } else if (lResult == ERROR_MORE_DATA) {
// Allocate buffer on heap and retry. // Allocate buffer on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[(dwSize + sizeof(_Elem) - 1)/sizeof(_Elem)]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[(dwSize + sizeof(wchar_t) - 1)/sizeof(wchar_t)]);
sOut.assign(szBuffer.get(), (lResult = RegLoadMUIStringW(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? wcsnlen(szBuffer.get(), dwSize/sizeof(_Elem)) : 0); sOut.assign(szBuffer.get(), (lResult = RegLoadMUIStringW(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? wcsnlen(szBuffer.get(), dwSize/sizeof(wchar_t)) : 0);
} }
return lResult; return lResult;
@ -2294,13 +2294,13 @@ static VOID OutputDebugStr(_In_z_ LPCWSTR lpOutputString, ...) noexcept
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept static _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<char, _Traits, _Ax> &sDate) noexcept
{ {
int iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0); int iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
if (iResult) { if (iResult) {
// Allocate buffer on heap and retry. // Allocate buffer on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[iResult]); std::unique_ptr<char[]> szBuffer(new char[iResult]);
iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult); iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0); sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
return iResult; return iResult;
@ -2310,13 +2310,13 @@ static _Success_(return != 0) int GetDateFormatA(_In_ LCID Locale, _In_ DWORD dw
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sDate) noexcept static _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sDate) noexcept
{ {
int iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0); int iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
if (iResult) { if (iResult) {
// Allocate buffer on heap and retry. // Allocate buffer on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[iResult]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[iResult]);
iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult); iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0); sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
return iResult; return iResult;
@ -2326,8 +2326,8 @@ static _Success_(return != 0) int GetDateFormatW(_In_ LCID Locale, _In_ DWORD dw
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept static _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<char, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<char, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
@ -2344,8 +2344,8 @@ static _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemN
return TRUE; return TRUE;
} else if (GetLastError() == ERROR_MORE_DATA) { } else if (GetLastError() == ERROR_MORE_DATA) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> bufName (new _Elem[dwNameLen ]); std::unique_ptr<char[]> bufName (new char[dwNameLen ]);
std::unique_ptr<_Elem[]> bufRefDomain(new _Elem[dwRefDomainLen]); std::unique_ptr<char[]> bufRefDomain(new char[dwRefDomainLen]);
if (LookupAccountSidA(lpSystemName, lpSid, if (LookupAccountSidA(lpSystemName, lpSid,
bufName .get(), &dwNameLen , bufName .get(), &dwNameLen ,
bufRefDomain.get(), &dwRefDomainLen, bufRefDomain.get(), &dwRefDomainLen,
@ -2361,8 +2361,8 @@ static _Success_(return != 0) BOOL LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemN
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<_Elem, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept static _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<wchar_t, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<wchar_t, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept
{ {
assert(0); // TODO: Test this code. assert(0); // TODO: Test this code.
@ -2379,8 +2379,8 @@ static _Success_(return != 0) BOOL LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystem
return TRUE; return TRUE;
} else if (GetLastError() == ERROR_MORE_DATA) { } else if (GetLastError() == ERROR_MORE_DATA) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> bufName (new _Elem[dwNameLen ]); std::unique_ptr<wchar_t[]> bufName (new wchar_t[dwNameLen ]);
std::unique_ptr<_Elem[]> bufRefDomain(new _Elem[dwRefDomainLen]); std::unique_ptr<wchar_t[]> bufRefDomain(new wchar_t[dwRefDomainLen]);
if (LookupAccountSidW(lpSystemName, lpSid, if (LookupAccountSidW(lpSystemName, lpSid,
bufName .get(), &dwNameLen , bufName .get(), &dwNameLen ,
bufRefDomain.get(), &dwRefDomainLen, bufRefDomain.get(), &dwRefDomainLen,
@ -2424,10 +2424,10 @@ static _Success_(return != 0) BOOL GetTokenInformation(_In_ HANDLE TokenHandle,
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<_Elem, _Traits, _Ax>& sExeName) static _Success_(return != 0) BOOL QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<char, _Traits, _Ax>& sExeName)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(_Elem)]; char szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(char)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
// Try with stack buffer first. // Try with stack buffer first.
@ -2436,9 +2436,9 @@ static _Success_(return != 0) BOOL QueryFullProcessImageNameA(_In_ HANDLE hProce
sExeName.assign(szStackBuffer, dwSize); sExeName.assign(szStackBuffer, dwSize);
return TRUE; return TRUE;
} }
for (DWORD dwCapacity = 2 * WINSTD_STACK_BUFFER_BYTES / sizeof(_Elem); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) { for (DWORD dwCapacity = 2 * WINSTD_STACK_BUFFER_BYTES / sizeof(char); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwCapacity]); std::unique_ptr<char[]> szBuffer(new char[dwCapacity]);
dwSize = dwCapacity; dwSize = dwCapacity;
if (::QueryFullProcessImageNameA(hProcess, dwFlags, szBuffer.get(), &dwSize)) { if (::QueryFullProcessImageNameA(hProcess, dwFlags, szBuffer.get(), &dwSize)) {
sExeName.assign(szBuffer.get(), dwSize); sExeName.assign(szBuffer.get(), dwSize);
@ -2449,10 +2449,10 @@ static _Success_(return != 0) BOOL QueryFullProcessImageNameA(_In_ HANDLE hProce
} }
template<class _Elem, class _Traits, class _Ax> template<class _Traits, class _Ax>
static _Success_(return != 0) BOOL QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<_Elem, _Traits, _Ax>& sExeName) static _Success_(return != 0) BOOL QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<wchar_t, _Traits, _Ax>& sExeName)
{ {
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(_Elem)]; wchar_t szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(wchar_t)];
DWORD dwSize = _countof(szStackBuffer); DWORD dwSize = _countof(szStackBuffer);
// Try with stack buffer first. // Try with stack buffer first.
@ -2461,9 +2461,9 @@ static _Success_(return != 0) BOOL QueryFullProcessImageNameW(_In_ HANDLE hProce
sExeName.assign(szStackBuffer, dwSize); sExeName.assign(szStackBuffer, dwSize);
return TRUE; return TRUE;
} }
for (DWORD dwCapacity = 2 * WINSTD_STACK_BUFFER_BYTES / sizeof(_Elem); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) { for (DWORD dwCapacity = 2 * WINSTD_STACK_BUFFER_BYTES / sizeof(wchar_t); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
// Allocate on heap and retry. // Allocate on heap and retry.
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwCapacity]); std::unique_ptr<wchar_t[]> szBuffer(new wchar_t[dwCapacity]);
dwSize = dwCapacity; dwSize = dwCapacity;
if (::QueryFullProcessImageNameW(hProcess, dwFlags, szBuffer.get(), &dwSize)) { if (::QueryFullProcessImageNameW(hProcess, dwFlags, szBuffer.get(), &dwSize)) {
sExeName.assign(szBuffer.get(), dwSize); sExeName.assign(szBuffer.get(), dwSize);