Pull changes from downstream
- Drop Visual Studio 2010 support - Update SAL - New and updated classes and templates - Copyright year update Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
7440a3f421
commit
f47faea71b
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,2 @@
|
||||
/*.sdf
|
||||
/*.suo
|
||||
/*.opensdf
|
||||
/doc
|
||||
/ipch
|
||||
/.vs
|
||||
|
@ -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
|
@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{47399D91-7EB9-41DE-B521-514BA5DB0C43}</ProjectGuid>
|
||||
<RootNamespace>WinStd</RootNamespace>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectName>WinStd</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="WinStd.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="WinStd.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="WinStd.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="WinStd.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,92 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\StdAfx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Base64.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\ETW.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\COM.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Crypt.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\EAP.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Win.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WinTrust.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Sec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WLAN.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Win.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\WinTrust.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\MSI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Crypt.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\WLAN.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Shell.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Common.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\EAP.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Sec.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Base64.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Cred.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\COM.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\ETW.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\Hex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -41,6 +41,12 @@
|
||||
<ClCompile Include="..\src\WLAN.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\SetupAPI.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WinSock2.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\StdAfx.h">
|
||||
@ -88,5 +94,11 @@
|
||||
<ClInclude Include="..\include\WinStd\Hex.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\SetupAPI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\WinStd\WinSock2.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -27,10 +27,12 @@
|
||||
<ClCompile Include="..\src\EAP.cpp" />
|
||||
<ClCompile Include="..\src\ETW.cpp" />
|
||||
<ClCompile Include="..\src\Sec.cpp" />
|
||||
<ClCompile Include="..\src\SetupAPI.cpp" />
|
||||
<ClCompile Include="..\src\StdAfx.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Win.cpp" />
|
||||
<ClCompile Include="..\src\WinSock2.cpp" />
|
||||
<ClCompile Include="..\src\WinTrust.cpp" />
|
||||
<ClCompile Include="..\src\WLAN.cpp" />
|
||||
</ItemGroup>
|
||||
@ -45,8 +47,10 @@
|
||||
<ClInclude Include="..\include\WinStd\Hex.h" />
|
||||
<ClInclude Include="..\include\WinStd\MSI.h" />
|
||||
<ClInclude Include="..\include\WinStd\Sec.h" />
|
||||
<ClInclude Include="..\include\WinStd\SetupAPI.h" />
|
||||
<ClInclude Include="..\include\WinStd\Shell.h" />
|
||||
<ClInclude Include="..\include\WinStd\Win.h" />
|
||||
<ClInclude Include="..\include\WinStd\WinSock2.h" />
|
||||
<ClInclude Include="..\include\WinStd\WinTrust.h" />
|
||||
<ClInclude Include="..\include\WinStd\WLAN.h" />
|
||||
<ClInclude Include="..\src\StdAfx.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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Ty, class _Ax, class _Tchr>
|
||||
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;
|
||||
|
||||
|
@ -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 T> 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<HRESULT>(num, msg.c_str())
|
||||
inline com_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error<HRESULT>(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 <class _T>
|
||||
void operator()(_T *_Ptr) const
|
||||
{
|
||||
CoTaskMemFree(_Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
/// COM object wrapper template
|
||||
///
|
||||
template <class T>
|
||||
class com_obj : public dplhandle<T*>
|
||||
class com_obj : public dplhandle<T*, NULL>
|
||||
{
|
||||
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<BSTR>
|
||||
class WINSTD_API bstr : public dplhandle<BSTR, NULL>
|
||||
{
|
||||
DPLHANDLE_IMPL(bstr)
|
||||
DPLHANDLE_IMPL(bstr, NULL)
|
||||
|
||||
public:
|
||||
///
|
||||
|
@ -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 <stdarg.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@ -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<handle_type>( h ) { } \
|
||||
inline C (_Inout_ C &&h) noexcept : handle<handle_type>(std::move(h)) { } \
|
||||
inline C& operator=(_In_ handle_type h) { handle<handle_type>::operator=( h ); return *this; } \
|
||||
inline C& operator=(_Inout_ C &&h) noexcept { handle<handle_type>::operator=(std::move(h)); return *this; } \
|
||||
inline C (_In_ handle_type h) : handle<handle_type, INVAL>( h ) { } \
|
||||
inline C (_Inout_ C &&h) noexcept : handle<handle_type, INVAL>(std::move(h)) { } \
|
||||
inline C& operator=(_In_ handle_type h) { handle<handle_type, INVAL>::operator=( h ); return *this; } \
|
||||
inline C& operator=(_Inout_ C &&h) noexcept { handle<handle_type, INVAL>::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<handle_type>( h ) { } \
|
||||
inline C (_In_ const C &h) : dplhandle<handle_type>(duplicate_internal(h.m_h)) { } \
|
||||
inline C (_Inout_ C &&h) noexcept : dplhandle<handle_type>(std::move (h )) { } \
|
||||
inline C& operator=(_In_ handle_type h) { dplhandle<handle_type>::operator=( h ); return *this; } \
|
||||
inline C& operator=(_In_ const C &h) { dplhandle<handle_type>::operator=( h ); return *this; } \
|
||||
inline C& operator=(_Inout_ C &&h) noexcept { dplhandle<handle_type>::operator=(std::move(h)); return *this; } \
|
||||
inline C (_In_ handle_type h) : dplhandle<handle_type, INVAL>( h ) { } \
|
||||
inline C (_In_ const C &h) : dplhandle<handle_type, INVAL>(duplicate_internal(h.m_h)) { } \
|
||||
inline C (_Inout_ C &&h) noexcept : dplhandle<handle_type, INVAL>(std::move (h )) { } \
|
||||
inline C& operator=(_In_ handle_type h) { dplhandle<handle_type, INVAL>::operator=( h ); return *this; } \
|
||||
inline C& operator=(_In_ const C &h) { dplhandle<handle_type, INVAL>::operator=( h ); return *this; } \
|
||||
inline C& operator=(_Inout_ C &&h) noexcept { dplhandle<handle_type, INVAL>::operator=(std::move(h)); return *this; } \
|
||||
private:
|
||||
|
||||
/// @}
|
||||
@ -166,8 +212,8 @@ namespace winstd
|
||||
template <class _Ty> struct LocalFree_delete<_Ty[]>;
|
||||
template<class _Ty, class _Dx = std::default_delete<_Ty>> class ref_unique_ptr;
|
||||
template<class _Ty, class _Dx> class ref_unique_ptr<_Ty[], _Dx>;
|
||||
template <class T> class handle;
|
||||
template <class T> class dplhandle;
|
||||
template <class T, T INVAL> class handle;
|
||||
template <class T, T INVAL> class dplhandle;
|
||||
template <class T> class vector_queue;
|
||||
template <typename _Tn> class num_runtime_error;
|
||||
class WINSTD_API win_runtime_error;
|
||||
@ -262,6 +308,8 @@ namespace winstd
|
||||
/// @{
|
||||
|
||||
template<class _Ty> class sanitizing_allocator;
|
||||
template<size_t N> 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<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 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<class _Elem, class _Traits, class _Ax> inline int vsprintf(_Out_ std::b
|
||||
///
|
||||
/// \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, ...);
|
||||
template<class _Elem, class _Traits, class _Ax> 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<class _Traits, class _Ax> inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string<char, _Traits, _Ax> &str, _In_opt_ va_list *Arguments);
|
||||
template<class _Traits, class _Ax> inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string<char, _Traits, _Ax> &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<class _Traits, class _Ax> inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &str, _In_opt_ va_list *Arguments);
|
||||
template<class _Traits, class _Ax> inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &str, _In_opt_ va_list *Arguments);
|
||||
|
||||
/// @}
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@ -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 <class T>
|
||||
template <class T, const T INVAL>
|
||||
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<handle_type> &&h) noexcept
|
||||
inline handle(_Inout_ handle<handle_type, INVAL> &&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<handle_type> &h);
|
||||
handle<handle_type>& operator=(_In_ const handle<handle_type> &h);
|
||||
handle(_In_ const handle<handle_type, INVAL> &h);
|
||||
handle<handle_type, INVAL>& operator=(_In_ const handle<handle_type, INVAL> &h);
|
||||
|
||||
public:
|
||||
///
|
||||
@ -658,7 +712,7 @@ namespace winstd
|
||||
///
|
||||
/// \param[in] h Object handle value
|
||||
///
|
||||
inline handle<handle_type>& operator=(_In_ handle_type h)
|
||||
inline handle<handle_type, INVAL>& 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<handle_type>& operator=(_Inout_ handle<handle_type> &&h) noexcept
|
||||
inline handle<handle_type, INVAL>& operator=(_Inout_ handle<handle_type, INVAL> &&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 <class T, const T INVAL>
|
||||
const T handle<T, INVAL>::invalid = INVAL;
|
||||
|
||||
|
||||
///
|
||||
/// Base abstract template class to support object handle keeping for objects that support handle duplication
|
||||
///
|
||||
template <class T>
|
||||
class dplhandle : public handle<T>
|
||||
template <class T, T INVAL>
|
||||
class dplhandle : public handle<T, INVAL>
|
||||
{
|
||||
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<handle_type>(h)
|
||||
inline dplhandle(_In_ handle_type h) : handle<handle_type, INVAL>(h)
|
||||
{
|
||||
}
|
||||
|
||||
@ -891,7 +949,7 @@ namespace winstd
|
||||
///
|
||||
/// \param[inout] h A reference of another object
|
||||
///
|
||||
inline dplhandle<handle_type>(_In_ const dplhandle<handle_type> &h) : handle<handle_type>(internal_duplicate(h.m_h))
|
||||
inline dplhandle<handle_type, INVAL>(_In_ const dplhandle<handle_type, INVAL> &h) : handle<handle_type, INVAL>(internal_duplicate(h.m_h))
|
||||
{
|
||||
}
|
||||
|
||||
@ -900,7 +958,7 @@ namespace winstd
|
||||
///
|
||||
/// \param[inout] h A rvalue reference of another object
|
||||
///
|
||||
inline dplhandle<handle_type>(_Inout_ dplhandle<handle_type> &&h) noexcept : handle<handle_type>(std::move(h))
|
||||
inline dplhandle<handle_type, INVAL>(_Inout_ dplhandle<handle_type, INVAL> &&h) noexcept : handle<handle_type, INVAL>(std::move(h))
|
||||
{
|
||||
}
|
||||
|
||||
@ -909,9 +967,9 @@ namespace winstd
|
||||
///
|
||||
/// \param[in] h Object handle value
|
||||
///
|
||||
inline dplhandle<handle_type>& operator=(_In_ handle_type h)
|
||||
inline dplhandle<handle_type, INVAL>& operator=(_In_ handle_type h)
|
||||
{
|
||||
handle<handle_type>::operator=(h);
|
||||
handle<handle_type, INVAL>::operator=(h);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -920,23 +978,23 @@ namespace winstd
|
||||
///
|
||||
/// \param[in] h Object
|
||||
///
|
||||
inline dplhandle<handle_type>& operator=(_In_ const dplhandle<handle_type> &h)
|
||||
inline dplhandle<handle_type, INVAL>& operator=(_In_ const dplhandle<handle_type, INVAL> &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<handle_type>& operator=(_Inout_ dplhandle<handle_type> &&h) noexcept
|
||||
inline dplhandle<handle_type, INVAL>& operator=(_Inout_ dplhandle<handle_type, INVAL> &&h) noexcept
|
||||
{
|
||||
handle<handle_type>::operator=(std::move(h));
|
||||
handle<handle_type, INVAL>::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<DWORD>(num, msg.c_str())
|
||||
inline win_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error<DWORD>(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<DWORD>(GetLastError(), msg.c_str())
|
||||
inline win_runtime_error(_In_ const std::string& msg) : num_runtime_error<DWORD>(GetLastError(), msg)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1538,6 +1596,23 @@ namespace winstd
|
||||
inline win_runtime_error(const win_runtime_error &other) : num_runtime_error<DWORD>(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<size_t N>
|
||||
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<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)
|
||||
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<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 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<class _Traits, class _Ax>
|
||||
inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string<char, _Traits, _Ax> &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<char, _Traits, _Ax> &str, _In_opt_ va_list *Arguments)
|
||||
{
|
||||
std::unique_ptr<CHAR[], winstd::LocalFree_delete<CHAR[]> > lpBuffer;
|
||||
DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast<LPSTR>((LPSTR*)get_ptr(lpBuffer)), 0, Arguments);
|
||||
@ -1945,7 +2047,7 @@ inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ D
|
||||
|
||||
|
||||
template<class _Traits, class _Ax>
|
||||
inline DWORD FormatMessage(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &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<wchar_t, _Traits, _Ax> &str, _In_opt_ va_list *Arguments)
|
||||
{
|
||||
std::unique_ptr<WCHAR[], winstd::LocalFree_delete<WCHAR[]> > lpBuffer;
|
||||
DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast<LPWSTR>((LPWSTR*)get_ptr(lpBuffer)), 0, Arguments);
|
||||
|
@ -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<PCREDENTIAL[], winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials);
|
||||
inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr<PCREDENTIAL[], winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials);
|
||||
|
||||
/// @copydoc CredProtectW()
|
||||
template<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials);
|
||||
template<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> inline BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sCredentials);
|
||||
template<class _Elem, class _Traits, class _Ax> 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<PCREDENTIAL[], winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials)
|
||||
inline BOOL CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr<PCREDENTIAL[], winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials)
|
||||
{
|
||||
PCREDENTIAL *pCredentials = NULL;
|
||||
BOOL bResult = CredEnumerate(Filter, Flags, Count, &pCredentials);
|
||||
PCREDENTIAL *pCredentials;
|
||||
if (CredEnumerate(Filter, Flags, Count, &pCredentials)) {
|
||||
cCredentials.reset(pCredentials);
|
||||
return bResult;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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);
|
||||
|
@ -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<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 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<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 _Elem, class _Traits, class _Ax> 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<class _Ty, class _Ax> inline BOOL WINAPI CertGetCertificateContextProperty(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwPropId, _Out_ std::vector<_Ty, _Ax> &aData);
|
||||
template<class _Ty, class _Ax> 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<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 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<class _Ty, class _Ax> inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD dwParam, _Out_ std::vector<_Ty, _Ax> &aData, _In_ DWORD dwFlags);
|
||||
template<class _Ty, class _Ax> 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<class T> inline BOOL CryptGetKeyParam(_In_ HCRYPTKEY hKey, _In_ DWORD d
|
||||
///
|
||||
/// \sa [CryptExportKey function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379931.aspx)
|
||||
///
|
||||
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);
|
||||
template<class _Ty, class _Ax> 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<PCCERT_CONTEXT>
|
||||
class WINSTD_API cert_context : public dplhandle<PCCERT_CONTEXT, NULL>
|
||||
{
|
||||
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<DWORD>(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<DWORD>(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<PCCERT_CHAIN_CONTEXT>
|
||||
class WINSTD_API cert_chain_context : public dplhandle<PCCERT_CHAIN_CONTEXT, NULL>
|
||||
{
|
||||
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<HCERTSTORE>
|
||||
class WINSTD_API cert_store : public handle<HCERTSTORE, NULL>
|
||||
{
|
||||
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<HCRYPTPROV>
|
||||
class WINSTD_API crypt_prov : public handle<HCRYPTPROV, NULL>
|
||||
{
|
||||
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<HCRYPTHASH>
|
||||
class WINSTD_API crypt_hash : public dplhandle<HCRYPTHASH, NULL>
|
||||
{
|
||||
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<HCRYPTKEY>
|
||||
class WINSTD_API crypt_key : public dplhandle<HCRYPTKEY, NULL>
|
||||
{
|
||||
DPLHANDLE_IMPL(crypt_key)
|
||||
DPLHANDLE_IMPL(crypt_key, NULL)
|
||||
|
||||
public:
|
||||
///
|
||||
@ -698,7 +701,7 @@ namespace winstd
|
||||
|
||||
|
||||
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)
|
||||
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<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)
|
||||
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<class _Ty, class _Ax>
|
||||
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<class _Ty, class _Ax>
|
||||
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<class _Ty, class _Ax>
|
||||
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<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)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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 <EapHostPeerTypes.h>
|
||||
#include <eapmethodtypes.h>
|
||||
#include <eappapis.h>
|
||||
#include <WinSock2.h>
|
||||
|
||||
|
||||
namespace winstd
|
||||
@ -394,9 +395,9 @@ namespace winstd
|
||||
///
|
||||
/// EapPacket wrapper class
|
||||
///
|
||||
class WINSTD_API eap_packet : public dplhandle<EapPacket*>
|
||||
class WINSTD_API eap_packet : public dplhandle<EapPacket*, NULL>
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<TRACE_EVENT_INFO> &info);
|
||||
inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _Inout_ std::unique_ptr<TRACE_EVENT_INFO> &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<EVENT_MAP_INFO> &info);
|
||||
inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Inout_ std::unique_ptr<EVENT_MAP_INFO> &info);
|
||||
|
||||
///
|
||||
/// Retrieves a property value from the event data.
|
||||
///
|
||||
/// \sa [TdhGetProperty function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa964843.aspx)
|
||||
///
|
||||
template<class _Ty, class _Ax> 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<class _Ty, class _Ax> 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<REGHANDLE>
|
||||
class WINSTD_API event_provider : public handle<REGHANDLE, NULL>
|
||||
{
|
||||
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<EVENT_DATA_DESCRIPTOR> 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<TRACEHANDLE>
|
||||
class WINSTD_API event_session : public handle<TRACEHANDLE, 0>
|
||||
{
|
||||
WINSTD_NONCOPYABLE(event_session)
|
||||
|
||||
@ -654,7 +654,7 @@ namespace winstd
|
||||
inline event_session& operator=(_Inout_ event_session &&other) noexcept
|
||||
{
|
||||
if (this != std::addressof(other)) {
|
||||
(handle<handle_type>&&)*this = std::move(other);
|
||||
(handle<handle_type, 0>&&)*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<handle_type>::attach(h);
|
||||
handle<handle_type, 0>::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<EVENT_TRACE_PROPERTIES> prop(reinterpret_cast<EVENT_TRACE_PROPERTIES*>(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<TRACEHANDLE>
|
||||
class WINSTD_API event_trace : public handle<TRACEHANDLE, INVALID_PROCESSTRACE_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<TRACE_EVENT_INFO> &info)
|
||||
inline ULONG TdhGetEventInformation(_In_ PEVENT_RECORD pEvent, _In_ ULONG TdhContextCount, _In_ PTDH_CONTEXT pTdhContext, _Inout_ std::unique_ptr<TRACE_EVENT_INFO> &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<EVENT_MAP_INFO> &info)
|
||||
inline ULONG TdhGetEventMapInformation(_In_ PEVENT_RECORD pEvent, _In_ LPWSTR pMapName, _Inout_ std::unique_ptr<EVENT_MAP_INFO> &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<class _Ty, class _Ax>
|
||||
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;
|
||||
|
||||
|
@ -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<class _Elem, class _Traits, class _Ax>
|
||||
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);
|
||||
|
||||
|
@ -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<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 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<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 MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
|
||||
/// @copydoc MsiRecordGetStringW()
|
||||
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 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<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 MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
|
||||
/// @copydoc MsiFormatRecordW()
|
||||
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 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<class _Elem, class _Traits, class _Ax> inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
template<class _Elem, class _Traits, class _Ax> 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<class _Ty, class _Ax> inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ std::vector<_Ty, _Ax> &binData);
|
||||
template<class _Ty, class _Ax> inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Inout_ std::vector<_Ty, _Ax> &binData);
|
||||
|
||||
/// @copydoc MsiGetTargetPathW()
|
||||
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 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<class _Elem, class _Traits, class _Ax> inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
template<class _Elem, class _Traits, class _Ax> inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
|
||||
/// @copydoc MsiGetComponentPathW()
|
||||
template<class _Elem, class _Traits, class _Ax> inline INSTALLSTATE MsiGetComponentPathA(_In_ LPCSTR szProduct, _In_ LPCSTR szComponent, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
template<class _Elem, class _Traits, class _Ax> 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<class _Elem, class _Traits, class _Ax> inline INSTALLSTATE MsiGetComponentPathW(_In_ LPCWSTR szProduct, _In_ LPCWSTR szComponent, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
template<class _Elem, class _Traits, class _Ax> inline INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue);
|
||||
|
||||
/// @}
|
||||
|
||||
@ -96,7 +96,7 @@ template<class _Elem, class _Traits, class _Ax> inline INSTALLSTATE MsiGetCompon
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Ty, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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);
|
||||
|
@ -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<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 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<class _Elem, class _Traits, class _Ax> BOOLEAN GetUserNameExW(_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, _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<SECURITY_STATUS>(num, msg.c_str())
|
||||
inline sec_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error<SECURITY_STATUS>(num, msg)
|
||||
{
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ namespace winstd
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
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<class _Elem, class _Traits, class _Ax>
|
||||
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;
|
||||
}
|
||||
|
167
include/WinStd/SetupAPI.h
Normal file
167
include/WinStd/SetupAPI.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
///
|
||||
/// \defgroup SetupAPI Setup API
|
||||
/// Integrates WinStd classes with Microsoft Setup API
|
||||
///
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
class WINSTD_API setup_device_info_list;
|
||||
class WINSTD_API setup_driver_info_list_builder;
|
||||
}
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SetupAPI.h>
|
||||
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
/// \addtogroup SetupAPI
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// HDEVINFO wrapper class
|
||||
///
|
||||
class WINSTD_API setup_device_info_list : public handle<HDEVINFO, INVALID_HANDLE_VALUE>
|
||||
{
|
||||
HANDLE_IMPL(setup_device_info_list, INVALID_HANDLE_VALUE)
|
||||
|
||||
public:
|
||||
///
|
||||
/// Frees the device information set.
|
||||
///
|
||||
/// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist)
|
||||
///
|
||||
virtual ~setup_device_info_list();
|
||||
|
||||
///
|
||||
/// Creates an empty device information set and optionally associates the set with a device setup class and a top-level window.
|
||||
///
|
||||
/// \return
|
||||
/// - true when creation succeeds;
|
||||
/// - false when creation fails. For extended error information, call `GetLastError()`.
|
||||
///
|
||||
/// \sa [SetupDiCreateDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdicreatedeviceinfolist)
|
||||
///
|
||||
inline bool create(
|
||||
_In_opt_ const GUID * ClassGuid,
|
||||
_In_opt_ HWND hwndParent)
|
||||
{
|
||||
handle_type h = SetupDiCreateDeviceInfoList(ClassGuid, hwndParent);
|
||||
if (h != invalid) {
|
||||
attach(h);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
/// Creates a device information set that contains requested device information elements for a local or a remote computer.
|
||||
///
|
||||
/// \return
|
||||
/// - true when creation succeeds;
|
||||
/// - false when creation fails. For extended error information, call `GetLastError()`.
|
||||
///
|
||||
/// \sa [SetupDiGetClassDevsExW function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdigetclassdevsexw)
|
||||
///
|
||||
inline bool create(
|
||||
_In_opt_ const GUID * ClassGuid,
|
||||
_In_opt_ PCTSTR Enumerator,
|
||||
_In_opt_ HWND hwndParent,
|
||||
_In_ DWORD Flags,
|
||||
_In_opt_ HDEVINFO DeviceInfoSet,
|
||||
_In_opt_ PCTSTR MachineName,
|
||||
_Reserved_ PVOID Reserved)
|
||||
{
|
||||
handle_type h = SetupDiGetClassDevsEx(ClassGuid, Enumerator, hwndParent, Flags, DeviceInfoSet, MachineName, Reserved);
|
||||
if (h != invalid) {
|
||||
attach(h);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Frees the device information set.
|
||||
///
|
||||
/// \sa [SetupDiDestroyDeviceInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydeviceinfolist)
|
||||
///
|
||||
virtual void free_internal();
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// Builds a list of drivers in constructor and deletes it in destructor
|
||||
///
|
||||
class WINSTD_API setup_driver_info_list_builder
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Construct the builder and builds a list of drivers that is associated with a specific device or with the global class driver list for a device information set.
|
||||
///
|
||||
/// \sa [SetupDiBuildDriverInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdibuilddriverinfolist)
|
||||
///
|
||||
inline setup_driver_info_list_builder(
|
||||
_In_ HDEVINFO DeviceInfoSet,
|
||||
_Inout_opt_ PSP_DEVINFO_DATA DeviceInfoData,
|
||||
_In_ DWORD DriverType) :
|
||||
m_DeviceInfoSet (DeviceInfoSet),
|
||||
m_DeviceInfoData(DeviceInfoData),
|
||||
m_DriverType (DriverType)
|
||||
{
|
||||
m_result = SetupDiBuildDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
|
||||
}
|
||||
|
||||
///
|
||||
/// Deletes a driver list and destructs the builder.
|
||||
///
|
||||
/// \sa [SetupDiDestroyDriverInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdidestroydriverinfolist)
|
||||
///
|
||||
virtual ~setup_driver_info_list_builder();
|
||||
|
||||
|
||||
///
|
||||
/// Return result of `SetupDiBuildDriverInfoList()` call.
|
||||
///
|
||||
/// \sa [SetupDiBuildDriverInfoList function](https://docs.microsoft.com/en-us/windows/desktop/api/setupapi/nf-setupapi-setupdibuilddriverinfolist)
|
||||
///
|
||||
inline BOOL status() const
|
||||
{
|
||||
return m_result;
|
||||
}
|
||||
|
||||
protected:
|
||||
HDEVINFO m_DeviceInfoSet;
|
||||
PSP_DEVINFO_DATA m_DeviceInfoData;
|
||||
DWORD m_DriverType;
|
||||
BOOL m_result; ///< Did building succeed?
|
||||
};
|
||||
|
||||
/// @}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -32,14 +32,14 @@
|
||||
/// @{
|
||||
|
||||
/// @copydoc PathCanonicalizeW()
|
||||
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 PathCanonicalizeA(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath);
|
||||
|
||||
///
|
||||
/// Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path, and stores it in a std::wstring string.
|
||||
///
|
||||
/// \sa [PathCanonicalize function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569.aspx)
|
||||
///
|
||||
template<class _Elem, class _Traits, class _Ax> inline BOOL PathCanonicalizeW(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCWSTR pszPath);
|
||||
template<class _Elem, class _Traits, class _Ax> inline BOOL PathCanonicalizeW(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath);
|
||||
|
||||
/// @}
|
||||
|
||||
@ -47,7 +47,7 @@ template<class _Elem, class _Traits, class _Ax> inline BOOL PathCanonicalizeW(__
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
inline BOOL PathCanonicalizeA(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCSTR pszPath)
|
||||
inline BOOL PathCanonicalizeA(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath)
|
||||
{
|
||||
assert(0); // TODO: Test this code.
|
||||
|
||||
@ -60,7 +60,7 @@ inline BOOL PathCanonicalizeA(__out std::basic_string<_Elem, _Traits, _Ax> &sVal
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
inline BOOL PathCanonicalizeW(__out std::basic_string<_Elem, _Traits, _Ax> &sValue, __in LPCWSTR pszPath)
|
||||
inline BOOL PathCanonicalizeW(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath)
|
||||
{
|
||||
assert(0); // TODO: Test this code.
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -51,7 +51,7 @@ namespace winstd {
|
||||
/// Since Wlanapi.dll is not always present, the `pfnWlanReasonCodeToString` pointer to `WlanReasonCodeToString()`
|
||||
/// function must be loaded dynamically.
|
||||
///
|
||||
template<class _Elem, class _Traits, class _Ax> inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved);
|
||||
template<class _Elem, class _Traits, class _Ax> inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved);
|
||||
|
||||
/// @}
|
||||
|
||||
@ -124,9 +124,9 @@ namespace winstd
|
||||
///
|
||||
/// WLAN handle wrapper
|
||||
///
|
||||
class WINSTD_API wlan_handle : public handle<HANDLE>
|
||||
class WINSTD_API wlan_handle : public handle<HANDLE, NULL>
|
||||
{
|
||||
HANDLE_IMPL(wlan_handle)
|
||||
HANDLE_IMPL(wlan_handle, NULL)
|
||||
|
||||
public:
|
||||
///
|
||||
@ -172,7 +172,7 @@ namespace winstd
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved)
|
||||
inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Inout_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved)
|
||||
{
|
||||
DWORD dwSize = 0;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
176
include/WinStd/WinSock2.h
Normal file
176
include/WinStd/WinSock2.h
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
///
|
||||
/// \defgroup WinSock2API WinSock2 API
|
||||
/// Integrates WinStd classes with Microsoft WinSock2 API
|
||||
///
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
class WINSTD_API ws2_runtime_error;
|
||||
#if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
|
||||
class WINSTD_API addrinfo;
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <ws2def.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
/// \addtogroup WinStdExceptions
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// WinSock2 runtime error
|
||||
///
|
||||
class WINSTD_API ws2_runtime_error : public num_runtime_error<int>
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \param[in] num WinSock2 error code
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
inline ws2_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error<int>(num, msg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \param[in] num WinSock2 error code
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
inline ws2_runtime_error(_In_ error_type num, _In_z_ const char *msg) : num_runtime_error<int>(num, msg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructs an exception using `WSAGetLastError()`
|
||||
///
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
inline ws2_runtime_error(_In_ const std::string& msg) : num_runtime_error<int>(WSAGetLastError(), msg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructs an exception using `WSAGetLastError()`
|
||||
///
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
inline ws2_runtime_error(_In_z_ const char *msg) : num_runtime_error<int>(WSAGetLastError(), msg)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Copies an exception
|
||||
///
|
||||
/// \param[in] other Exception to copy from
|
||||
///
|
||||
inline ws2_runtime_error(const ws2_runtime_error &other) : num_runtime_error<int>(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;
|
||||
}
|
||||
};
|
||||
|
||||
/// @}
|
||||
|
||||
|
||||
/// \addtogroup WinSock2API
|
||||
/// @{
|
||||
|
||||
#if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
|
||||
|
||||
///
|
||||
/// SID wrapper class
|
||||
///
|
||||
class WINSTD_API addrinfo : public handle<PADDRINFOT, NULL>
|
||||
{
|
||||
HANDLE_IMPL(addrinfo, NULL)
|
||||
|
||||
public:
|
||||
///
|
||||
/// Provides protocol-independent translation from a host name to an address.
|
||||
///
|
||||
/// \sa [GetAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfow)
|
||||
///
|
||||
inline bool get(
|
||||
_In_opt_ PCTSTR pNodeName,
|
||||
_In_opt_ PCTSTR pServiceName,
|
||||
_In_opt_ const ADDRINFOT *pHints)
|
||||
{
|
||||
handle_type h;
|
||||
if (GetAddrInfo(pNodeName, pServiceName, pHints, &h) == 0) {
|
||||
attach(h);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
/// Frees address information
|
||||
///
|
||||
/// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow)
|
||||
///
|
||||
virtual ~addrinfo();
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Frees address information
|
||||
///
|
||||
/// \sa [FreeAddrInfoW function](https://docs.microsoft.com/en-us/windows/desktop/api/ws2tcpip/nf-ws2tcpip-freeaddrinfow)
|
||||
///
|
||||
virtual void free_internal();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -27,6 +27,8 @@
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#include <WinTrust.h>
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
class WINSTD_API wintrust;
|
||||
@ -34,8 +36,6 @@ namespace winstd
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WinTrust.h>
|
||||
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
winstd::bstr::~bstr()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
SysFreeString(m_h);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
winstd::cert_context::~cert_context()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CertFreeCertificateContext(m_h);
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_
|
||||
|
||||
winstd::cert_chain_context::~cert_chain_context()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CertFreeCertificateChain(m_h);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_in
|
||||
|
||||
winstd::cert_store::~cert_store()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CertCloseStore(m_h, 0);
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ void winstd::cert_store::free_internal()
|
||||
|
||||
winstd::crypt_prov::~crypt_prov()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CryptReleaseContext(m_h, 0);
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ void winstd::crypt_prov::free_internal()
|
||||
|
||||
winstd::crypt_hash::~crypt_hash()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CryptDestroyHash(m_h);
|
||||
}
|
||||
|
||||
@ -122,8 +122,8 @@ void winstd::crypt_hash::free_internal()
|
||||
|
||||
winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const
|
||||
{
|
||||
handle_type hNew = NULL;
|
||||
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : NULL;
|
||||
handle_type hNew = invalid;
|
||||
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : invalid;
|
||||
}
|
||||
|
||||
|
||||
@ -133,7 +133,7 @@ winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ hand
|
||||
|
||||
winstd::crypt_key::~crypt_key()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CryptDestroyKey(m_h);
|
||||
}
|
||||
|
||||
@ -209,8 +209,8 @@ void winstd::crypt_key::free_internal()
|
||||
|
||||
winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const
|
||||
{
|
||||
handle_type hNew = NULL;
|
||||
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : NULL;
|
||||
handle_type hNew = invalid;
|
||||
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : invalid;
|
||||
}
|
||||
|
||||
|
||||
@ -220,6 +220,6 @@ winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle
|
||||
|
||||
winstd::data_blob::~data_blob()
|
||||
{
|
||||
if (pbData)
|
||||
if (pbData != NULL)
|
||||
LocalFree(pbData);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -80,7 +80,7 @@ const EAP_ATTRIBUTE winstd::eap_attr::blank = {};
|
||||
|
||||
winstd::eap_packet::~eap_packet()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
HeapFree(GetProcessHeap(), 0, m_h);
|
||||
}
|
||||
|
||||
@ -95,9 +95,9 @@ winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ hand
|
||||
{
|
||||
WORD n = ntohs(*(WORD*)h->Length);
|
||||
handle_type h2 = (handle_type)HeapAlloc(GetProcessHeap(), 0, n);
|
||||
if (!h2) {
|
||||
if (h2 == invalid) {
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return NULL;
|
||||
return invalid;
|
||||
}
|
||||
|
||||
memcpy(h2, h, n);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -118,7 +118,7 @@ void winstd::event_rec::set_user_data_internal(_In_ USHORT size, _In_bytecount_(
|
||||
|
||||
winstd::event_provider::~event_provider()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
EventUnregister(m_h);
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ VOID NTAPI winstd::event_provider::enable_callback(_In_ LPCGUID SourceId, _In_ U
|
||||
|
||||
winstd::event_session::~event_session()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ winstd::event_trace_enabler::~event_trace_enabler()
|
||||
|
||||
winstd::event_trace::~event_trace()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
CloseTrace(m_h);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
51
src/SetupAPI.cpp
Normal file
51
src/SetupAPI.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#pragma comment(lib, "Setupapi.lib")
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::setup_device_info_list
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::setup_device_info_list::~setup_device_info_list()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
SetupDiDestroyDeviceInfoList(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::setup_device_info_list::free_internal()
|
||||
{
|
||||
SetupDiDestroyDeviceInfoList(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::setup_device_info_list
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::setup_driver_info_list_builder::~setup_driver_info_list_builder()
|
||||
{
|
||||
if (m_result)
|
||||
SetupDiDestroyDriverInfoList(m_DeviceInfoSet, m_DeviceInfoData, m_DriverType);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -20,6 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define _WINSOCKAPI_ // Prevent inclusion of winsock.h in windows.h.
|
||||
|
||||
#include "../include/WinStd/Base64.h"
|
||||
#include "../include/WinStd/COM.h"
|
||||
#include "../include/WinStd/Cred.h"
|
||||
@ -33,8 +35,10 @@
|
||||
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
||||
#include "../include/WinStd/Sec.h"
|
||||
#endif
|
||||
#include "../include/WinStd/SetupAPI.h"
|
||||
#include "../include/WinStd/Shell.h"
|
||||
#include "../include/WinStd/Win.h"
|
||||
#include "../include/WinStd/WinSock2.h"
|
||||
#include "../include/WinStd/WinTrust.h"
|
||||
#include "../include/WinStd/WLAN.h"
|
||||
#include "../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.
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
winstd::wlan_handle::~wlan_handle()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
|
||||
@ -36,5 +36,3 @@ void winstd::wlan_handle::free_internal()
|
||||
{
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
83
src/Win.cpp
83
src/Win.cpp
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
@ -151,30 +151,13 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::win_handle
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::win_handle::~win_handle()
|
||||
{
|
||||
if (m_h)
|
||||
CloseHandle(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::win_handle::free_internal()
|
||||
{
|
||||
CloseHandle(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::library
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::library::~library()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
FreeLibrary(m_h);
|
||||
}
|
||||
|
||||
@ -185,13 +168,47 @@ void winstd::library::free_internal()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::critical_section
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::critical_section::critical_section()
|
||||
{
|
||||
InitializeCriticalSection(&m_data);
|
||||
}
|
||||
|
||||
|
||||
winstd::critical_section::~critical_section()
|
||||
{
|
||||
DeleteCriticalSection(&m_data);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::find_file
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::find_file::~find_file()
|
||||
{
|
||||
if (m_h != invalid) {
|
||||
FindClose(m_h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void winstd::find_file::free_internal()
|
||||
{
|
||||
FindClose(m_h);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::heap
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::heap::~heap()
|
||||
{
|
||||
if (m_h) {
|
||||
if (m_h != invalid) {
|
||||
enumerate();
|
||||
HeapDestroy(m_h);
|
||||
}
|
||||
@ -200,6 +217,8 @@ winstd::heap::~heap()
|
||||
|
||||
bool winstd::heap::enumerate()
|
||||
{
|
||||
assert(m_h != invalid);
|
||||
|
||||
bool found = false;
|
||||
|
||||
// Lock the heap for exclusive access.
|
||||
@ -277,13 +296,31 @@ winstd::user_impersonator::~user_impersonator()
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::console_ctrl_handler
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::console_ctrl_handler::console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) :
|
||||
m_handler(HandlerRoutine)
|
||||
{
|
||||
m_cookie = SetConsoleCtrlHandler(m_handler, TRUE);
|
||||
}
|
||||
|
||||
|
||||
winstd::console_ctrl_handler::~console_ctrl_handler()
|
||||
{
|
||||
if (m_cookie)
|
||||
SetConsoleCtrlHandler(m_handler, FALSE);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::vmemory
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::vmemory::~vmemory()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
@ -300,7 +337,7 @@ void winstd::vmemory::free_internal()
|
||||
|
||||
winstd::reg_key::~reg_key()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
RegCloseKey(m_h);
|
||||
}
|
||||
|
||||
@ -317,7 +354,7 @@ void winstd::reg_key::free_internal()
|
||||
|
||||
winstd::security_id::~security_id()
|
||||
{
|
||||
if (m_h)
|
||||
if (m_h != invalid)
|
||||
FreeSid(m_h);
|
||||
}
|
||||
|
||||
|
42
src/WinSock2.cpp
Normal file
42
src/WinSock2.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
#if (NTDDI_VERSION >= NTDDI_WINXPSP2) || (_WIN32_WINNT >= 0x0502)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::addrinfo
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::addrinfo::~addrinfo()
|
||||
{
|
||||
if (m_h != invalid)
|
||||
FreeAddrInfo(m_h);
|
||||
}
|
||||
|
||||
|
||||
void winstd::addrinfo::free_internal()
|
||||
{
|
||||
FreeAddrInfo(m_h);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 1991-2018 Amebis
|
||||
Copyright 1991-2019 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
Loading…
x
Reference in New Issue
Block a user