Forward declarations introduced

This commit is contained in:
Simon Rozman 2016-05-17 12:05:32 +02:00
parent 2cb830b341
commit 705e26a2d8
9 changed files with 212 additions and 120 deletions

View File

@ -18,13 +18,19 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "Common.h" #include "Common.h"
#include <string> #include <string>
#include <vector> #include <vector>
namespace winstd
{
class WINSTD_API base64_enc;
class WINSTD_API base64_dec;
}
#pragma once
namespace winstd namespace winstd
{ {
@ -37,7 +43,7 @@ namespace winstd
/// ///
/// Base64 encoding session /// Base64 encoding session
/// ///
class base64_enc class WINSTD_API base64_enc
{ {
public: public:
inline base64_enc() : num(0) {}; inline base64_enc() : num(0) {};

View File

@ -18,15 +18,102 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include <Windows.h> #include <Windows.h>
#include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#include <memory>
#include <string> #include <string>
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<class _Elem, class _Traits, class _Ax> inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, _In_ va_list arg);
template<class _Elem, class _Traits, class _Ax> 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 <class _Ty> struct LocalFree_delete;
template <class _Ty> struct LocalFree_delete<_Ty[]>;
template <class T> class handle;
template <class T> class dplhandle;
template<class _Elem, class _Traits = char_traits<_Elem>, 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<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > string_printf;
///
/// Wide character implementation of a class to support string formatting using `printf()` style templates
///
typedef basic_string_printf<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>> wstring_printf;
#ifdef _UNICODE
typedef wstring_printf tstring_printf;
#else
typedef string_printf tstring_printf;
#endif
template<class _Elem, class _Traits = char_traits<_Elem>, 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<char, std::char_traits<char>, std::allocator<char> > string_msg;
///
/// Wide character implementation of a class to support string formatting using `FormatMessage()` style templates
///
typedef basic_string_msg<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > wstring_msg;
#ifdef _UNICODE
typedef wstring_msg tstring_msg;
#else
typedef string_msg tstring_msg;
#endif
template<class _Ty> class sanitizing_allocator;
template<class _Ty> 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<char, std::char_traits<char>, sanitizing_allocator<char> > 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<wchar_t, std::char_traits<wchar_t>, sanitizing_allocator<wchar_t> > sanitizing_wstring;
#ifdef _UNICODE
typedef sanitizing_wstring sanitizing_tstring;
#else
typedef sanitizing_string sanitizing_tstring;
#endif
}
#pragma once
#include <assert.h>
#include <memory>
#include <vector> #include <vector>
@ -117,6 +204,25 @@ inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _P
#pragma warning(pop) #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<class _Elem, class _Traits, class _Ax>
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. /// 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<class _Elem, class _Traits, class _Ax>
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 namespace winstd
{ {
#ifdef _UNICODE
typedef std::wstring tstring;
#else
typedef std::string tstring;
#endif
/// ///
/// Deleter for unique_ptr using LocalFree /// 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. /// 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 T> class handle template <class T>
class handle
{ {
public: public:
/// ///
@ -564,7 +645,7 @@ namespace winstd
/// ///
/// Base template class to support string formatting using `printf()` style templates /// Base template class to support string formatting using `printf()` style templates
/// ///
template<class _Elem, class _Traits = char_traits<_Elem>, class _Ax = allocator<_Elem> > template<class _Elem, class _Traits, class _Ax>
class basic_string_printf : public std::basic_string<_Elem, _Traits, _Ax> class basic_string_printf : public std::basic_string<_Elem, _Traits, _Ax>
{ {
public: 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<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > string_printf;
///
/// Wide character implementation of a class to support string formatting using `printf()` style templates
///
typedef basic_string_printf<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>> 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 /// Base template class to support string formatting using `FormatMessage()` style templates
/// ///
template<class _Elem, class _Traits = char_traits<_Elem>, class _Ax = allocator<_Elem> > template<class _Elem, class _Traits, class _Ax>
class basic_string_msg : public std::basic_string<_Elem, _Traits, _Ax> class basic_string_msg : public std::basic_string<_Elem, _Traits, _Ax>
{ {
public: 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<char, std::char_traits<char>, std::allocator<char> > string_msg;
///
/// Wide character implementation of a class to support string formatting using `FormatMessage()` style templates
///
typedef basic_string_msg<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > wstring_msg;
#ifdef _UNICODE
typedef wstring_msg tstring_msg;
#else
typedef string_msg tstring_msg;
#endif
/// @} /// @}
/// \defgroup WinStdMemSanitize Auto-sanitize Memory Management /// \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<char, std::char_traits<char>, sanitizing_allocator<char> > 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<wchar_t, std::char_traits<wchar_t>, sanitizing_allocator<wchar_t> > sanitizing_wstring;
#ifdef _UNICODE
typedef sanitizing_wstring sanitizing_tstring;
#else
typedef sanitizing_string sanitizing_tstring;
#endif
/// @} /// @}
} }

View File

@ -18,8 +18,6 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "Common.h" #include "Common.h"
#include <WinCrypt.h> #include <WinCrypt.h>
@ -27,6 +25,22 @@
#include <string> #include <string>
#include <vector> #include <vector>
template<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Ty, class _Ax> inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags);
template<class _Ty, class _Ax> 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 /// \defgroup WinStdCryptoAPI Cryptography API

View File

@ -18,10 +18,17 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #include "Common.h"
#include <eaptypes.h> #include <eaptypes.h>
namespace winstd
{
class eap_attr;
}
#pragma once
namespace winstd namespace winstd
{ {

View File

@ -18,8 +18,6 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "Common.h" #include "Common.h"
#include <MsiQuery.h> #include <MsiQuery.h>
@ -27,6 +25,18 @@
#include <string> #include <string>
#include <vector> #include <vector>
template<class _Elem, class _Traits, class _Ax> inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Ty, class _Ax> inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::vector<_Ty, _Ax> &binData);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
#pragma once
/// ///
/// \defgroup WinStdMSIAPI Microsoft Installer API /// \defgroup WinStdMSIAPI Microsoft Installer API

View File

@ -18,12 +18,17 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #include "Common.h"
#include <Security.h> #include <Security.h>
#include <string> #include <string>
template<class _Elem, class _Traits, class _Ax> BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName);
template<class _Elem, class _Traits, class _Ax> BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName);
#pragma once
/// ///
/// \defgroup WinStdSecurityAPI Security API /// \defgroup WinStdSecurityAPI Security API

View File

@ -18,10 +18,17 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Common.h"
#include <Shlwapi.h>
#include <string>
template<class _Elem, class _Traits, class _Ax> inline BOOL PathCanonicalizeA(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCSTR pszPath);
template<class _Elem, class _Traits, class _Ax> inline BOOL PathCanonicalizeW(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCWSTR pszPath);
#pragma once #pragma once
#include <atlstr.h>
#include <Shlwapi.h>
/// ///
/// \defgroup WinStdShellWAPI Shell API /// \defgroup WinStdShellWAPI Shell API

View File

@ -18,16 +18,20 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #include "Common.h"
#include <atlstr.h>
#include <wlanapi.h> #include <wlanapi.h>
#include <string>
// Must not statically link to Wlanapi.dll as it is not available on Windows // Must not statically link to Wlanapi.dll as it is not available on Windows
// without a WLAN interface. // without a WLAN interface.
extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in DWORD dwBufferSize, __in_ecount(dwBufferSize) PWCHAR pStringBuffer, __reserved PVOID pReserved); extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in DWORD dwBufferSize, __in_ecount(dwBufferSize) PWCHAR pStringBuffer, __reserved PVOID pReserved);
template<class _Elem, class _Traits, class _Ax> inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved);
#pragma once
/// ///
/// \defgroup WinStdWLANAPI WLAN API /// \defgroup WinStdWLANAPI WLAN API

View File

@ -18,8 +18,6 @@
along with Setup. If not, see <http://www.gnu.org/licenses/>. along with Setup. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "Common.h" #include "Common.h"
#include <Windows.h> #include <Windows.h>
@ -27,6 +25,38 @@
#include <string> #include <string>
#include <vector> #include <vector>
template<class _Elem, class _Traits, class _Ax> inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Ty, class _Ax> inline BOOL GetFileVersionInfoA(_In_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue);
template<class _Ty, class _Ax> inline BOOL GetFileVersionInfoW(_In_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue);
template<class _Elem, class _Traits, class _Ax> inline DWORD ExpandEnvironmentStringsW(_In_ LPCSTR lpSrc, std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline DWORD ExpandEnvironmentStringsW(_In_ LPCWSTR lpSrc, std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline VOID GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<_Elem, _Traits, _Ax> &str);
template<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Elem, class _Traits, class _Ax> inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
template<class _Ty, class _Ax> inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData);
template<class _Ty, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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 /// \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]); 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. /// Queries for a string value in the registry and stores it in a std::string string.