diff --git a/.gitignore b/.gitignore
index e87a9297..8fb1f80b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,2 @@
-/*.sdf
-/*.suo
-/*.opensdf
/doc
-/ipch
/.vs
diff --git a/WinStd-10.0.sln b/WinStd-10.0.sln
deleted file mode 100644
index 7959f6f8..00000000
--- a/WinStd-10.0.sln
+++ /dev/null
@@ -1,26 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinStd", "build\WinStd-10.0.vcxproj", "{47399D91-7EB9-41DE-B521-514BA5DB0C43}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Debug|x64 = Debug|x64
- Release|Win32 = Release|Win32
- Release|x64 = Release|x64
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|Win32.ActiveCfg = Debug|Win32
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|Win32.Build.0 = Debug|Win32
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|x64.ActiveCfg = Debug|x64
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Debug|x64.Build.0 = Debug|x64
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|Win32.ActiveCfg = Release|Win32
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|Win32.Build.0 = Release|Win32
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|x64.ActiveCfg = Release|x64
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}.Release|x64.Build.0 = Release|x64
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/build/WinStd-10.0.vcxproj b/build/WinStd-10.0.vcxproj
deleted file mode 100644
index d1530577..00000000
--- a/build/WinStd-10.0.vcxproj
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Debug
- x64
-
-
- Release
- Win32
-
-
- Release
- x64
-
-
-
- {47399D91-7EB9-41DE-B521-514BA5DB0C43}
- WinStd
- Win32Proj
- WinStd
-
-
-
- StaticLibrary
- Unicode
-
-
- StaticLibrary
- Unicode
-
-
- StaticLibrary
- Unicode
-
-
- StaticLibrary
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <_ProjectFileVersion>10.0.40219.1
-
-
-
-
-
\ No newline at end of file
diff --git a/build/WinStd-10.0.vcxproj.filters b/build/WinStd-10.0.vcxproj.filters
deleted file mode 100644
index cbf838d0..00000000
--- a/build/WinStd-10.0.vcxproj.filters
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hpp;hxx;hm;inl;inc;xsd
-
-
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
- Source Files
-
-
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
-
\ No newline at end of file
diff --git a/build/WinStd-15.0.vcxproj.filters b/build/WinStd-15.0.vcxproj.filters
index cbf838d0..3d31fc8b 100644
--- a/build/WinStd-15.0.vcxproj.filters
+++ b/build/WinStd-15.0.vcxproj.filters
@@ -41,6 +41,12 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
@@ -88,5 +94,11 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
\ No newline at end of file
diff --git a/build/WinStd.props b/build/WinStd.props
index 65fbe029..c32fe0a0 100644
--- a/build/WinStd.props
+++ b/build/WinStd.props
@@ -27,10 +27,12 @@
+
Create
+
@@ -45,8 +47,10 @@
+
+
diff --git a/include/WinStd/Base64.h b/include/WinStd/Base64.h
index 596578e3..71235c65 100644
--- a/include/WinStd/Base64.h
+++ b/include/WinStd/Base64.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -68,7 +68,7 @@ namespace winstd
/// \param[in ] is_last Is this the last block of data?
///
template
- inline void encode(_Out_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size, _In_opt_ bool is_last = true)
+ inline void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size, _In_opt_ bool is_last = true)
{
assert(data || !size);
@@ -200,7 +200,7 @@ namespace winstd
/// \param[in ] size Length of `data` in bytes
///
template
- inline void decode(_Out_ std::vector<_Ty, _Ax> &out, _Out_ bool &is_last, _In_z_count_(size) const _Tchr *data, _In_ size_t size)
+ inline void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_ bool &is_last, _In_z_count_(size) const _Tchr *data, _In_ size_t size)
{
is_last = false;
diff --git a/include/WinStd/COM.h b/include/WinStd/COM.h
index c6b632c4..d7a1e193 100644
--- a/include/WinStd/COM.h
+++ b/include/WinStd/COM.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -30,6 +30,7 @@
namespace winstd
{
class WINSTD_API com_runtime_error;
+ struct WINSTD_API CoTaskMemFree_delete;
template class com_obj;
class WINSTD_API bstr;
class WINSTD_API variant;
@@ -62,7 +63,7 @@ namespace winstd
/// \param[in] num COM error code
/// \param[in] msg Error message
///
- inline com_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg.c_str())
+ inline com_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg)
{
}
@@ -92,13 +93,35 @@ namespace winstd
/// \addtogroup WinStdCOM
/// @{
+ ///
+ /// Deleter for unique_ptr using CoTaskMemFree
+ ///
+ struct WINSTD_API CoTaskMemFree_delete
+ {
+ ///
+ /// Default constructor
+ ///
+ CoTaskMemFree_delete() {}
+
+ ///
+ /// Delete a pointer
+ ///
+ /// \sa [CoTaskMemFree function](https://docs.microsoft.com/en-us/windows/desktop/api/combaseapi/nf-combaseapi-cotaskmemfree)
+ ///
+ template
+ void operator()(_T *_Ptr) const
+ {
+ CoTaskMemFree(_Ptr);
+ }
+ };
+
///
/// COM object wrapper template
///
template
- class com_obj : public dplhandle
+ class com_obj : public dplhandle
{
- DPLHANDLE_IMPL(com_obj)
+ DPLHANDLE_IMPL(com_obj, NULL)
public:
///
@@ -143,7 +166,7 @@ namespace winstd
///
virtual ~com_obj()
{
- if (m_h)
+ if (m_h != invalid)
m_h->Release();
}
@@ -225,9 +248,9 @@ namespace winstd
///
/// BSTR string wrapper
///
- class WINSTD_API bstr : public dplhandle
+ class WINSTD_API bstr : public dplhandle
{
- DPLHANDLE_IMPL(bstr)
+ DPLHANDLE_IMPL(bstr, NULL)
public:
///
diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h
index 68bb7d85..6152ed4a 100644
--- a/include/WinStd/Common.h
+++ b/include/WinStd/Common.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -46,6 +46,7 @@
#include
+#include
#include
#include
#include
@@ -107,35 +108,80 @@ private: \
inline C (_In_ const C &h); \
inline C& operator=(_In_ const C &h);
+///
+/// Declares a class as non-movable
+///
+#define WINSTD_NONMOVABLE(C) \
+private: \
+ inline C (_Inout_ C &&h); \
+ inline C& operator=(_Inout_ C &&h);
+
/// @}
+
+/// \addtogroup WinStdStrFormat
+/// @{
+
+///
+/// LPTSTR printf/scanf format specifier
+///
+#ifdef UNICODE
+#define PRINTF_LPTSTR "ls"
+#else
+#define PRINTF_LPTSTR "s"
+#endif
+
+///
+/// LPOLESTR printf/scanf format specifier
+///
+#ifdef OLE2ANSI
+#define PRINTF_LPOLESTR "hs"
+#else
+#define PRINTF_LPOLESTR "ls"
+#endif
+
+#ifdef _UNICODE
+#define _tcin (std::wcin )
+#define _tcout (std::wcout)
+#define _tcerr (std::wcerr)
+#define _tclog (std::wclog)
+#else
+#define _tcin (std::cin )
+#define _tcout (std::cout)
+#define _tcerr (std::cerr)
+#define _tclog (std::clog)
+#endif
+
+/// @}
+
+
/// \addtogroup WinStdSysHandles
/// @{
///
/// Implements default constructors and operators to prevent their auto-generation by compiler.
///
-#define HANDLE_IMPL(C) \
+#define HANDLE_IMPL(C, INVAL) \
public: \
- inline C ( ) { } \
- inline C (_In_ handle_type h) : handle( h ) { } \
- inline C (_Inout_ C &&h) noexcept : handle(std::move(h)) { } \
- inline C& operator=(_In_ handle_type h) { handle::operator=( h ); return *this; } \
- inline C& operator=(_Inout_ C &&h) noexcept { handle::operator=(std::move(h)); return *this; } \
+ inline C ( ) { } \
+ inline C (_In_ handle_type h) : handle( h ) { } \
+ inline C (_Inout_ C &&h) noexcept : handle(std::move(h)) { } \
+ inline C& operator=(_In_ handle_type h) { handle::operator=( h ); return *this; } \
+ inline C& operator=(_Inout_ C &&h) noexcept { handle::operator=(std::move(h)); return *this; } \
WINSTD_NONCOPYABLE(C)
///
/// Implements default constructors and operators to prevent their auto-generation by compiler.
///
-#define DPLHANDLE_IMPL(C) \
+#define DPLHANDLE_IMPL(C, INVAL) \
public: \
- inline C ( ) { } \
- inline C (_In_ handle_type h) : dplhandle( h ) { } \
- inline C (_In_ const C &h) : dplhandle(duplicate_internal(h.m_h)) { } \
- inline C (_Inout_ C &&h) noexcept : dplhandle(std::move (h )) { } \
- inline C& operator=(_In_ handle_type h) { dplhandle::operator=( h ); return *this; } \
- inline C& operator=(_In_ const C &h) { dplhandle::operator=( h ); return *this; } \
- inline C& operator=(_Inout_ C &&h) noexcept { dplhandle::operator=(std::move(h)); return *this; } \
+ inline C ( ) { } \
+ inline C (_In_ handle_type h) : dplhandle( h ) { } \
+ inline C (_In_ const C &h) : dplhandle(duplicate_internal(h.m_h)) { } \
+ inline C (_Inout_ C &&h) noexcept : dplhandle(std::move (h )) { } \
+ inline C& operator=(_In_ handle_type h) { dplhandle::operator=( h ); return *this; } \
+ inline C& operator=(_In_ const C &h) { dplhandle::operator=( h ); return *this; } \
+ inline C& operator=(_Inout_ C &&h) noexcept { dplhandle::operator=(std::move(h)); return *this; } \
private:
/// @}
@@ -166,8 +212,8 @@ namespace winstd
template struct LocalFree_delete<_Ty[]>;
template> class ref_unique_ptr;
template class ref_unique_ptr<_Ty[], _Dx>;
- template class handle;
- template class dplhandle;
+ template class handle;
+ template class dplhandle;
template class vector_queue;
template class num_runtime_error;
class WINSTD_API win_runtime_error;
@@ -262,6 +308,8 @@ namespace winstd
/// @{
template class sanitizing_allocator;
+ template class __declspec(novtable) sanitizing_blob;
+
///
/// A sanitizing variant of std::string
@@ -331,7 +379,7 @@ inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _
///
/// \returns Number of characters in result.
///
-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 vsprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, _In_ va_list arg);
///
/// Formats string using `printf()`.
@@ -341,27 +389,28 @@ template inline int vsprintf(_Out_ std::b
///
/// \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, ...);
+template inline int sprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...);
///
/// Formats a message string.
///
/// \sa [FormatMessage function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351.aspx)
///
-template inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string &str, _In_opt_ va_list *Arguments);
+template inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments);
///
/// Formats a message string.
///
/// \sa [FormatMessage function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351.aspx)
///
-template inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string &str, _In_opt_ va_list *Arguments);
+template inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments);
/// @}
#pragma once
#include
+#include
#include
#include
@@ -610,7 +659,7 @@ 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
+ template
class handle
{
public:
@@ -620,9 +669,14 @@ namespace winstd
typedef T handle_type;
///
- /// Initializes a new class instance with the object handle set to NULL.
+ /// Invalid handle value
///
- inline handle() : m_h(NULL)
+ static const T invalid;
+
+ ///
+ /// Initializes a new class instance with the object handle set to INVAL.
+ ///
+ inline handle() : m_h(invalid)
{
}
@@ -640,17 +694,17 @@ namespace winstd
///
/// \param[inout] h A rvalue reference of another object
///
- inline handle(_Inout_ handle &&h) noexcept
+ inline handle(_Inout_ handle &&h) noexcept
{
// Transfer handle.
m_h = h.m_h;
- h.m_h = NULL;
+ h.m_h = invalid;
}
private:
// This class is noncopyable.
- handle(_In_ const handle &h);
- handle& operator=(_In_ const handle &h);
+ handle(_In_ const handle &h);
+ handle& operator=(_In_ const handle &h);
public:
///
@@ -658,7 +712,7 @@ namespace winstd
///
/// \param[in] h Object handle value
///
- inline handle& operator=(_In_ handle_type h)
+ inline handle& operator=(_In_ handle_type h)
{
attach(h);
return *this;
@@ -669,14 +723,14 @@ namespace winstd
///
/// \param[inout] h A rvalue reference of another object
///
- inline handle& operator=(_Inout_ handle &&h) noexcept
+ inline handle& operator=(_Inout_ handle &&h) noexcept
{
if (this != std::addressof(h)) {
// Transfer handle.
- if (m_h)
+ if (m_h != invalid)
free_internal();
m_h = h.m_h;
- h.m_h = NULL;
+ h.m_h = invalid;
}
return *this;
}
@@ -698,7 +752,7 @@ namespace winstd
///
inline handle_type*& operator*() const
{
- assert(m_h != NULL);
+ assert(m_h != invalid);
return *m_h;
}
@@ -708,7 +762,7 @@ namespace winstd
///
inline handle_type* operator&()
{
- assert(m_h == NULL);
+ assert(m_h == invalid);
return &m_h;
}
@@ -719,20 +773,20 @@ namespace winstd
///
inline handle_type operator->() const
{
- assert(m_h != NULL);
+ assert(m_h != invalid);
return m_h;
}
///
- /// Tests if the object handle is NULL.
+ /// Tests if the object handle is INVAL.
///
/// \return
- /// - Non zero when object handle is NULL;
+ /// - Non zero when object handle is INVAL;
/// - Zero otherwise.
///
inline bool operator!() const
{
- return m_h == NULL;
+ return m_h == invalid;
}
///
@@ -816,13 +870,13 @@ namespace winstd
///
/// Sets a new object handle for the class
///
- /// When the current object handle of the class is non-NULL, the object is destroyed first.
+ /// When the current object handle of the class is non-INVAL, the object is destroyed first.
///
/// \param[in] h New object handle
///
- inline void attach(_In_ handle_type h)
+ inline void attach(_In_opt_ handle_type h)
{
- if (m_h)
+ if (m_h != invalid)
free_internal();
m_h = h;
}
@@ -835,7 +889,7 @@ namespace winstd
inline handle_type detach()
{
handle_type h = m_h;
- m_h = NULL;
+ m_h = invalid;
return h;
}
@@ -844,9 +898,9 @@ namespace winstd
///
inline void free()
{
- if (m_h) {
+ if (m_h != invalid) {
free_internal();
- m_h = NULL;
+ m_h = invalid;
}
}
@@ -863,15 +917,19 @@ namespace winstd
};
+ template
+ const T handle::invalid = INVAL;
+
+
///
/// Base abstract template class to support object handle keeping for objects that support handle duplication
///
- template
- class dplhandle : public handle
+ template
+ class dplhandle : public handle
{
public:
///
- /// Initializes a new class instance with the object handle set to NULL.
+ /// Initializes a new class instance with the object handle set to INVAL.
///
inline dplhandle()
{
@@ -882,7 +940,7 @@ namespace winstd
///
/// \param[in] h Initial object handle value
///
- inline dplhandle(_In_ handle_type h) : handle(h)
+ inline dplhandle(_In_ handle_type h) : handle(h)
{
}
@@ -891,7 +949,7 @@ namespace winstd
///
/// \param[inout] h A reference of another object
///
- inline dplhandle(_In_ const dplhandle &h) : handle(internal_duplicate(h.m_h))
+ inline dplhandle(_In_ const dplhandle &h) : handle(internal_duplicate(h.m_h))
{
}
@@ -900,7 +958,7 @@ namespace winstd
///
/// \param[inout] h A rvalue reference of another object
///
- inline dplhandle(_Inout_ dplhandle &&h) noexcept : handle(std::move(h))
+ inline dplhandle(_Inout_ dplhandle &&h) noexcept : handle(std::move(h))
{
}
@@ -909,9 +967,9 @@ namespace winstd
///
/// \param[in] h Object handle value
///
- inline dplhandle& operator=(_In_ handle_type h)
+ inline dplhandle& operator=(_In_ handle_type h)
{
- handle::operator=(h);
+ handle::operator=(h);
return *this;
}
@@ -920,23 +978,23 @@ namespace winstd
///
/// \param[in] h Object
///
- inline dplhandle& operator=(_In_ const dplhandle &h)
+ inline dplhandle& operator=(_In_ const dplhandle &h)
{
if (this != std::addressof(h)) {
- if (h.m_h) {
+ if (h.m_h != invalid) {
handle_type h_new = duplicate_internal(h.m_h);
- if (h_new) {
- if (m_h)
+ if (h_new != invalid) {
+ if (m_h != invalid)
free_internal();
m_h = h_new;
} else
assert(0); // Could not duplicate the handle
} else {
- if (m_h)
+ if (m_h != invalid)
free_internal();
- m_h = NULL;
+ m_h = invalid;
}
}
return *this;
@@ -947,9 +1005,9 @@ namespace winstd
///
/// \param[inout] h A rvalue reference of another object
///
- inline dplhandle& operator=(_Inout_ dplhandle &&h) noexcept
+ inline dplhandle& operator=(_Inout_ dplhandle &&h) noexcept
{
- handle::operator=(std::move(h));
+ handle::operator=(std::move(h));
return *this;
}
@@ -960,7 +1018,7 @@ namespace winstd
///
inline handle_type duplicate() const
{
- return m_h ? duplicate_internal(m_h) : NULL;
+ return m_h != invalid ? duplicate_internal(m_h) : invalid;
}
///
@@ -974,10 +1032,10 @@ namespace winstd
///
inline bool attach_duplicated(_In_ handle_type h)
{
- if (m_h)
+ if (m_h != invalid)
free_internal();
- return h ? (m_h = duplicate_internal(h)) != NULL : (m_h = NULL, true);
+ return h != invalid ? (m_h = duplicate_internal(h)) != invalid : (m_h = invalid, true);
}
protected:
@@ -1423,7 +1481,7 @@ namespace winstd
///
inline num_runtime_error(_In_ error_type num, _In_ const std::string& msg) :
m_num(num),
- runtime_error(msg.c_str())
+ runtime_error(msg)
{
}
@@ -1494,7 +1552,7 @@ namespace winstd
/// \param[in] num Windows error code
/// \param[in] msg Error message
///
- inline win_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg.c_str())
+ inline win_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg)
{
}
@@ -1515,7 +1573,7 @@ namespace winstd
///
/// \param[in] msg Error message
///
- inline win_runtime_error(_In_ const std::string& msg) : num_runtime_error(GetLastError(), msg.c_str())
+ inline win_runtime_error(_In_ const std::string& msg) : num_runtime_error(GetLastError(), msg)
{
}
@@ -1538,6 +1596,23 @@ namespace winstd
inline win_runtime_error(const win_runtime_error &other) : num_runtime_error(other)
{
}
+
+
+ ///
+ /// Returns a user-readable Windows error message
+ ///
+ /// \sa [FormatMessage function](https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-formatmessage)
+ ///
+ inline tstring msg(_In_opt_ DWORD dwLanguageId = 0) const
+ {
+ tstring str;
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, m_num, dwLanguageId, str, NULL)) {
+ // Stock Windows error messages contain CRLF. Well... Trim all the trailing white space.
+ str.erase(str.find_last_not_of(_T(" \t\n\r\f\v")) + 1);
+ } else
+ sprintf(str, m_num >= 0x10000 ? _T("Error 0x%X") : _T("Error %u"), m_num);
+ return str;
+ }
};
/// @}
@@ -1868,6 +1943,33 @@ namespace winstd
#pragma warning(pop)
+ ///
+ /// Sanitizing BLOB
+ ///
+ template
+ class __declspec(novtable) sanitizing_blob
+ {
+ public:
+ ///
+ /// Constructs uninitialized BLOB
+ ///
+ inline sanitizing_blob()
+ {
+ ZeroMemory(m_data, N);
+ }
+
+ ///
+ /// Sanitizes BLOB
+ ///
+ inline ~sanitizing_blob()
+ {
+ SecureZeroMemory(m_data, N);
+ }
+
+ public:
+ unsigned char m_data[N]; ///< BLOB data
+ };
+
/// @}
}
@@ -1895,7 +1997,7 @@ inline int vsnprintf(_Out_z_cap_(capacity) wchar_t *str, _In_ size_t capacity, _
template
-inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, _In_ va_list arg)
+inline int vsprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, _In_ va_list arg)
{
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
@@ -1923,7 +2025,7 @@ inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _P
template
-inline int sprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...)
+inline int sprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...)
{
va_list arg;
va_start(arg, format);
@@ -1934,7 +2036,7 @@ inline int sprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Pr
template
-inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string &str, _In_opt_ va_list *Arguments)
+inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments)
{
std::unique_ptr > lpBuffer;
DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast((LPSTR*)get_ptr(lpBuffer)), 0, Arguments);
@@ -1945,7 +2047,7 @@ inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ D
template
-inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string &str, _In_opt_ va_list *Arguments)
+inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments)
{
std::unique_ptr > lpBuffer;
DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast((LPWSTR*)get_ptr(lpBuffer)), 0, Arguments);
diff --git a/include/WinStd/Cred.h b/include/WinStd/Cred.h
index e6658660..6cb6d855 100644
--- a/include/WinStd/Cred.h
+++ b/include/WinStd/Cred.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -44,27 +44,27 @@ namespace winstd
///
/// \sa [CredEnumerate function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa374794.aspx)
///
-inline BOOL CredEnumerate(_In_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Out_ std::unique_ptr > &cCredentials);
+inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr > &cCredentials);
/// @copydoc CredProtectW()
-template inline BOOL CredProtectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType);
+template inline 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);
///
/// 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)
///
-template inline BOOL CredProtectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType);
+template inline 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);
/// @copydoc CredUnprotectW()
-template inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials);
+template inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials);
///
/// 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)
///
-template inline BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials);
+template inline BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials);
/// @}
@@ -143,17 +143,20 @@ namespace winstd
}
-inline BOOL CredEnumerate(_In_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Out_ std::unique_ptr > &cCredentials)
+inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr > &cCredentials)
{
- PCREDENTIAL *pCredentials = NULL;
- BOOL bResult = CredEnumerate(Filter, Flags, Count, &pCredentials);
- cCredentials.reset(pCredentials);
- return bResult;
+ PCREDENTIAL *pCredentials;
+ if (CredEnumerate(Filter, Flags, Count, &pCredentials)) {
+ cCredentials.reset(pCredentials);
+ return TRUE;
+ }
+
+ return FALSE;
}
template
-inline BOOL CredProtectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType)
+inline 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)
{
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(buf);
@@ -177,7 +180,7 @@ inline BOOL CredProtectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszCredentials, _In_ DWO
template
-inline BOOL CredProtectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType)
+inline 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)
{
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(buf);
@@ -201,7 +204,7 @@ inline BOOL CredProtectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszCredentials, _In_ DW
template
-inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials)
+inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials)
{
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(buf);
@@ -225,7 +228,7 @@ inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszProtectedCredential
template
-inline BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials)
+inline BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials)
{
_Elem buf[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(buf);
diff --git a/include/WinStd/Crypt.h b/include/WinStd/Crypt.h
index 4860b8c6..61d501ef 100644
--- a/include/WinStd/Crypt.h
+++ b/include/WinStd/Crypt.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -45,35 +45,35 @@ namespace winstd
/// @{
/// @copydoc CertGetNameStringW()
-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 CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_ void *pvTypePara, _Inout_ std::basic_string<_Elem, _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.
///
/// \sa [CertGetNameString function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086.aspx)
///
-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 DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_ void *pvTypePara, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sNameString);
///
/// Retrieves the information contained in an extended property of a certificate context.
///
/// \sa [CertGetCertificateContextProperty function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376079.aspx)
///
-template inline BOOL WINAPI CertGetCertificateContextProperty(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwPropId, _Out_ std::vector<_Ty, _Ax> &aData);
+template inline BOOL WINAPI CertGetCertificateContextProperty(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwPropId, _Inout_ std::vector<_Ty, _Ax> &aData);
///
/// Retrieves data that governs the operations of a hash object. The actual hash value can be retrieved by using this function.
///
/// \sa [CryptGetHashParam function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379947.aspx)
///
-template inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags);
+template inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Inout_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags);
///
/// Retrieves data that governs the operations of a key.
///
/// \sa [CryptGetKeyParam function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379949.aspx)
///
-template inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags);
+template inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Inout_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags);
///
/// Retrieves data that governs the operations of a key.
@@ -87,7 +87,7 @@ template inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD d
///
/// \sa [CryptExportKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379931.aspx)
///
-template inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWORD dwBlobType, _In_ DWORD dwFlags, _Out_ std::vector<_Ty, _Ax> &aData);
+template inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWORD dwBlobType, _In_ DWORD dwFlags, _Inout_ std::vector<_Ty, _Ax> &aData);
///
/// Encrypts data.
@@ -120,9 +120,9 @@ namespace winstd
///
/// PCCERT_CONTEXT wrapper class
///
- class WINSTD_API cert_context : public dplhandle
+ class WINSTD_API cert_context : public dplhandle
{
- DPLHANDLE_IMPL(cert_context)
+ DPLHANDLE_IMPL(cert_context, NULL)
public:
///
@@ -144,7 +144,7 @@ namespace winstd
inline bool create(_In_ DWORD dwCertEncodingType, _In_ const BYTE *pbCertEncoded, _In_ DWORD cbCertEncoded)
{
handle_type h = CertCreateCertificateContext(dwCertEncodingType, pbCertEncoded, cbCertEncoded);
- if (h) {
+ if (h != invalid) {
attach(h);
return true;
} else
@@ -161,6 +161,7 @@ namespace winstd
///
inline bool operator==(_In_ const handle_type &other) const
{
+ // TODO: [Crypto] Make constant time.
return
m_h == other ||
m_h->cbCertEncoded == other->cbCertEncoded && memcmp(m_h->pbCertEncoded, other->pbCertEncoded, m_h->cbCertEncoded) == 0;
@@ -189,6 +190,7 @@ namespace winstd
///
inline bool operator<(_In_ const handle_type &other) const
{
+ // TODO: [Crypto] Make constant time.
int r = memcmp(m_h->pbCertEncoded, other->pbCertEncoded, std::min(m_h->cbCertEncoded, other->cbCertEncoded));
return r < 0 || r == 0 && m_h->cbCertEncoded < other->cbCertEncoded;
}
@@ -203,6 +205,7 @@ namespace winstd
///
inline bool operator>(_In_ const handle_type &other) const
{
+ // TODO: [Crypto] Make constant time.
int r = memcmp(m_h->pbCertEncoded, other->pbCertEncoded, std::min(m_h->cbCertEncoded, other->cbCertEncoded));
return r > 0 || r == 0 && m_h->cbCertEncoded > other->cbCertEncoded;
}
@@ -257,9 +260,9 @@ namespace winstd
///
/// PCCERT_CHAIN_CONTEXT wrapper class
///
- class WINSTD_API cert_chain_context : public dplhandle
+ class WINSTD_API cert_chain_context : public dplhandle
{
- DPLHANDLE_IMPL(cert_chain_context)
+ DPLHANDLE_IMPL(cert_chain_context, NULL)
public:
///
@@ -312,9 +315,9 @@ namespace winstd
///
/// HCERTSTORE wrapper class
///
- class WINSTD_API cert_store : public handle
+ class WINSTD_API cert_store : public handle
{
- HANDLE_IMPL(cert_store)
+ HANDLE_IMPL(cert_store, NULL)
public:
///
@@ -336,7 +339,7 @@ namespace winstd
inline bool create(_In_ LPCSTR lpszStoreProvider, _In_ DWORD dwEncodingType, _In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_ DWORD dwFlags, _In_opt_ const void *pvPara)
{
handle_type h = CertOpenStore(lpszStoreProvider, dwEncodingType, hCryptProv, dwFlags, pvPara);
- if (h) {
+ if (h != invalid) {
attach(h);
return true;
} else
@@ -352,10 +355,10 @@ namespace winstd
///
/// \sa [CertOpenSystemStore function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376560.aspx)
///
- inline bool create(_In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_ LPCTSTR szSubsystemProtocol)
+ inline bool create(_In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_z_ LPCTSTR szSubsystemProtocol)
{
handle_type h = CertOpenSystemStore(hCryptProv, szSubsystemProtocol);
- if (h) {
+ if (h != invalid) {
attach(h);
return true;
} else
@@ -375,9 +378,9 @@ namespace winstd
///
/// HCRYPTPROV wrapper class
///
- class WINSTD_API crypt_prov : public handle
+ class WINSTD_API crypt_prov : public handle
{
- HANDLE_IMPL(crypt_prov)
+ HANDLE_IMPL(crypt_prov, NULL)
public:
///
@@ -396,7 +399,7 @@ namespace winstd
///
/// \sa [CryptAcquireContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886.aspx)
///
- inline bool create(_In_opt_ LPCTSTR szContainer, _In_opt_ LPCTSTR szProvider, _In_ DWORD dwProvType, _In_ DWORD dwFlags = 0)
+ inline bool create(_In_opt_z_ LPCTSTR szContainer, _In_opt_z_ LPCTSTR szProvider, _In_ DWORD dwProvType, _In_ DWORD dwFlags = 0)
{
handle_type h;
if (CryptAcquireContext(&h, szContainer, szProvider, dwProvType, dwFlags)) {
@@ -419,9 +422,9 @@ namespace winstd
///
/// HCRYPTHASH wrapper class
///
- class WINSTD_API crypt_hash : public dplhandle
+ class WINSTD_API crypt_hash : public dplhandle
{
- DPLHANDLE_IMPL(crypt_hash)
+ DPLHANDLE_IMPL(crypt_hash, NULL)
public:
///
@@ -474,9 +477,9 @@ namespace winstd
///
/// HCRYPTKEY wrapper class
///
- class WINSTD_API crypt_key : public dplhandle
+ class WINSTD_API crypt_key : public dplhandle
{
- DPLHANDLE_IMPL(crypt_key)
+ DPLHANDLE_IMPL(crypt_key, NULL)
public:
///
@@ -698,7 +701,7 @@ namespace winstd
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)
+inline DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_ void *pvTypePara, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sNameString)
{
// Query the final string length first.
DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
@@ -712,7 +715,7 @@ inline DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwT
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)
+inline DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_ DWORD dwFlags, _In_ void *pvTypePara, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sNameString)
{
// Query the final string length first.
DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
@@ -726,7 +729,7 @@ inline DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwT
template
-inline BOOL WINAPI CertGetCertificateContextProperty(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwPropId, _Out_ std::vector<_Ty, _Ax> &aData)
+inline BOOL WINAPI CertGetCertificateContextProperty(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwPropId, _Inout_ std::vector<_Ty, _Ax> &aData)
{
BYTE buf[WINSTD_STACK_BUFFER_BYTES];
DWORD dwSize = WINSTD_STACK_BUFFER_BYTES;
@@ -742,13 +745,12 @@ inline BOOL WINAPI CertGetCertificateContextProperty(_In_ PCCERT_CONTEXT pCertCo
return TRUE;
}
- aData.clear();
return FALSE;
}
template
-inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags)
+inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Inout_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags)
{
BYTE buf[WINSTD_STACK_BUFFER_BYTES];
DWORD dwSize = WINSTD_STACK_BUFFER_BYTES;
@@ -764,7 +766,6 @@ inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_ s
return TRUE;
}
- aData.clear();
return FALSE;
}
@@ -778,7 +779,7 @@ inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_ T
template
-inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags)
+inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Inout_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags)
{
BYTE buf[WINSTD_STACK_BUFFER_BYTES];
DWORD dwSize = WINSTD_STACK_BUFFER_BYTES;
@@ -794,7 +795,6 @@ inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Out_ std:
return TRUE;
}
- aData.clear();
return FALSE;
}
@@ -808,7 +808,7 @@ inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Out_ T &d
template
-inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWORD dwBlobType, _In_ DWORD dwFlags, _Out_ std::vector<_Ty, _Ax> &aData)
+inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWORD dwBlobType, _In_ DWORD dwFlags, _Inout_ std::vector<_Ty, _Ax> &aData)
{
DWORD dwKeyBLOBSize = 0;
@@ -818,7 +818,6 @@ inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWO
return TRUE;
}
- aData.clear();
return FALSE;
}
diff --git a/include/WinStd/EAP.h b/include/WinStd/EAP.h
index abc28145..e83e0f9d 100644
--- a/include/WinStd/EAP.h
+++ b/include/WinStd/EAP.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -105,6 +105,7 @@ inline bool operator!=(_In_ const EAP_METHOD_TYPE &a, _In_ const EAP_METHOD_TYPE
#include
#include
#include
+#include
namespace winstd
@@ -394,9 +395,9 @@ namespace winstd
///
/// EapPacket wrapper class
///
- class WINSTD_API eap_packet : public dplhandle
+ class WINSTD_API eap_packet : public dplhandle
{
- DPLHANDLE_IMPL(eap_packet)
+ DPLHANDLE_IMPL(eap_packet, NULL)
public:
///
@@ -423,7 +424,7 @@ namespace winstd
assert(size >= 4); // EAP packets must contain at least Code, Id, and Length fields: 4B.
handle_type h = (handle_type)HeapAlloc(GetProcessHeap(), 0, size);
- if (h) {
+ if (h != NULL) {
h->Code = (BYTE) code ;
h->Id = id ;
*(WORD*)h->Length = htons(size);
@@ -442,7 +443,7 @@ namespace winstd
///
inline WORD size() const
{
- return m_h ? ntohs(*(WORD*)m_h->Length) : 0;
+ return m_h != NULL ? ntohs(*(WORD*)m_h->Length) : 0;
}
diff --git a/include/WinStd/ETW.h b/include/WinStd/ETW.h
index 9102093b..090364a9 100644
--- a/include/WinStd/ETW.h
+++ b/include/WinStd/ETW.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -55,21 +55,21 @@ namespace winstd
///
/// \sa [TdhGetEventInformation function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa964840.aspx)
///
-inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _Out_ std::unique_ptr &info);
+inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _Inout_ std::unique_ptr &info);
///
/// Retrieves information about the event map contained in the event.
///
/// \sa [TdhGetEventMapInformation function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa964841.aspx)
///
-inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Out_ std::unique_ptr &info);
+inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Inout_ std::unique_ptr &info);
///
/// Retrieves a property value from the event data.
///
/// \sa [TdhGetProperty function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa964843.aspx)
///
-template inline ULONG TdhGetProperty(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _In_ ULONG PropertyDataCount, _In_ PPROPERTY_DATA_DESCRIPTOR pPropertyData, _Out_ std::vector<_Ty, _Ax> &aData);
+template inline ULONG TdhGetProperty(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _In_ ULONG PropertyDataCount, _In_ PPROPERTY_DATA_DESCRIPTOR pPropertyData, _Inout_ std::vector<_Ty, _Ax> &aData);
/// @}
@@ -381,9 +381,9 @@ namespace winstd
///
/// ETW event provider
///
- class WINSTD_API event_provider : public handle
+ class WINSTD_API event_provider : public handle
{
- HANDLE_IMPL(event_provider)
+ HANDLE_IMPL(event_provider, NULL)
public:
///
@@ -424,7 +424,7 @@ namespace winstd
///
inline ULONG write(_In_ PCEVENT_DESCRIPTOR EventDescriptor)
{
- assert(m_h);
+ assert(m_h != invalid);
return EventWrite(m_h, EventDescriptor, 0, NULL);
}
@@ -440,7 +440,7 @@ namespace winstd
///
inline ULONG write(_In_ PCEVENT_DESCRIPTOR EventDescriptor, _In_ ULONG UserDataCount = 0, _In_opt_count_(UserDataCount) PEVENT_DATA_DESCRIPTOR UserData = NULL)
{
- assert(m_h);
+ assert(m_h != invalid);
return EventWrite(m_h, EventDescriptor, UserDataCount, UserData);
}
@@ -458,7 +458,7 @@ namespace winstd
///
inline ULONG write(_In_ PCEVENT_DESCRIPTOR EventDescriptor, _In_ const EVENT_DATA_DESCRIPTOR param1, ...)
{
- assert(m_h);
+ assert(m_h != invalid);
// The first argument (param1) is outside of varadic argument list.
if (param1.Ptr == winstd::event_data::blank.Ptr &&
@@ -513,7 +513,7 @@ namespace winstd
///
inline ULONG write(_In_ PCEVENT_DESCRIPTOR EventDescriptor, _In_ va_list arg)
{
- assert(m_h);
+ assert(m_h != invalid);
va_list arg_start = arg;
std::vector params;
@@ -556,7 +556,7 @@ namespace winstd
///
inline ULONG write(_In_ UCHAR Level, _In_ ULONGLONG Keyword, _In_z_ _Printf_format_string_ PCWSTR String, ...)
{
- assert(m_h);
+ assert(m_h != invalid);
std::wstring msg;
va_list arg;
@@ -599,7 +599,7 @@ namespace winstd
///
/// ETW session
///
- class WINSTD_API event_session : public handle
+ class WINSTD_API event_session : public handle
{
WINSTD_NONCOPYABLE(event_session)
@@ -654,8 +654,8 @@ namespace winstd
inline event_session& operator=(_Inout_ event_session &&other) noexcept
{
if (this != std::addressof(other)) {
- (handle&&)*this = std::move(other);
- m_prop = std::move(other.m_prop);
+ (handle&&)*this = std::move(other);
+ m_prop = std::move(other.m_prop);
}
return *this;
}
@@ -694,7 +694,7 @@ namespace winstd
///
inline void attach(_In_opt_ handle_type h, _In_ EVENT_TRACE_PROPERTIES *prop)
{
- handle::attach(h);
+ handle::attach(h);
m_prop.reset(prop);
}
@@ -708,7 +708,7 @@ namespace winstd
///
/// \sa [StartTrace function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa364117.aspx)
///
- inline ULONG create(_In_ LPCTSTR SessionName, _In_ const EVENT_TRACE_PROPERTIES *Properties)
+ inline ULONG create(_In_z_ LPCTSTR SessionName, _In_ const EVENT_TRACE_PROPERTIES *Properties)
{
handle_type h;
std::unique_ptr prop(reinterpret_cast(new char[Properties->Wnode.BufferSize]));
@@ -731,7 +731,7 @@ namespace winstd
///
inline ULONG enable_trace(_In_ LPCGUID ProviderId, _In_ UCHAR Level, _In_opt_ ULONGLONG MatchAnyKeyword = 0, _In_opt_ ULONGLONG MatchAllKeyword = 0, _In_opt_ ULONG EnableProperty = 0, _In_opt_ PEVENT_FILTER_DESCRIPTOR EnableFilterDesc = NULL)
{
- assert(m_h);
+ assert(m_h != invalid);
return EnableTraceEx(
ProviderId,
&m_prop->Wnode.Guid,
@@ -756,7 +756,7 @@ namespace winstd
///
inline ULONG disable_trace(_In_ LPCGUID ProviderId, _In_ UCHAR Level, _In_opt_ ULONGLONG MatchAnyKeyword = 0, _In_opt_ ULONGLONG MatchAllKeyword = 0, _In_opt_ ULONG EnableProperty = 0, _In_opt_ PEVENT_FILTER_DESCRIPTOR EnableFilterDesc = NULL)
{
- assert(m_h);
+ assert(m_h != invalid);
return EnableTraceEx(
ProviderId,
&m_prop->Wnode.Guid,
@@ -786,9 +786,9 @@ namespace winstd
///
/// ETW trace
///
- class WINSTD_API event_trace : public handle
+ class WINSTD_API event_trace : public handle
{
- HANDLE_IMPL(event_trace)
+ HANDLE_IMPL(event_trace, INVALID_PROCESSTRACE_HANDLE)
public:
///
@@ -811,7 +811,7 @@ namespace winstd
inline bool create(_Inout_ PEVENT_TRACE_LOGFILE Logfile)
{
handle_type h = OpenTrace(Logfile);
- if (h != (TRACEHANDLE)INVALID_HANDLE_VALUE) {
+ if (h != invalid) {
attach(h);
return true;
} else
@@ -1130,7 +1130,7 @@ namespace winstd
}
-inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _Out_ std::unique_ptr &info)
+inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _Inout_ std::unique_ptr &info)
{
BYTE szBuffer[WINSTD_STACK_BUFFER_BYTES];
ULONG ulSize = sizeof(szBuffer), ulResult;
@@ -1148,12 +1148,11 @@ inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhCon
return TdhGetEventInformation(pEvent, TdhContextCount, pTdhContext, info.get(), &ulSize);
}
- info.reset(nullptr);
return ulResult;
}
-inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Out_ std::unique_ptr &info)
+inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Inout_ std::unique_ptr &info)
{
BYTE szBuffer[WINSTD_STACK_BUFFER_BYTES];
ULONG ulSize = sizeof(szBuffer), ulResult;
@@ -1171,13 +1170,12 @@ inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pM
return TdhGetEventMapInformation(pEvent, pMapName, info.get(), &ulSize);
}
- info.reset(nullptr);
return ulResult;
}
template
-inline ULONG TdhGetProperty(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _In_ ULONG PropertyDataCount, _In_ PPROPERTY_DATA_DESCRIPTOR pPropertyData, _Out_ std::vector<_Ty, _Ax> &aData)
+inline ULONG TdhGetProperty(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _In_ ULONG PropertyDataCount, _In_ PPROPERTY_DATA_DESCRIPTOR pPropertyData, _Inout_ std::vector<_Ty, _Ax> &aData)
{
ULONG ulSize, ulResult;
diff --git a/include/WinStd/Hex.h b/include/WinStd/Hex.h
index 3805a171..5394f66a 100644
--- a/include/WinStd/Hex.h
+++ b/include/WinStd/Hex.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -64,7 +64,7 @@ namespace winstd
/// \param[in ] size Length of `data` in bytes
///
template
- inline void encode(_Out_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size)
+ inline void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size)
{
assert(data || !size);
diff --git a/include/WinStd/MSI.h b/include/WinStd/MSI.h
index 201b6fed..a35910ec 100644
--- a/include/WinStd/MSI.h
+++ b/include/WinStd/MSI.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -34,61 +34,61 @@
/// @{
/// @copydoc MsiGetPropertyW()
-template inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
///
/// 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)
///
-template inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
/// @copydoc MsiRecordGetStringW()
-template inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
///
/// 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)
///
-template inline UINT MsiRecordGetStringW(_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, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
/// @copydoc MsiFormatRecordW()
-template inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
///
/// 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)
///
-template inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
///
/// Reads bytes from a record stream field into a std::vector buffer.
///
/// \sa [MsiRecordReadStream function](https://msdn.microsoft.com/en-us/library/aa370370.aspx)
///
-template inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::vector<_Ty, _Ax> &binData);
+template inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::vector<_Ty, _Ax> &binData);
/// @copydoc MsiGetTargetPathW()
-template inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
///
/// 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)
///
-template inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
/// @copydoc MsiGetComponentPathW()
-template inline INSTALLSTATE MsiGetComponentPathA(_In_ LPCSTR szProduct, _In_ LPCSTR szComponent, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<_Elem, _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.
///
/// \sa [MsiGetComponentPath function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa370112.aspx)
///
-template inline INSTALLSTATE MsiGetComponentPathW(_In_ LPCWSTR szProduct, _In_ LPCWSTR szComponent, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
+template inline INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
/// @}
@@ -96,7 +96,7 @@ template inline INSTALLSTATE MsiGetCompon
template
-inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
assert(0); // TODO: Test this code.
@@ -124,7 +124,7 @@ inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ s
template
-inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(szStackBuffer);
@@ -150,7 +150,7 @@ inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_
template
-inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
assert(0); // TODO: Test this code.
@@ -178,7 +178,7 @@ inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
template
-inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(szStackBuffer);
@@ -204,7 +204,7 @@ inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
template
-inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
assert(0); // TODO: Test this code.
@@ -232,7 +232,7 @@ inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_s
template
-inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(szStackBuffer);
@@ -258,7 +258,7 @@ inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_s
template
-inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::vector<_Ty, _Ax> &binData)
+inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::vector<_Ty, _Ax> &binData)
{
assert(0); // TODO: Test this code.
@@ -278,7 +278,7 @@ inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
template
-inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
assert(0); // TODO: Test this code.
@@ -306,7 +306,7 @@ inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Ou
template
-inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(szStackBuffer);
@@ -332,7 +332,7 @@ inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _O
template
-inline INSTALLSTATE MsiGetComponentPathA(_In_ LPCSTR szProduct, _In_ LPCSTR szComponent, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(szStackBuffer);
@@ -358,7 +358,7 @@ inline INSTALLSTATE MsiGetComponentPathA(_In_ LPCSTR szProduct, _In_ LPCSTR szCo
template
-inline INSTALLSTATE MsiGetComponentPathW(_In_ LPCWSTR szProduct, _In_ LPCWSTR szComponent, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
+inline INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue)
{
_Elem szStackBuffer[WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem)];
DWORD dwSize = _countof(szStackBuffer);
diff --git a/include/WinStd/Sec.h b/include/WinStd/Sec.h
index 2729c52a..427d6763 100644
--- a/include/WinStd/Sec.h
+++ b/include/WinStd/Sec.h
@@ -1,5 +1,5 @@
/*
- Copyright 1991-2018 Amebis
+ Copyright 1991-2019 Amebis
Copyright 2016 GÉANT
This file is part of WinStd.
@@ -41,14 +41,14 @@ namespace winstd
/// @{
/// @copydoc GetUserNameExW()
-template BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName);
+template BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _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.
///
/// \sa [GetUserNameEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435.aspx)
///
-template BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName);
+template BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName);
/// @}
@@ -223,7 +223,7 @@ namespace winstd
///
inline SECURITY_STATUS initialize(
_In_opt_ PCredHandle phCredential,
- _In_opt_ LPCTSTR pszTargetName,
+ _In_opt_z_ LPCTSTR pszTargetName,
_In_ ULONG fContextReq,
_In_ ULONG TargetDataRep,
_In_opt_ PSecBufferDesc pInput,
@@ -253,7 +253,7 @@ namespace winstd
///
inline SECURITY_STATUS process(
_In_opt_ PCredHandle phCredential,
- _In_opt_ LPCTSTR pszTargetName,
+ _In_opt_z_ LPCTSTR pszTargetName,
_In_ ULONG fContextReq,
_In_ ULONG TargetDataRep,
_In_opt_ PSecBufferDesc pInput,
@@ -322,7 +322,7 @@ namespace winstd
/// \param[in] num Security provider error code
/// \param[in] msg Error message
///
- inline sec_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg.c_str())
+ inline sec_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error(num, msg)
{
}
@@ -353,7 +353,7 @@ namespace winstd
template
-BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName)
+BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName)
{
assert(0); // TODO: Test this code.
@@ -376,13 +376,12 @@ BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_st
}
}
- sName.clear();
return FALSE;
}
template
-BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sName)
+BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sName)
{
assert(0); // TODO: Test this code.
@@ -405,6 +404,5 @@ BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_st
}
}
- sName.clear();
return FALSE;
}
diff --git a/include/WinStd/SetupAPI.h b/include/WinStd/SetupAPI.h
new file mode 100644
index 00000000..f3715d0d
--- /dev/null
+++ b/include/WinStd/SetupAPI.h
@@ -0,0 +1,167 @@
+/*
+ Copyright 1991-2019 Amebis
+ Copyright 2016 GÉANT
+
+ This file is part of WinStd.
+
+ Setup is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Setup is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Setup. If not, see