From 705e26a2d88d4219de93690ca02a9775a8c4c648 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 17 May 2016 12:05:32 +0200 Subject: [PATCH] Forward declarations introduced --- include/WinStd/Base64.h | 12 ++- include/WinStd/Common.h | 213 +++++++++++++++++++++------------------- include/WinStd/Crypt.h | 18 +++- include/WinStd/EAP.h | 9 +- include/WinStd/MSI.h | 14 ++- include/WinStd/Sec.h | 7 +- include/WinStd/Shell.h | 11 ++- include/WinStd/WLAN.h | 8 +- include/WinStd/Win.h | 40 ++++++-- 9 files changed, 212 insertions(+), 120 deletions(-) diff --git a/include/WinStd/Base64.h b/include/WinStd/Base64.h index d8a61426..318d7ee3 100644 --- a/include/WinStd/Base64.h +++ b/include/WinStd/Base64.h @@ -18,13 +18,19 @@ along with Setup. If not, see . */ -#pragma once - #include "Common.h" #include #include +namespace winstd +{ + class WINSTD_API base64_enc; + class WINSTD_API base64_dec; +} + +#pragma once + namespace winstd { @@ -37,7 +43,7 @@ namespace winstd /// /// Base64 encoding session /// - class base64_enc + class WINSTD_API base64_enc { public: inline base64_enc() : num(0) {}; diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index ec12842b..810444b0 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -18,15 +18,102 @@ along with Setup. If not, see . */ -#pragma once - #include -#include #include -#include #include + +inline int vsnprintf(_Out_z_cap_(capacity) char *str, _In_ size_t capacity, _In_z_ _Printf_format_string_ const char *format, _In_ va_list arg); +inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _In_z_ _Printf_format_string_ const wchar_t *format, _In_ va_list arg); +template inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, _In_ va_list arg); +template inline int sprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...); +inline VOID OutputDebugStrV(_In_ LPCSTR lpOutputString, _In_ va_list arg); +inline VOID OutputDebugStrV(_In_ LPCWSTR lpOutputString, _In_ va_list arg); +inline VOID OutputDebugStr(_In_ LPCSTR lpOutputString, ...); +inline VOID OutputDebugStr(_In_ LPCWSTR lpOutputString, ...); +namespace winstd +{ +#ifdef _UNICODE + typedef std::wstring tstring; +#else + typedef std::string tstring; +#endif + + + template struct LocalFree_delete; + template struct LocalFree_delete<_Ty[]>; + template class handle; + template class dplhandle; + template, class _Ax = allocator<_Elem> > class basic_string_printf; + + /// + /// Single-byte character implementation of a class to support string formatting using `printf()` style templates + /// + typedef basic_string_printf, std::allocator > string_printf; + + /// + /// Wide character implementation of a class to support string formatting using `printf()` style templates + /// + typedef basic_string_printf, std::allocator> wstring_printf; + +#ifdef _UNICODE + typedef wstring_printf tstring_printf; +#else + typedef string_printf tstring_printf; +#endif + + template, class _Ax = allocator<_Elem> > class basic_string_msg; + + /// + /// Single-byte character implementation of a class to support string formatting using `FormatMessage()` style templates + /// + typedef basic_string_msg, std::allocator > string_msg; + + /// + /// Wide character implementation of a class to support string formatting using `FormatMessage()` style templates + /// + typedef basic_string_msg, std::allocator > wstring_msg; + +#ifdef _UNICODE + typedef wstring_msg tstring_msg; +#else + typedef string_msg tstring_msg; +#endif + + template class sanitizing_allocator; + template class sanitizing_vector; + + /// + /// A sanitizing variant of std::string + /// + /// \note + /// `sanitizing_string` introduces a performance penalty. However, it provides an additional level of security. + /// Use for security sensitive data memory storage only. + /// + typedef std::basic_string, sanitizing_allocator > sanitizing_string; + + /// + /// A sanitizing variant of std::wstring + /// + /// \note + /// `sanitizing_wstring` introduces a performance penalty. However, it provides an additional level of security. + /// Use for security sensitive data memory storage only. + /// + typedef std::basic_string, sanitizing_allocator > sanitizing_wstring; + +#ifdef _UNICODE + typedef sanitizing_wstring sanitizing_tstring; +#else + typedef sanitizing_string sanitizing_tstring; +#endif +} + +#pragma once + +#include + +#include #include @@ -117,6 +204,25 @@ inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _P #pragma warning(pop) +/// +/// Formats string using `printf()`. +/// +/// \param[out] str Formatted string +/// \param[in ] format String template using `printf()` style +/// +/// \returns Number of characters in result. +/// +template +inline int sprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...) +{ + va_list arg; + va_start(arg, format); + int res = vsprintf(str, format, arg); + va_end(arg); + return res; +} + + /// /// Formats and sends a string to the debugger for display. /// @@ -171,34 +277,8 @@ inline VOID OutputDebugStr(_In_ LPCWSTR lpOutputString, ...) } -/// -/// Formats string using `printf()`. -/// -/// \param[out] str Formatted string -/// \param[in ] format String template using `printf()` style -/// -/// \returns Number of characters in result. -/// -template -inline int sprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...) -{ - va_list arg; - va_start(arg, format); - int res = vsprintf(str, format, arg); - va_end(arg); - return res; -} - - namespace winstd { -#ifdef _UNICODE - typedef std::wstring tstring; -#else - typedef std::string tstring; -#endif - - /// /// Deleter for unique_ptr using LocalFree /// @@ -268,7 +348,8 @@ namespace winstd /// /// It provides basic operators and methods common to all descendands of this class establishing a base to ease the replacement of native object handle type with classes in object-oriented approach. /// - template class handle + template + class handle { public: /// @@ -564,7 +645,7 @@ namespace winstd /// /// Base template class to support string formatting using `printf()` style templates /// - template, class _Ax = allocator<_Elem> > + template class basic_string_printf : public std::basic_string<_Elem, _Traits, _Ax> { public: @@ -628,29 +709,10 @@ namespace winstd }; - /// - /// Single-byte character implementation of a class to support string formatting using `printf()` style templates - /// - typedef basic_string_printf, std::allocator > string_printf; - - - /// - /// Wide character implementation of a class to support string formatting using `printf()` style templates - /// - typedef basic_string_printf, std::allocator> wstring_printf; - - -#ifdef _UNICODE - typedef wstring_printf tstring_printf; -#else - typedef string_printf tstring_printf; -#endif - - /// /// Base template class to support string formatting using `FormatMessage()` style templates /// - template, class _Ax = allocator<_Elem> > + template class basic_string_msg : public std::basic_string<_Elem, _Traits, _Ax> { public: @@ -713,26 +775,6 @@ namespace winstd /// @} }; - - /// - /// Single-byte character implementation of a class to support string formatting using `FormatMessage()` style templates - /// - typedef basic_string_msg, std::allocator > string_msg; - - - /// - /// Wide character implementation of a class to support string formatting using `FormatMessage()` style templates - /// - typedef basic_string_msg, std::allocator > wstring_msg; - - -#ifdef _UNICODE - typedef wstring_msg tstring_msg; -#else - typedef string_msg tstring_msg; -#endif - - /// @} /// \defgroup WinStdMemSanitize Auto-sanitize Memory Management @@ -928,32 +970,5 @@ namespace winstd { }; - - /// - /// A sanitizing variant of std::string - /// - /// \note - /// `sanitizing_string` introduces a performance penalty. However, it provides an additional level of security. - /// Use for security sensitive data memory storage only. - /// - typedef std::basic_string, sanitizing_allocator > sanitizing_string; - - - /// - /// A sanitizing variant of std::wstring - /// - /// \note - /// `sanitizing_wstring` introduces a performance penalty. However, it provides an additional level of security. - /// Use for security sensitive data memory storage only. - /// - typedef std::basic_string, sanitizing_allocator > sanitizing_wstring; - - -#ifdef _UNICODE - typedef sanitizing_wstring sanitizing_tstring; -#else - typedef sanitizing_string sanitizing_tstring; -#endif - /// @} } diff --git a/include/WinStd/Crypt.h b/include/WinStd/Crypt.h index caf5e361..a25da71a 100644 --- a/include/WinStd/Crypt.h +++ b/include/WinStd/Crypt.h @@ -18,8 +18,6 @@ along with Setup. If not, see . */ -#pragma once - #include "Common.h" #include @@ -27,6 +25,22 @@ #include #include +template inline DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_ void *pvTypePara, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sNameString); +template inline DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_ void *pvTypePara, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sNameString); +template inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags); +template inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWORD dwBlobType, _In_ DWORD dwFlags, _Out_ std::vector<_Ty, _Ax> &aData); +namespace winstd +{ + class cert_context; + class cert_chain_context; + class cert_store; + class crypt_prov; + class crypt_hash; + class crypt_key; +} + +#pragma once + /// /// \defgroup WinStdCryptoAPI Cryptography API diff --git a/include/WinStd/EAP.h b/include/WinStd/EAP.h index 4d7ec94f..870423d6 100644 --- a/include/WinStd/EAP.h +++ b/include/WinStd/EAP.h @@ -18,10 +18,17 @@ along with Setup. If not, see . */ -#pragma once +#include "Common.h" #include +namespace winstd +{ + class eap_attr; +} + +#pragma once + namespace winstd { diff --git a/include/WinStd/MSI.h b/include/WinStd/MSI.h index c86d0bbc..ec243cd3 100644 --- a/include/WinStd/MSI.h +++ b/include/WinStd/MSI.h @@ -18,8 +18,6 @@ along with Setup. If not, see . */ -#pragma once - #include "Common.h" #include @@ -27,6 +25,18 @@ #include #include +template inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::vector<_Ty, _Ax> &binData); +template inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); + +#pragma once + /// /// \defgroup WinStdMSIAPI Microsoft Installer API diff --git a/include/WinStd/Sec.h b/include/WinStd/Sec.h index 43333a87..df4bad15 100644 --- a/include/WinStd/Sec.h +++ b/include/WinStd/Sec.h @@ -18,12 +18,17 @@ along with Setup. If not, see . */ -#pragma once +#include "Common.h" #include #include +template BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName); +template BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName); + +#pragma once + /// /// \defgroup WinStdSecurityAPI Security API diff --git a/include/WinStd/Shell.h b/include/WinStd/Shell.h index 6eb1ef1a..4e11059a 100644 --- a/include/WinStd/Shell.h +++ b/include/WinStd/Shell.h @@ -18,10 +18,17 @@ along with Setup. If not, see . */ +#include "Common.h" + +#include + +#include + +template inline BOOL PathCanonicalizeA(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCSTR pszPath); +template inline BOOL PathCanonicalizeW(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCWSTR pszPath); + #pragma once -#include -#include /// /// \defgroup WinStdShellWAPI Shell API diff --git a/include/WinStd/WLAN.h b/include/WinStd/WLAN.h index 678d4180..68eac876 100644 --- a/include/WinStd/WLAN.h +++ b/include/WinStd/WLAN.h @@ -18,16 +18,20 @@ along with Setup. If not, see . */ -#pragma once +#include "Common.h" -#include #include +#include // Must not statically link to Wlanapi.dll as it is not available on Windows // without a WLAN interface. extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in DWORD dwBufferSize, __in_ecount(dwBufferSize) PWCHAR pStringBuffer, __reserved PVOID pReserved); +template inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved); + +#pragma once + /// /// \defgroup WinStdWLANAPI WLAN API diff --git a/include/WinStd/Win.h b/include/WinStd/Win.h index e38c9f38..0fd3830d 100644 --- a/include/WinStd/Win.h +++ b/include/WinStd/Win.h @@ -18,8 +18,6 @@ along with Setup. If not, see . */ -#pragma once - #include "Common.h" #include @@ -27,6 +25,38 @@ #include #include +template inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline BOOL GetFileVersionInfoA(_In_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue); +template inline BOOL GetFileVersionInfoW(_In_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue); +template inline DWORD ExpandEnvironmentStringsW(_In_ LPCSTR lpSrc, std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline DWORD ExpandEnvironmentStringsW(_In_ LPCWSTR lpSrc, std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str); +template inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str); +#ifdef _UNICODE +#define GuidToString GuidToStringW +#else +#define GuidToString GuidToStringA +#endif +template inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue); +template inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData); +template inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData); +#if _WIN32_WINNT >= _WIN32_WINNT_VISTA +template inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_ LPCSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_ LPCSTR pszDirectory); +template inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_ LPCWSTR pszValue, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_ LPCWSTR pszDirectory); +#endif +template inline int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_ int cchWideChar, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sMultiByteStr, _In_opt_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar); +template inline int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_ int cbMultiByte, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sWideCharStr); +namespace winstd +{ + class library; +} + +#pragma once + /// /// \defgroup WinStdWinAPI Windows API @@ -305,12 +335,6 @@ inline VOID GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _T lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]); } -#ifdef _UNICODE -#define GuidToString GuidToStringW -#else -#define GuidToString GuidToStringA -#endif - /// /// Queries for a string value in the registry and stores it in a std::string string.