57#define WINSTD_STRING_IMPL(x) #x
62#define WINSTD_STRING(x) WINSTD_STRING_IMPL(x)
67#define WINSTD_NONCOPYABLE(C) \
69 C (_In_ const C &h) noexcept; \
70 C& operator=(_In_ const C &h) noexcept;
75#define WINSTD_NONMOVABLE(C) \
77 C (_Inout_ C &&h) noexcept; \
78 C& operator=(_Inout_ C &&h) noexcept;
80#ifndef WINSTD_STACK_BUFFER_BYTES
94#define WINSTD_STACK_BUFFER_BYTES 1024
106#define PRINTF_LPTSTR "ls"
108#define PRINTF_LPTSTR "s"
115#define PRINTF_LPOLESTR "hs"
117#define PRINTF_LPOLESTR "ls"
124#define _tcin (std::wcin )
126#define _tcin (std::cin )
133#define _tcout (std::wcout)
135#define _tcout (std::cout)
142#define _tcerr (std::wcerr)
144#define _tcerr (std::cerr)
151#define _tclog (std::wclog)
153#define _tclog (std::clog)
164#define WINSTD_HANDLE_IMPL(C, T, INVAL) \
167 C (_In_opt_ T h) noexcept : handle<T, INVAL>( h ) {} \
168 C (_Inout_ C &&h) noexcept : handle<T, INVAL>(std::move(h)) {} \
169 C& operator=(_In_opt_ T h) noexcept { handle<T, INVAL>::operator=( h ); return *this; } \
170 C& operator=(_Inout_ C &&h) noexcept { handle<T, INVAL>::operator=(std::move(h)); return *this; } \
176#define WINSTD_DPLHANDLE_IMPL(C, T, INVAL) \
179 C (_In_opt_ T h) noexcept : dplhandle<T, INVAL>( h ) {} \
180 C (_In_ const C &h) noexcept : dplhandle<T, INVAL>(duplicate_internal(h.m_h)) {} \
181 C (_Inout_ C &&h) noexcept : dplhandle<T, INVAL>(std::move (h )) {} \
182 C& operator=(_In_opt_ T h) noexcept { dplhandle<T, INVAL>::operator=( h ); return *this; } \
183 C& operator=(_In_ const C &h) noexcept { dplhandle<T, INVAL>::operator=( h ); return *this; } \
184 C& operator=(_Inout_ C &&h) noexcept { dplhandle<T, INVAL>::operator=(std::move(h)); return *this; } \
189#ifndef _FormatMessage_format_string_
190#define _FormatMessage_format_string_ _In_z_
194#ifndef _LPCBYTE_DEFINED
195#define _LPCBYTE_DEFINED
196typedef const BYTE *LPCBYTE;
203#pragma warning(disable: 4995)
204#pragma warning(disable: 4996)
205#pragma warning(disable: 4505)
208inline ULONGLONG ULongLongMult(ULONGLONG a, ULONGLONG b)
211 if (SUCCEEDED(ULongLongMult(a, b, &result)))
213 throw std::invalid_argument(
"multiply overflow");
216inline SIZE_T SIZETMult(SIZE_T a, SIZE_T b)
219 if (SUCCEEDED(SIZETMult(a, b, &result)))
221 throw std::invalid_argument(
"multiply overflow");
226inline ULONGLONG ULongLongAdd(ULONGLONG a, ULONGLONG b)
229 if (SUCCEEDED(ULongLongAdd(a, b, &result)))
231 throw std::invalid_argument(
"add overflow");
234inline SIZE_T SIZETAdd(SIZE_T a, SIZE_T b)
237 if (SUCCEEDED(SIZETAdd(a, b, &result)))
239 throw std::invalid_argument(
"add overflow");
247static inline int __vsnprintf(_Out_z_cap_(capacity)
char* str, _In_
size_t capacity, _In_z_ _Printf_format_string_params_(2)
const char* format, _In_ va_list arg)
249#pragma warning(suppress: 4996)
250 return _vsnprintf(str, capacity, format, arg);
253static inline int __vsnprintf(_Out_z_cap_(capacity)
wchar_t* str, _In_
size_t capacity, _In_z_ _Printf_format_string_params_(2)
const wchar_t* format, _In_ va_list arg)
255#pragma warning(suppress: 4996)
256 return _vsnwprintf(str, capacity, format, arg);
269template<
class _Elem,
class _Traits,
class _Ax>
270static int vsprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_
const _Elem *format, _In_ va_list arg)
275 int count = __vsnprintf(buf, _countof(buf), format, arg);
276 if (0 <= count && count < _countof(buf)) {
278 str.append(buf, count);
284 count = __vsnprintf(NULL, 0, format, arg);
287 case EINVAL:
throw std::invalid_argument(
"invalid vsnprintf arguments");
288 case EILSEQ:
throw std::runtime_error(
"encoding error");
289 default:
throw std::runtime_error(
"failed to format string");
292 size_t offset = str.size();
293 str.resize(offset + count);
294 if (__vsnprintf(&str[offset], count + 1, format, arg) != count)
295 throw std::runtime_error(
"failed to format string");
307template<
class _Elem,
class _Traits,
class _Ax>
308static int sprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_
const _Elem *format, ...)
311 va_start(arg, format);
312 const int res =
vsprintf(str, format, arg);
322template<
class _Traits,
class _Ax>
323static _Success_(
return != 0) int
WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_
int cchWideChar, _Out_ std::basic_string<
char, _Traits, _Ax> &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept
328 int cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
331 sMultiByteStr.assign(szStackBuffer, cchWideChar != -1 ? strnlen(szStackBuffer, cch) : (size_t)cch - 1);
333 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
335 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
336 sMultiByteStr.resize(cch);
337 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
338 sMultiByteStr.resize(cchWideChar != -1 ? strnlen(&sMultiByteStr[0], cch) : (size_t)cch - 1);
350static _Success_(
return != 0) int
WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_
int cchWideChar, _Out_ std::vector<
char, _Ax> &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept
355 int cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
358 sMultiByteStr.assign(szStackBuffer, szStackBuffer + cch);
360 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
362 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
363 sMultiByteStr.resize(cch);
364 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, sMultiByteStr.data(), cch, lpDefaultChar, lpUsedDefaultChar);
375template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
376static _Success_(
return != 0) int
WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ std::basic_string<
wchar_t, _Traits1, _Ax1> sWideCharStr, _Out_ std::basic_string<
char, _Traits2, _Ax2> &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept
381 int cch =
::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (
int)sWideCharStr.length(), szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
384 sMultiByteStr.assign(szStackBuffer, cch);
386 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
388 cch =
::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (
int)sWideCharStr.length(), NULL, 0, lpDefaultChar, lpUsedDefaultChar);
389 sMultiByteStr.resize(cch);
390 cch =
::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (
int)sWideCharStr.length(), &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
403template<
class _Traits,
class _Ax>
404static _Success_(
return != 0) int
SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_
int cchWideChar, _Out_ std::basic_string<
char, _Traits, _Ax> &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept
409 int cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
412 sMultiByteStr.assign(szStackBuffer, cchWideChar != -1 ? strnlen(szStackBuffer, cch) : (size_t)cch - 1);
414 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
416 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
417 sMultiByteStr.resize(cch);
418 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
419 sMultiByteStr.resize(cchWideChar != -1 ? strnlen(&sMultiByteStr[0], cch) : (size_t)cch - 1);
422 SecureZeroMemory(szStackBuffer,
sizeof(szStackBuffer));
435static _Success_(
return != 0) int
SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cchWideChar) LPCWSTR lpWideCharStr, _In_
int cchWideChar, _Out_ std::vector<
char, _Ax> &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept
440 int cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
443 sMultiByteStr.assign(szStackBuffer, szStackBuffer + cch);
445 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
447 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
448 sMultiByteStr.resize(cch);
449 cch =
::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, sMultiByteStr.data(), cch, lpDefaultChar, lpUsedDefaultChar);
452 SecureZeroMemory(szStackBuffer,
sizeof(szStackBuffer));
464template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
465static _Success_(
return != 0) int
SecureWideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _Out_ std::basic_string<
wchar_t, _Traits1, _Ax1> sWideCharStr, _Out_ std::basic_string<
char, _Traits2, _Ax2> &sMultiByteStr, _In_opt_z_ LPCSTR lpDefaultChar, _Out_opt_ LPBOOL lpUsedDefaultChar) noexcept
470 int cch =
::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (
int)sWideCharStr.length(), szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
473 sMultiByteStr.assign(szStackBuffer, cch);
475 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
477 cch =
::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (
int)sWideCharStr.length(), NULL, 0, lpDefaultChar, lpUsedDefaultChar);
478 sMultiByteStr.resize(cch);
479 cch =
::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (
int)sWideCharStr.length(), &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
482 SecureZeroMemory(szStackBuffer,
sizeof(szStackBuffer));
492template<
class _Traits,
class _Ax>
493static _Success_(
return != 0) int
MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_
int cbMultiByte, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sWideCharStr) noexcept
498 int cch =
::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
501 sWideCharStr.assign(szStackBuffer, cbMultiByte != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
503 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
506 sWideCharStr.resize(cch);
508 sWideCharStr.resize(cbMultiByte != -1 ? wcsnlen(&sWideCharStr[0], cch) : (size_t)cch - 1);
520static _Success_(
return != 0) int
MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_
int cbMultiByte, _Out_ std::vector<
wchar_t, _Ax> &sWideCharStr) noexcept
525 int cch =
::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
528 sWideCharStr.assign(szStackBuffer, szStackBuffer + cch);
530 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
533 sWideCharStr.resize(cch);
534 cch =
::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, sWideCharStr.data(), cch);
545template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
546static _Success_(
return != 0) int
MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string<
char, _Traits1, _Ax1> &sMultiByteStr, _Out_ std::basic_string<
wchar_t, _Traits2, _Ax2> &sWideCharStr) noexcept
551 int cch =
::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (
int)sMultiByteStr.length(), szStackBuffer, _countof(szStackBuffer));
554 sWideCharStr.assign(szStackBuffer, cch);
556 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
558 cch =
::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (
int)sMultiByteStr.length(), NULL, 0);
559 sWideCharStr.resize(cch);
560 cch =
::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (
int)sMultiByteStr.length(), &sWideCharStr[0], cch);
573template<
class _Traits,
class _Ax>
574static _Success_(
return != 0) int
SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_
int cbMultiByte, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sWideCharStr) noexcept
579 int cch =
::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
582 sWideCharStr.assign(szStackBuffer, cbMultiByte != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
584 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
587 sWideCharStr.resize(cch);
589 sWideCharStr.resize(cbMultiByte != -1 ? wcsnlen(&sWideCharStr[0], cch) : (size_t)cch - 1);
592 SecureZeroMemory(szStackBuffer,
sizeof(szStackBuffer));
605static _Success_(
return != 0) int
SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_count_(cbMultiByte) LPCSTR lpMultiByteStr, _In_
int cbMultiByte, _Out_ std::vector<
wchar_t, _Ax> &sWideCharStr) noexcept
610 int cch =
::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
613 sWideCharStr.assign(szStackBuffer, szStackBuffer + cch);
615 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
618 sWideCharStr.resize(cch);
619 cch =
::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, sWideCharStr.data(), cch);
622 SecureZeroMemory(szStackBuffer,
sizeof(szStackBuffer));
634template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
635static _Success_(
return != 0) int
SecureMultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_ const std::basic_string<
char, _Traits1, _Ax1> &sMultiByteStr, _Out_ std::basic_string<
wchar_t, _Traits2, _Ax2> &sWideCharStr) noexcept
640 int cch =
::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (
int)sMultiByteStr.length(), szStackBuffer, _countof(szStackBuffer));
643 sWideCharStr.assign(szStackBuffer, cch);
645 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
647 cch =
::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (
int)sMultiByteStr.length(), NULL, 0);
648 sWideCharStr.resize(cch);
649 cch =
::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (
int)sMultiByteStr.length(), &sWideCharStr[0], cch);
652 SecureZeroMemory(szStackBuffer,
sizeof(szStackBuffer));
662template<
class _Traits,
class _Ax>
663static DWORD
FormatMessageA(_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)
665 std::unique_ptr<CHAR[], winstd::LocalFree_delete<CHAR[]> > lpBuffer;
666 DWORD dwResult =
FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId,
reinterpret_cast<LPSTR
>((LPSTR*)get_ptr(lpBuffer)), 0, Arguments);
668 str.assign(lpBuffer.get(), dwResult);
677template<
class _Traits,
class _Ax>
678static DWORD
FormatMessageW(_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)
680 std::unique_ptr<WCHAR[], winstd::LocalFree_delete<WCHAR[]> > lpBuffer;
681 DWORD dwResult =
FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId,
reinterpret_cast<LPWSTR
>((LPWSTR*)get_ptr(lpBuffer)), 0, Arguments);
683 str.assign(lpBuffer.get(), dwResult);
760 template<
class _Other>
805 m_data =
reinterpret_cast<T*
>(GlobalLock(hMem));
836 template<
class _Ty,
class _Dx>
847 m_ptr(owner.release())
859 other.m_ptr =
nullptr;
867 if (
m_ptr !=
nullptr)
876 operator typename _Ty**()
886 operator typename _Ty*&()
903 template<
class _Ty,
class _Dx>
913 template<
class _Ty,
class _Dx>
936 other.
m_ptr =
nullptr;
944 if (
m_ptr !=
nullptr)
953 operator typename _Ty**()
noexcept
981 template<
class _Ty,
class _Dx>
997 template <
class T, const T INVAL>
1040 handle<handle_type, INVAL>& operator=(_In_
const handle<handle_type, INVAL> &h)
noexcept {};
1059 #pragma warning(suppress: 26432)
1062 if (
this != std::addressof(
h)) {
1291 dplhandle<handle_type, INVAL>(_Inout_ dplhandle<handle_type, INVAL> &&h) noexcept : handle<handle_type, INVAL>(std::move(h))
1312 if (
this != std::addressof(
h)) {
1335 #pragma warning(disable: 26432)
1433 dwSize /=
sizeof(*szFormat);
1454 template <
typename _Tn>
1562 wstr.erase(
wstr.find_last_not_of(
L" \t\n\r\f\v") + 1);
1580 template<
class _Elem,
class _Traits,
class _Ax>
1665 template<
class _Elem,
class _Traits,
class _Ax>
1790 template<
class _Elem,
class _Traits,
class _Ax>
1873 #pragma warning(push)
1874 #pragma warning(disable: 4100)
1892 template<
class _Other>
1913 template<
class _Other>
1928 #pragma warning(pop)
1981 unsigned char m_data[
N];
Base template class to support converting GUID to string.
Definition Common.h:1792
basic_string_guid(const GUID &guid, const _Elem *format)
Initializes a new string and formats its contents to string representation of given GUID.
Definition Common.h:1803
Base template class to support string formatting using FormatMessage() style templates.
Definition Common.h:1667
basic_string_msg(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, DWORD_PTR *Arguments)
Initializes a new string and formats its contents using FormatMessage() style.
Definition Common.h:1742
basic_string_msg(DWORD dwFlags, LPCTSTR pszFormat, va_list *Arguments)
Initializes a new string and formats its contents using FormatMessage() style.
Definition Common.h:1752
basic_string_msg(HINSTANCE hInstance, WORD wLanguageID, UINT nFormatID,...)
Initializes a new string and formats its contents using FormatMessage() style template in resources.
Definition Common.h:1714
basic_string_msg(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, va_list *Arguments)
Initializes a new string and formats its contents using FormatMessage() style.
Definition Common.h:1732
basic_string_msg(const _Elem *format,...)
Initializes a new string and formats its contents using FormatMessage() style template.
Definition Common.h:1677
basic_string_msg(HINSTANCE hInstance, UINT nFormatID,...)
Initializes a new string and formats its contents using FormatMessage() style template in resources.
Definition Common.h:1696
basic_string_msg(DWORD dwFlags, LPCTSTR pszFormat, DWORD_PTR *Arguments)
Initializes a new string and formats its contents using FormatMessage() style.
Definition Common.h:1762
Base template class to support string formatting using printf() style templates.
Definition Common.h:1582
basic_string_printf(const _Elem *format,...)
Initializes a new string and formats its contents using printf() style template.
Definition Common.h:1592
basic_string_printf(HINSTANCE hInstance, WORD wLanguageID, UINT nFormatID,...)
Initializes a new string and formats its contents using printf() style template in resources.
Definition Common.h:1629
basic_string_printf(HINSTANCE hInstance, UINT nFormatID,...)
Initializes a new string and formats its contents using printf() style template in resources.
Definition Common.h:1611
Base abstract template class to support object handle keeping for objects that support trivial handle...
Definition Common.h:1262
virtual handle_type duplicate_internal(handle_type h) const =0
Abstract member function that must be implemented by child classes to do the actual object handle dup...
dplhandle< handle_type, INVAL > & operator=(handle_type h) noexcept
Attaches already available object handle.
Definition Common.h:1299
handle_type duplicate() const
Duplicates and returns a new object handle.
Definition Common.h:1347
dplhandle< handle_type, INVAL > & operator=(dplhandle< handle_type, INVAL > &&h) noexcept
Moves the object.
Definition Common.h:1336
void attach_duplicated(handle_type h)
Duplicates an object handle and sets a new object handle.
Definition Common.h:1357
dplhandle(handle_type h) noexcept
Initializes a new class instance with an already available object handle.
Definition Common.h:1275
dplhandle< handle_type, INVAL > & operator=(const dplhandle< handle_type, INVAL > &h) noexcept
Duplicates the object.
Definition Common.h:1310
dplhandle() noexcept
Initializes a new class instance with the object handle set to INVAL.
Definition Common.h:1267
Context scope automatic GlobalAlloc (un)access.
Definition Common.h:793
HGLOBAL m_h
memory handle
Definition Common.h:829
virtual ~globalmem_accessor()
Decrements the lock count associated with a memory object.
Definition Common.h:815
T * m_data
memory pointer
Definition Common.h:830
T * data() const noexcept
Return data pointer.
Definition Common.h:823
globalmem_accessor(HGLOBAL hMem)
Locks a global memory object and returns a pointer to the first byte of the object's memory block.
Definition Common.h:803
Base abstract template class to support generic object handle keeping.
Definition Common.h:999
handle_type *& operator*() const
Returns the object handle value when the object handle is a pointer to a value (class,...
Definition Common.h:1087
virtual void free_internal() noexcept=0
Abstract member function that must be implemented by child classes to do the actual object destructio...
handle() noexcept
Initializes a new class instance with the object handle set to INVAL.
Definition Common.h:1014
bool operator>=(handle_type h) const
Is handle greater than or equal to?
Definition Common.h:1163
handle_type operator->() const
Provides object handle member access when the object handle is a pointer to a class or struct.
Definition Common.h:1108
handle_type * operator&()
Returns the object handle reference.
Definition Common.h:1097
T handle_type
Datatype of the object handle this template class handles.
Definition Common.h:1004
handle(handle_type h) noexcept
Initializes a new class instance with an already available object handle.
Definition Common.h:1022
bool operator<(handle_type h) const
Is handle less than?
Definition Common.h:1137
handle< handle_type, INVAL > & operator=(handle_type h) noexcept
Attaches already available object handle.
Definition Common.h:1048
bool operator!() const
Tests if the object handle is invalid.
Definition Common.h:1124
handle< handle_type, INVAL > & operator=(handle< handle_type, INVAL > &&h) noexcept
Move assignment.
Definition Common.h:1060
bool operator!=(handle_type h) const
Is handle not equal to?
Definition Common.h:1189
void free()
Destroys the object.
Definition Common.h:1236
handle_type m_h
Object handle.
Definition Common.h:1251
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1214
bool operator==(handle_type h) const
Is handle equal to?
Definition Common.h:1202
handle(handle< handle_type, INVAL > &&h) noexcept
Move constructor.
Definition Common.h:1030
handle_type detach()
Dismisses the object handle from this class.
Definition Common.h:1226
bool operator>(handle_type h) const
Is handle greater than?
Definition Common.h:1176
bool operator<=(handle_type h) const
Is handle less than or equal to?
Definition Common.h:1150
Numerical runtime error.
Definition Common.h:1456
num_runtime_error(error_type num, const char *msg=nullptr)
Constructs an exception.
Definition Common.h:1478
num_runtime_error(error_type num, const std::string &msg)
Constructs an exception.
Definition Common.h:1467
error_type number() const
Returns the error number.
Definition Common.h:1486
_Tn error_type
Error number type.
Definition Common.h:1458
error_type m_num
Numeric error code.
Definition Common.h:1492
std::unique_ptr< _Ty[], _Dx > & m_own
Original owner of the pointer.
Definition Common.h:969
ref_unique_ptr(ref_unique_ptr< _Ty[], _Dx > &&other)
Moves object.
Definition Common.h:932
virtual ~ref_unique_ptr()
Returns ownership of the pointer.
Definition Common.h:942
ref_unique_ptr(std::unique_ptr< _Ty[], _Dx > &owner) noexcept
Takes ownership of the pointer.
Definition Common.h:922
_Ty * m_ptr
Pointer.
Definition Common.h:970
Helper class for returning pointers to std::unique_ptr.
Definition Common.h:838
std::unique_ptr< _Ty, _Dx > & m_own
Original owner of the pointer.
Definition Common.h:892
_Ty * m_ptr
Pointer.
Definition Common.h:893
ref_unique_ptr(ref_unique_ptr< _Ty, _Dx > &&other)
Moves object.
Definition Common.h:855
~ref_unique_ptr()
Returns ownership of the pointer.
Definition Common.h:865
ref_unique_ptr(std::unique_ptr< _Ty, _Dx > &owner)
Takes ownership of the pointer.
Definition Common.h:845
An allocator template that sanitizes each memory block before it is destroyed or reallocated.
Definition Common.h:1885
sanitizing_allocator(const sanitizing_allocator< _Ty > &_Othr)
Construct by copying.
Definition Common.h:1907
sanitizing_allocator(const sanitizing_allocator< _Other > &_Othr) noexcept
Construct from a related allocator.
Definition Common.h:1914
void deallocate(_Ty *const _Ptr, const std::size_t _Count)
Deallocate object at _Ptr sanitizing its content first.
Definition Common.h:1920
std::allocator< _Ty > _Mybase
Base type.
Definition Common.h:1887
sanitizing_allocator() noexcept
Construct default allocator.
Definition Common.h:1901
Sanitizing BLOB.
Definition Common.h:1962
sanitizing_blob()
Constructs uninitialized BLOB.
Definition Common.h:1967
~sanitizing_blob()
Sanitizes BLOB.
Definition Common.h:1975
Single-byte character implementation of a class to support converting GUID to string.
Definition Common.h:1820
string_guid(const GUID &guid)
Initializes a new string and formats its contents to string representation of given GUID.
Definition Common.h:1830
Windows runtime error.
Definition Common.h:1499
win_runtime_error(const char *msg)
Constructs an exception using GetLastError()
Definition Common.h:1546
win_runtime_error(error_type num, const char *msg)
Constructs an exception.
Definition Common.h:1524
win_runtime_error(error_type num)
Constructs an exception.
Definition Common.h:1506
win_runtime_error()
Constructs an exception using GetLastError()
Definition Common.h:1530
static std::string message(error_type num, DWORD dwLanguageId=0)
Returns a user-readable Windows error message. As std::exception messages may only be char*,...
Definition Common.h:1556
win_runtime_error(const std::string &msg)
Constructs an exception using GetLastError()
Definition Common.h:1538
win_runtime_error(error_type num, const std::string &msg)
Constructs an exception.
Definition Common.h:1515
Wide character implementation of a class to support converting GUID to string.
Definition Common.h:1841
wstring_guid(const GUID &guid)
Initializes a new string and formats its contents to string representation of given GUID.
Definition Common.h:1851
std::string load_msg_from_res(HMODULE hModule, UINT nId, WORD wLanguage)
Loads exception message string from resources and converts it to UTF-8.
Definition Common.h:1391
std::string fmt_msg_from_res(HMODULE hModule, UINT nId, WORD wLanguage,...)
Loads exception message sprintf template from resources, formats it and converts it to UTF-8.
Definition Common.h:1422
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition Common.h:94
std::string tstring
Multi-byte / Wide-character string (according to _UNICODE)
Definition Common.h:702
ref_unique_ptr< _Ty, _Dx > get_ptr(std::unique_ptr< _Ty, _Dx > &owner) noexcept
Helper function template for returning pointers to std::unique_ptr.
Definition Common.h:904
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition Common.h:75
std::basic_string< wchar_t, std::char_traits< wchar_t >, sanitizing_allocator< wchar_t > > sanitizing_wstring
A sanitizing variant of std::wstring.
Definition Common.h:1946
sanitizing_string sanitizing_tstring
Multi-byte / Wide-character sanitizing string (according to _UNICODE)
Definition Common.h:1954
std::basic_string< char, std::char_traits< char >, sanitizing_allocator< char > > sanitizing_string
A sanitizing variant of std::string.
Definition Common.h:1937
static const T invalid
Invalid handle value.
Definition Common.h:1009
Deleter for unique_ptr using GlobalFree.
Definition Common.h:771
GlobalFree_delete()
Default construct.
Definition Common.h:775
void operator()(HGLOBAL _Ptr) const
Delete a pointer.
Definition Common.h:782
LocalFree_delete() noexcept
Default construct.
Definition Common.h:745
LocalFree_delete< _Ty > _Myt
This type.
Definition Common.h:740
void operator()(_Other *) const
Delete a pointer of another type.
Definition Common.h:761
void operator()(_Ty *_Ptr) const noexcept
Delete a pointer.
Definition Common.h:750
Deleter for unique_ptr using LocalFree.
Definition Common.h:710
LocalFree_delete< _Ty > _Myt
This type.
Definition Common.h:711
LocalFree_delete(const LocalFree_delete< _Ty2 > &)
Construct from another LocalFree_delete.
Definition Common.h:721
void operator()(_Ty *_Ptr) const
Delete a pointer.
Definition Common.h:728
LocalFree_delete()
Default construct.
Definition Common.h:716
Convert this type to sanitizing_allocator<_Other>
Definition Common.h:1894
sanitizing_allocator< _Other > other
Other type.
Definition Common.h:1895