WinStd Windows Win32 API using Standard C++

Loading...
Searching...
No Matches
Common.h
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 1991-2024 Amebis
4 Copyright © 2016 GÉANT
5*/
6
7#pragma once
8
9#include <Windows.h>
10#include <assert.h>
11#include <intsafe.h>
12#include <stdarg.h>
13#include <tchar.h>
14#include <iostream>
15#include <memory>
16#include <stdexcept>
17#include <string>
18#include <vector>
19
36
39
43#ifndef __L
44#define __L(x) L ## x
45#endif
46
50#ifndef _L
51#define _L(x) __L(x)
52#endif
53
57#define WINSTD_STRING_IMPL(x) #x
58
62#define WINSTD_STRING(x) WINSTD_STRING_IMPL(x)
63
67#define WINSTD_NONCOPYABLE(C) \
68 private: \
69 C (_In_ const C &h) noexcept; \
70 C& operator=(_In_ const C &h) noexcept;
71
75#define WINSTD_NONMOVABLE(C) \
76 private: \
77 C (_Inout_ C &&h) noexcept; \
78 C& operator=(_Inout_ C &&h) noexcept;
79
80#ifndef WINSTD_STACK_BUFFER_BYTES
94#define WINSTD_STACK_BUFFER_BYTES 1024
95#endif
96
98
101
105#ifdef UNICODE
106#define PRINTF_LPTSTR "ls"
107#else
108#define PRINTF_LPTSTR "s"
109#endif
110
114#ifdef OLE2ANSI
115#define PRINTF_LPOLESTR "hs"
116#else
117#define PRINTF_LPOLESTR "ls"
118#endif
119
123#ifdef _UNICODE
124#define _tcin (std::wcin )
125#else
126#define _tcin (std::cin )
127#endif
128
132#ifdef _UNICODE
133#define _tcout (std::wcout)
134#else
135#define _tcout (std::cout)
136#endif
137
141#ifdef _UNICODE
142#define _tcerr (std::wcerr)
143#else
144#define _tcerr (std::cerr)
145#endif
146
150#ifdef _UNICODE
151#define _tclog (std::wclog)
152#else
153#define _tclog (std::clog)
154#endif
155
157
160
164#define WINSTD_HANDLE_IMPL(C, T, INVAL) \
165 public: \
166 C ( ) noexcept {} \
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; } \
171 WINSTD_NONCOPYABLE(C)
172
176#define WINSTD_DPLHANDLE_IMPL(C, T, INVAL) \
177 public: \
178 C ( ) noexcept {} \
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; } \
185 private:
186
188
189#ifndef _FormatMessage_format_string_
190#define _FormatMessage_format_string_ _In_z_
191#endif
192
194#ifndef _LPCBYTE_DEFINED
195#define _LPCBYTE_DEFINED
196 typedef const BYTE *LPCBYTE;
197#endif
199
200#pragma warning(push)
201// Do not use _vsnprintf_s/_vsnwprintf_s(), since it terminates string by force even when we explicitly want to write unterminated string.
202// Threfore turn off compiler warning instead. ;)
203#pragma warning(disable: 4995)
204#pragma warning(disable: 4996)
205#pragma warning(disable: 4505) // Don't warn on unused code
206
207#ifdef _WIN64
208 inline ULONGLONG ULongLongMult(ULONGLONG a, ULONGLONG b)
209{
210 ULONGLONG result;
211 if (SUCCEEDED(ULongLongMult(a, b, &result)))
212 return result;
213 throw std::invalid_argument("multiply overflow");
214}
215#else
216 inline SIZE_T SIZETMult(SIZE_T a, SIZE_T b)
217{
218 SIZE_T result;
219 if (SUCCEEDED(SIZETMult(a, b, &result)))
220 return result;
221 throw std::invalid_argument("multiply overflow");
222}
223#endif
224
225#ifdef _WIN64
226 inline ULONGLONG ULongLongAdd(ULONGLONG a, ULONGLONG b)
227{
228 ULONGLONG result;
229 if (SUCCEEDED(ULongLongAdd(a, b, &result)))
230 return result;
231 throw std::invalid_argument("add overflow");
232}
233#else
234 inline SIZE_T SIZETAdd(SIZE_T a, SIZE_T b)
235{
236 SIZE_T result;
237 if (SUCCEEDED(SIZETAdd(a, b, &result)))
238 return result;
239 throw std::invalid_argument("add overflow");
240}
241#endif
242
245
255 template<class _Traits, class _Ax>
256 static int vsprintf(_Inout_ std::basic_string<char, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const char *format, _In_ va_list arg)
257{
258 char buf[WINSTD_STACK_BUFFER_BYTES/sizeof(char)];
259
260 // Try with stack buffer first.
261 int count = _vsnprintf(buf, _countof(buf), format, arg);
262 if (0 <= count && count < _countof(buf)) {
263 // Copy from stack.
264 str.append(buf, count);
265 return count;
266 }
267 if (count < 0) {
268 switch (errno) {
269 case 0:
270 count = _vsnprintf(NULL, 0, format, arg);
271 assert(count >= 0);
272 break;
273 case EINVAL: throw std::invalid_argument("invalid vsnprintf arguments");
274 case EILSEQ: throw std::runtime_error("encoding error");
275 default: throw std::runtime_error("failed to format string");
276 }
277 }
278 size_t offset = str.size();
279 str.resize(offset + count);
280 if (_vsnprintf(&str[offset], count + 1, format, arg) != count)
281 throw std::runtime_error("failed to format string");
282 return count;
283}
284
294 template<class _Traits, class _Ax>
295 static int vsprintf(_Inout_ std::basic_string<wchar_t, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const wchar_t *format, _In_ va_list arg)
296{
297 wchar_t buf[WINSTD_STACK_BUFFER_BYTES/sizeof(wchar_t)];
298
299 // Try with stack buffer first.
300 int count = _vsnwprintf(buf, _countof(buf), format, arg);
301 if (0 <= count && count < _countof(buf)) {
302 // Copy from stack.
303 str.append(buf, count);
304 return count;
305 }
306 if (count < 0) {
307 switch (errno) {
308 case 0:
309 count = _vsnwprintf(NULL, 0, format, arg);
310 assert(count >= 0);
311 break;
312 case EINVAL: throw std::invalid_argument("invalid vsnprintf arguments");
313 case EILSEQ: throw std::runtime_error("encoding error");
314 default: throw std::runtime_error("failed to format string");
315 }
316 }
317 size_t offset = str.size();
318 str.resize(offset + count);
319 if (_vsnwprintf(&str[offset], count + 1, format, arg) != count)
320 throw std::runtime_error("failed to format string");
321 return count;
322}
323
332 template<class _Elem, class _Traits, class _Ax>
333 static int sprintf(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _Printf_format_string_ const _Elem *format, ...)
334{
335 va_list arg;
336 va_start(arg, format);
337 const int res = vsprintf(str, format, arg);
338 va_end(arg);
339 return res;
340}
341
347 template<class _Traits, class _Ax>
348 static _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
349{
350 CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(CHAR)];
351
352 // Try to convert to stack buffer first.
353 int cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
354 if (cch) {
355 // Copy from stack. Be careful not to include zero terminator.
356 sMultiByteStr.assign(szStackBuffer, cchWideChar != -1 ? strnlen(szStackBuffer, cch) : (size_t)cch - 1);
357 }
358 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
359 // Query the required output size. Allocate buffer. Then convert again.
360 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
361 sMultiByteStr.resize(cch);
362 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
363 sMultiByteStr.resize(cchWideChar != -1 ? strnlen(&sMultiByteStr[0], cch) : (size_t)cch - 1);
364 }
365
366 return cch;
367}
368
374 template<class _Ax>
375 static _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
376{
377 CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(CHAR)];
378
379 // Try to convert to stack buffer first.
380 int cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
381 if (cch) {
382 // Copy from stack.
383 sMultiByteStr.assign(szStackBuffer, szStackBuffer + cch);
384 }
385 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
386 // Query the required output size. Allocate buffer. Then convert again.
387 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
388 sMultiByteStr.resize(cch);
389 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, sMultiByteStr.data(), cch, lpDefaultChar, lpUsedDefaultChar);
390 }
391
392 return cch;
393}
394
400 template<class _Traits1, class _Ax1, class _Traits2, class _Ax2>
401 static _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
402{
403 CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(CHAR)];
404
405 // Try to convert to stack buffer first.
406 int cch = ::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (int)sWideCharStr.length(), szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
407 if (cch) {
408 // Copy from stack.
409 sMultiByteStr.assign(szStackBuffer, cch);
410 }
411 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
412 // Query the required output size. Allocate buffer. Then convert again.
413 cch = ::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (int)sWideCharStr.length(), NULL, 0, lpDefaultChar, lpUsedDefaultChar);
414 sMultiByteStr.resize(cch);
415 cch = ::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (int)sWideCharStr.length(), &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
416 }
417
418 return cch;
419}
420
428 template<class _Traits, class _Ax>
429 static _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
430{
431 CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(CHAR)];
432
433 // Try to convert to stack buffer first.
434 int cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
435 if (cch) {
436 // Copy from stack. Be careful not to include zero terminator.
437 sMultiByteStr.assign(szStackBuffer, cchWideChar != -1 ? strnlen(szStackBuffer, cch) : (size_t)cch - 1);
438 }
439 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
440 // Query the required output size. Allocate buffer. Then convert again.
441 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
442 sMultiByteStr.resize(cch);
443 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
444 sMultiByteStr.resize(cchWideChar != -1 ? strnlen(&sMultiByteStr[0], cch) : (size_t)cch - 1);
445 }
446
447 SecureZeroMemory(szStackBuffer, sizeof(szStackBuffer));
448
449 return cch;
450}
451
459 template<class _Ax>
460 static _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
461{
462 CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(CHAR)];
463
464 // Try to convert to stack buffer first.
465 int cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
466 if (cch) {
467 // Copy from stack.
468 sMultiByteStr.assign(szStackBuffer, szStackBuffer + cch);
469 }
470 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
471 // Query the required output size. Allocate buffer. Then convert again.
472 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
473 sMultiByteStr.resize(cch);
474 cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, sMultiByteStr.data(), cch, lpDefaultChar, lpUsedDefaultChar);
475 }
476
477 SecureZeroMemory(szStackBuffer, sizeof(szStackBuffer));
478
479 return cch;
480}
481
489 template<class _Traits1, class _Ax1, class _Traits2, class _Ax2>
490 static _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
491{
492 CHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(CHAR)];
493
494 // Try to convert to stack buffer first.
495 int cch = ::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (int)sWideCharStr.length(), szStackBuffer, _countof(szStackBuffer), lpDefaultChar, lpUsedDefaultChar);
496 if (cch) {
497 // Copy from stack.
498 sMultiByteStr.assign(szStackBuffer, cch);
499 }
500 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
501 // Query the required output size. Allocate buffer. Then convert again.
502 cch = ::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (int)sWideCharStr.length(), NULL, 0, lpDefaultChar, lpUsedDefaultChar);
503 sMultiByteStr.resize(cch);
504 cch = ::WideCharToMultiByte(CodePage, dwFlags, sWideCharStr.c_str(), (int)sWideCharStr.length(), &sMultiByteStr[0], cch, lpDefaultChar, lpUsedDefaultChar);
505 }
506
507 SecureZeroMemory(szStackBuffer, sizeof(szStackBuffer));
508
509 return cch;
510}
511
517 template<class _Traits, class _Ax>
518 static _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
519{
520 WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(WCHAR)];
521
522 // Try to convert to stack buffer first.
523 int cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
524 if (cch) {
525 // Copy from stack.
526 sWideCharStr.assign(szStackBuffer, cbMultiByte != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
527 }
528 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
529 // Query the required output size. Allocate buffer. Then convert again.
530 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0);
531 sWideCharStr.resize(cch);
532 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, &sWideCharStr[0], cch);
533 sWideCharStr.resize(cbMultiByte != -1 ? wcsnlen(&sWideCharStr[0], cch) : (size_t)cch - 1);
534 }
535
536 return cch;
537}
538
544 template<class _Ax>
545 static _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
546{
547 WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(WCHAR)];
548
549 // Try to convert to stack buffer first.
550 int cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
551 if (cch) {
552 // Copy from stack.
553 sWideCharStr.assign(szStackBuffer, szStackBuffer + cch);
554 }
555 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
556 // Query the required output size. Allocate buffer. Then convert again.
557 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0);
558 sWideCharStr.resize(cch);
559 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, sWideCharStr.data(), cch);
560 }
561
562 return cch;
563}
564
570 template<class _Traits1, class _Ax1, class _Traits2, class _Ax2>
571 static _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
572{
573 WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(WCHAR)];
574
575 // Try to convert to stack buffer first.
576 int cch = ::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (int)sMultiByteStr.length(), szStackBuffer, _countof(szStackBuffer));
577 if (cch) {
578 // Copy from stack.
579 sWideCharStr.assign(szStackBuffer, cch);
580 }
581 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
582 // Query the required output size. Allocate buffer. Then convert again.
583 cch = ::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (int)sMultiByteStr.length(), NULL, 0);
584 sWideCharStr.resize(cch);
585 cch = ::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (int)sMultiByteStr.length(), &sWideCharStr[0], cch);
586 }
587
588 return cch;
589}
590
598 template<class _Traits, class _Ax>
599 static _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
600{
601 WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(WCHAR)];
602
603 // Try to convert to stack buffer first.
604 int cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
605 if (cch) {
606 // Copy from stack.
607 sWideCharStr.assign(szStackBuffer, cbMultiByte != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
608 }
609 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
610 // Query the required output size. Allocate buffer. Then convert again.
611 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0);
612 sWideCharStr.resize(cch);
613 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, &sWideCharStr[0], cch);
614 sWideCharStr.resize(cbMultiByte != -1 ? wcsnlen(&sWideCharStr[0], cch) : (size_t)cch - 1);
615 }
616
617 SecureZeroMemory(szStackBuffer, sizeof(szStackBuffer));
618
619 return cch;
620}
621
629 template<class _Ax>
630 static _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
631{
632 WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(WCHAR)];
633
634 // Try to convert to stack buffer first.
635 int cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szStackBuffer, _countof(szStackBuffer));
636 if (cch) {
637 // Copy from stack.
638 sWideCharStr.assign(szStackBuffer, szStackBuffer + cch);
639 }
640 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
641 // Query the required output size. Allocate buffer. Then convert again.
642 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0);
643 sWideCharStr.resize(cch);
644 cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, sWideCharStr.data(), cch);
645 }
646
647 SecureZeroMemory(szStackBuffer, sizeof(szStackBuffer));
648
649 return cch;
650}
651
659 template<class _Traits1, class _Ax1, class _Traits2, class _Ax2>
660 static _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
661{
662 WCHAR szStackBuffer[WINSTD_STACK_BUFFER_BYTES / sizeof(WCHAR)];
663
664 // Try to convert to stack buffer first.
665 int cch = ::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (int)sMultiByteStr.length(), szStackBuffer, _countof(szStackBuffer));
666 if (cch) {
667 // Copy from stack.
668 sWideCharStr.assign(szStackBuffer, cch);
669 }
670 else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
671 // Query the required output size. Allocate buffer. Then convert again.
672 cch = ::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (int)sMultiByteStr.length(), NULL, 0);
673 sWideCharStr.resize(cch);
674 cch = ::MultiByteToWideChar(CodePage, dwFlags, sMultiByteStr.c_str(), (int)sMultiByteStr.length(), &sWideCharStr[0], cch);
675 }
676
677 SecureZeroMemory(szStackBuffer, sizeof(szStackBuffer));
678
679 return cch;
680}
681
687 template<class _Traits, class _Ax>
688 static 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)
689{
690 std::unique_ptr<CHAR[], winstd::LocalFree_delete<CHAR[]> > lpBuffer;
691 DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast<LPSTR>((LPSTR*)get_ptr(lpBuffer)), 0, Arguments);
692 if (dwResult)
693 str.assign(lpBuffer.get(), dwResult);
694 return dwResult;
695}
696
702 template<class _Traits, class _Ax>
703 static 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)
704{
705 std::unique_ptr<WCHAR[], winstd::LocalFree_delete<WCHAR[]> > lpBuffer;
706 DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast<LPWSTR>((LPWSTR*)get_ptr(lpBuffer)), 0, Arguments);
707 if (dwResult)
708 str.assign(lpBuffer.get(), dwResult);
709 return dwResult;
710}
711
713
714#pragma warning(pop)
715
716 namespace winstd
717{
720
724#ifdef _UNICODE
725 typedef std::wstring tstring;
726#else
727 typedef std::string tstring;
728#endif
729
733 template <class _Ty>
734 struct LocalFree_delete
735 {
736 typedef LocalFree_delete<_Ty> _Myt;
737
741 LocalFree_delete() {}
742
746 template <class _Ty2> LocalFree_delete(const LocalFree_delete<_Ty2>&) {}
747
753 void operator()(_Ty *_Ptr) const
754 {
755 LocalFree(_Ptr);
756 }
757 };
758
762 template <class _Ty>
763 struct LocalFree_delete<_Ty[]>
764 {
765 typedef LocalFree_delete<_Ty> _Myt;
766
770 LocalFree_delete() noexcept {}
771
775 void operator()(_Frees_ptr_opt_ _Ty *_Ptr) const noexcept
776 {
777 LocalFree(_Ptr);
778 }
779
785 template<class _Other>
786 void operator()(_Other *) const
787 {
788 LocalFree(_Ptr);
789 }
790 };
791
795 struct GlobalFree_delete
796 {
800 GlobalFree_delete() {}
801
807 void operator()(HGLOBAL _Ptr) const
808 {
809 GlobalFree(_Ptr);
810 }
811 };
812
816 template <class T>
817 class globalmem_accessor
818 {
819 WINSTD_NONCOPYABLE(globalmem_accessor)
820 WINSTD_NONMOVABLE(globalmem_accessor)
821
822 public:
828 globalmem_accessor(_In_ HGLOBAL hMem) : m_h(hMem)
829 {
830 m_data = reinterpret_cast<T*>(GlobalLock(hMem));
831 if (!m_data)
832 throw win_runtime_error("GlobalLock failed");
833 }
834
840 virtual ~globalmem_accessor()
841 {
842 GlobalUnlock(m_h);
843 }
844
848 T* data() const noexcept
849 {
850 return m_data;
851 }
852
853 protected:
854 HGLOBAL m_h;
855 T* m_data;
856 };
857
861 template<class _Ty, class _Dx>
862 class ref_unique_ptr
863 {
864 public:
870 ref_unique_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) :
871 m_own(owner),
872 m_ptr(owner.release())
873 {}
874
880 ref_unique_ptr(_Inout_ ref_unique_ptr<_Ty, _Dx> &&other) :
881 m_own(other.m_own),
882 m_ptr(other.m_ptr)
883 {
884 other.m_ptr = nullptr;
885 }
886
890 ~ref_unique_ptr()
891 {
892 if (m_ptr != nullptr)
893 m_own.reset(m_ptr);
894 }
895
901 operator typename _Ty**()
902 {
903 return &m_ptr;
904 }
905
911 operator typename _Ty*&()
912 {
913 return m_ptr;
914 }
915
916 protected:
917 std::unique_ptr<_Ty, _Dx> &m_own;
918 _Ty *m_ptr;
919 };
920
928 template<class _Ty, class _Dx>
929 ref_unique_ptr<_Ty, _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty, _Dx> &owner) noexcept
930 {
931 return ref_unique_ptr<_Ty, _Dx>(owner);
932 }
933
938 template<class _Ty, class _Dx>
939 class ref_unique_ptr<_Ty[], _Dx>
940 {
941 public:
947 ref_unique_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx> &owner) noexcept :
948 m_own(owner),
949 m_ptr(owner.release())
950 {}
951
957 ref_unique_ptr(_Inout_ ref_unique_ptr<_Ty[], _Dx> &&other) :
958 m_own(other.m_own),
959 m_ptr(other.m_ptr)
960 {
961 other.m_ptr = nullptr;
962 }
963
967 virtual ~ref_unique_ptr()
968 {
969 if (m_ptr != nullptr)
970 m_own.reset(m_ptr);
971 }
972
978 operator typename _Ty**() noexcept
979 {
980 return &m_ptr;
981 }
982
988 operator typename _Ty*&()
989 {
990 return m_ptr;
991 }
992
993 protected:
994 std::unique_ptr<_Ty[], _Dx> &m_own;
995 _Ty *m_ptr;
996 };
997
1006 template<class _Ty, class _Dx>
1007 ref_unique_ptr<_Ty[], _Dx> get_ptr(_Inout_ std::unique_ptr<_Ty[], _Dx>& owner) noexcept
1008 {
1009 return ref_unique_ptr<_Ty[], _Dx>(owner);
1010 }
1011
1013
1016
1022 template <class T, const T INVAL>
1023 class handle
1024 {
1025 public:
1029 typedef T handle_type;
1030
1034 static const T invalid;
1035
1039 handle() noexcept : m_h(invalid)
1040 {}
1041
1047 handle(_In_opt_ handle_type h) noexcept : m_h(h)
1048 {}
1049
1055 handle(_Inout_ handle<handle_type, INVAL> &&h) noexcept
1056 {
1057 // Transfer handle.
1058 m_h = h.m_h;
1059 h.m_h = invalid;
1060 }
1061
1062 private:
1063 // This class is noncopyable.
1064 handle(_In_ const handle<handle_type, INVAL> &h) noexcept {};
1065 handle<handle_type, INVAL>& operator=(_In_ const handle<handle_type, INVAL> &h) noexcept {};
1066
1067 public:
1073 handle<handle_type, INVAL>& operator=(_In_opt_ handle_type h) noexcept
1074 {
1075 attach(h);
1076 return *this;
1077 }
1078
1084 #pragma warning(suppress: 26432) // Move constructor is also present, but not detected by code analysis somehow.
1085 handle<handle_type, INVAL>& operator=(_Inout_ handle<handle_type, INVAL> &&h) noexcept
1086 {
1087 if (this != std::addressof(h)) {
1088 // Transfer handle.
1089 if (m_h != invalid)
1090 free_internal();
1091 m_h = h.m_h;
1092 h.m_h = invalid;
1093 }
1094 return *this;
1095 }
1096
1102 operator handle_type() const
1103 {
1104 return m_h;
1105 }
1106
1112 handle_type*& operator*() const
1113 {
1114 assert(m_h != invalid);
1115 return *m_h;
1116 }
1117
1122 handle_type* operator&()
1123 {
1124 assert(m_h == invalid);
1125 return &m_h;
1126 }
1127
1133 handle_type operator->() const
1134 {
1135 assert(m_h != invalid);
1136 return m_h;
1137 }
1138
1149 bool operator!() const
1150 {
1151 return m_h == invalid;
1152 }
1153
1162 bool operator<(_In_opt_ handle_type h) const
1163 {
1164 return m_h < h;
1165 }
1166
1175 bool operator<=(_In_opt_ handle_type h) const
1176 {
1177 return !operator>(h);
1178 }
1179
1188 bool operator>=(_In_opt_ handle_type h) const
1189 {
1190 return !operator<(h);
1191 }
1192
1201 bool operator>(_In_opt_ handle_type h) const
1202 {
1203 return h < m_h;
1204 }
1205
1214 bool operator!=(_In_opt_ handle_type h) const
1215 {
1216 return !operator==(h);
1217 }
1218
1227 bool operator==(_In_opt_ handle_type h) const
1228 {
1229 return m_h == h;
1230 }
1231
1239 void attach(_In_opt_ handle_type h) noexcept
1240 {
1241 if (m_h != invalid)
1242 free_internal();
1243 m_h = h;
1244 }
1245
1251 handle_type detach()
1252 {
1253 handle_type h = m_h;
1254 m_h = invalid;
1255 return h;
1256 }
1257
1261 void free()
1262 {
1263 if (m_h != invalid) {
1264 free_internal();
1265 m_h = invalid;
1266 }
1267 }
1268
1269 protected:
1273 virtual void free_internal() noexcept = 0;
1274
1275 protected:
1276 handle_type m_h;
1277 };
1278
1279 template <class T, const T INVAL>
1280 const T handle<T, INVAL>::invalid = INVAL;
1281
1285 template <class T, T INVAL>
1286 class dplhandle : public handle<T, INVAL>
1287 {
1288 public:
1292 dplhandle() noexcept
1293 {}
1294
1300 dplhandle(_In_opt_ handle_type h) noexcept : handle<handle_type, INVAL>(h)
1301 {}
1302
1308 dplhandle<handle_type, INVAL>(_In_ const dplhandle<handle_type, INVAL> &h) : handle<handle_type, INVAL>(duplicate_internal(h.m_h))
1309 {}
1310
1316 dplhandle<handle_type, INVAL>(_Inout_ dplhandle<handle_type, INVAL> &&h) noexcept : handle<handle_type, INVAL>(std::move(h))
1317 {}
1318
1324 dplhandle<handle_type, INVAL>& operator=(_In_opt_ handle_type h) noexcept
1325 {
1326 handle<handle_type, INVAL>::operator=(h);
1327 return *this;
1328 }
1329
1335 dplhandle<handle_type, INVAL>& operator=(_In_ const dplhandle<handle_type, INVAL> &h) noexcept
1336 {
1337 if (this != std::addressof(h)) {
1338 if (h.m_h != invalid) {
1339 handle_type h_new = duplicate_internal(h.m_h);
1340
1341 if (m_h != invalid)
1342 free_internal();
1343
1344 m_h = h_new;
1345 } else {
1346 if (m_h != invalid)
1347 free_internal();
1348
1349 m_h = invalid;
1350 }
1351 }
1352 return *this;
1353 }
1354
1360 #pragma warning(disable: 26432) // Move constructor is also present, but not detected by code analysis somehow.
1361 dplhandle<handle_type, INVAL>& operator=(_Inout_ dplhandle<handle_type, INVAL> &&h) noexcept
1362 {
1363 handle<handle_type, INVAL>::operator=(std::move(h));
1364 return *this;
1365 }
1366
1372 handle_type duplicate() const
1373 {
1374 return m_h != invalid ? duplicate_internal(m_h) : invalid;
1375 }
1376
1382 void attach_duplicated(_In_opt_ handle_type h)
1383 {
1384 if (m_h != invalid)
1385 free_internal();
1386
1387 m_h = h != invalid ? duplicate_internal(h) : invalid;
1388 }
1389
1390 protected:
1399 virtual handle_type duplicate_internal(_In_ handle_type h) const = 0;
1400 };
1401
1403
1406
1416 inline std::string load_msg_from_res(_In_opt_ HMODULE hModule, _In_ UINT nId, _In_ WORD wLanguage)
1417 {
1418 std::string sResult;
1419 HRSRC hFoundRes = FindResourceExW(hModule, MAKEINTRESOURCEW(6), MAKEINTRESOURCEW(nId), wLanguage);
1420 if (hFoundRes) {
1421 DWORD dwSize = SizeofResource(hModule, hFoundRes);
1422 if (dwSize) {
1423 HGLOBAL hLoadedRes = LoadResource(hModule, hFoundRes);
1424 if (hLoadedRes) {
1425 LPCWSTR szMessage = reinterpret_cast<LPCWSTR>(LockResource(hLoadedRes));
1426 if (szMessage) {
1427 WideCharToMultiByte(CP_UTF8, 0, szMessage, dwSize / sizeof(*szMessage), sResult, NULL, NULL);
1428 return sResult;
1429 } else
1430 SetLastError(ERROR_LOCK_FAILED);
1431 }
1432 }
1433 }
1434 sprintf(sResult, "msg %u", nId);
1435 return sResult;
1436 }
1437
1447 inline std::string fmt_msg_from_res(_In_opt_ HMODULE hModule, _In_ UINT nId, _In_ WORD wLanguage, ...)
1448 {
1449 std::string sResult;
1450 HRSRC hFoundRes = FindResourceExW(hModule, MAKEINTRESOURCEW(6), MAKEINTRESOURCEW(nId), wLanguage);
1451 if (hFoundRes) {
1452 DWORD dwSize = SizeofResource(hModule, hFoundRes);
1453 if (dwSize) {
1454 HGLOBAL hLoadedRes = LoadResource(hModule, hFoundRes);
1455 if (hLoadedRes) {
1456 LPCWSTR szFormat = reinterpret_cast<LPCWSTR>(LockResource(hLoadedRes));
1457 if (szFormat) {
1458 dwSize /= sizeof(*szFormat);
1459 assert(wcsnlen(szFormat, dwSize) < dwSize); // Resource strings must be zero-terminated to make strings directly usable with sprintf.
1460 va_list arg;
1461 va_start(arg, wLanguage);
1462 std::wstring sMessage;
1463 vsprintf(sMessage, szFormat, arg);
1464 va_end(arg);
1465 WideCharToMultiByte(CP_UTF8, 0, sMessage, sResult, NULL, NULL);
1466 return sResult;
1467 } else
1468 SetLastError(ERROR_LOCK_FAILED);
1469 }
1470 }
1471 }
1472 sprintf(sResult, "msg %u", nId);
1473 return sResult;
1474 }
1475
1479 template <typename _Tn>
1480 class num_runtime_error : public std::runtime_error
1481 {
1482 public:
1483 typedef _Tn error_type;
1484
1485 public:
1492 num_runtime_error(_In_ error_type num, _In_ const std::string& msg) :
1493 m_num(num),
1494 runtime_error(msg)
1495 {}
1496
1503 num_runtime_error(_In_ error_type num, _In_opt_z_ const char *msg = nullptr) :
1504 m_num(num),
1505 runtime_error(msg)
1506 {}
1507
1511 error_type number() const
1512 {
1513 return m_num;
1514 }
1515
1516 protected:
1517 error_type m_num;
1518 };
1519
1523 class win_runtime_error : public num_runtime_error<DWORD>
1524 {
1525 public:
1531 win_runtime_error(_In_ error_type num) : num_runtime_error<DWORD>(num, message(num))
1532 {}
1533
1540 win_runtime_error(_In_ error_type num, _In_ const std::string& msg) : num_runtime_error<DWORD>(num, msg + ": " + message(num))
1541 {}
1542
1549 win_runtime_error(_In_ error_type num, _In_z_ const char *msg) : num_runtime_error<DWORD>(num, std::string(msg) + ": " + message(num))
1550 {}
1551
1555 win_runtime_error() : num_runtime_error<DWORD>(GetLastError(), message(GetLastError()))
1556 {}
1557
1563 win_runtime_error(_In_ const std::string& msg) : num_runtime_error<DWORD>(GetLastError(), msg + ": " + message(GetLastError()))
1564 {}
1565
1571 win_runtime_error(_In_z_ const char *msg) : num_runtime_error<DWORD>(GetLastError(), std::string(msg) + ": " + message(GetLastError()))
1572 {}
1573
1574 protected:
1581 static std::string message(_In_ error_type num, _In_opt_ DWORD dwLanguageId = 0)
1582 {
1583 error_type runtime_num = GetLastError();
1584 std::wstring wstr;
1585 if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, num, dwLanguageId, wstr, NULL)) {
1586 // Stock Windows error messages contain CRLF. Well... Trim all the trailing white space.
1587 wstr.erase(wstr.find_last_not_of(L" \t\n\r\f\v") + 1);
1588 } else
1589 sprintf(wstr, num >= 0x10000 ? L"Error 0x%X" : L"Error %u", num);
1590 std::string str;
1591 WideCharToMultiByte(CP_UTF8, 0, wstr, str, NULL, NULL);
1592 SetLastError(runtime_num);
1593 return str;
1594 }
1595 };
1596
1598
1601
1605 template<class _Elem, class _Traits, class _Ax>
1606 class basic_string_printf : public std::basic_string<_Elem, _Traits, _Ax>
1607 {
1608 public:
1611
1617 basic_string_printf(_In_z_ _Printf_format_string_ const _Elem *format, ...)
1618 {
1619 va_list arg;
1620 va_start(arg, format);
1621 vsprintf(*this, format, arg);
1622 va_end(arg);
1623 }
1624
1626
1629
1636 basic_string_printf(_In_ HINSTANCE hInstance, _In_ UINT nFormatID, ...)
1637 {
1638 _Myt format;
1639 ATLENSURE(format.LoadString(hInstance, nFormatID));
1640
1641 va_list arg;
1642 va_start(arg, nFormatID);
1643 vsprintf(*this, format, arg);
1644 va_end(arg);
1645 }
1646
1654 basic_string_printf(_In_ HINSTANCE hInstance, _In_ WORD wLanguageID, _In_ UINT nFormatID, ...)
1655 {
1656 _Myt format;
1657 ATLENSURE(format.LoadString(hInstance, nFormatID, wLanguageID));
1658
1659 va_list arg;
1660 va_start(arg, nFormatID);
1661 vsprintf(*this, format, arg);
1662 va_end(arg);
1663 }
1664
1666 };
1667
1671 typedef basic_string_printf<char, std::char_traits<char>, std::allocator<char> > string_printf;
1672
1676 typedef basic_string_printf<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > wstring_printf;
1677
1681#ifdef _UNICODE
1682 typedef wstring_printf tstring_printf;
1683#else
1684 typedef string_printf tstring_printf;
1685#endif
1686
1690 template<class _Elem, class _Traits, class _Ax>
1691 class basic_string_msg : public std::basic_string<_Elem, _Traits, _Ax>
1692 {
1693 public:
1696
1702 basic_string_msg(_In_z_ _FormatMessage_format_string_ const _Elem *format, ...)
1703 {
1704 va_list arg;
1705 va_start(arg, format);
1706 FormatMessage(FORMAT_MESSAGE_FROM_STRING, format, 0, 0, *this, &arg);
1707 va_end(arg);
1708 }
1709
1711
1714
1721 basic_string_msg(_In_ HINSTANCE hInstance, _In_ UINT nFormatID, ...)
1722 {
1723 _Myt format(GetManager());
1724 ATLENSURE(format.LoadString(hInstance, nFormatID));
1725
1726 va_list arg;
1727 va_start(arg, nFormatID);
1728 FormatMessage(FORMAT_MESSAGE_FROM_STRING, format, 0, 0, *this, &arg);
1729 va_end(arg);
1730 }
1731
1739 basic_string_msg(_In_ HINSTANCE hInstance, _In_ WORD wLanguageID, _In_ UINT nFormatID, ...)
1740 {
1741 _Myt format(GetManager());
1742 ATLENSURE(format.LoadString(hInstance, nFormatID, wLanguageID));
1743
1744 va_list arg;
1745 va_start(arg, nFormatID);
1746 FormatMessage(FORMAT_MESSAGE_FROM_STRING, format, 0, 0, *this, &arg);
1747 va_end(arg);
1748 }
1749
1751
1757 basic_string_msg(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _In_opt_ va_list *Arguments)
1758 {
1759 FormatMessage(dwFlags & ~FORMAT_MESSAGE_ARGUMENT_ARRAY, lpSource, dwMessageId, dwLanguageId, *this, Arguments);
1760 }
1761
1767 basic_string_msg(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _In_opt_ DWORD_PTR *Arguments)
1768 {
1769 FormatMessage(dwFlags | FORMAT_MESSAGE_ARGUMENT_ARRAY, lpSource, dwMessageId, dwLanguageId, *this, (va_list*)Arguments);
1770 }
1771
1777 basic_string_msg(_In_ DWORD dwFlags, _In_z_ LPCTSTR pszFormat, _In_opt_ va_list *Arguments)
1778 {
1779 FormatMessage(dwFlags & ~FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_FROM_STRING, pszFormat, 0, 0, *this, Arguments);
1780 }
1781
1787 basic_string_msg(_In_ DWORD dwFlags, _In_z_ LPCTSTR pszFormat, _In_opt_ DWORD_PTR *Arguments)
1788 {
1789 FormatMessage(dwFlags | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_FROM_STRING, pszFormat, 0, 0, *this, (va_list*)Arguments);
1790 }
1791 };
1792
1796 typedef basic_string_msg<char, std::char_traits<char>, std::allocator<char> > string_msg;
1797
1801 typedef basic_string_msg<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > wstring_msg;
1802
1806#ifdef _UNICODE
1807 typedef wstring_msg tstring_msg;
1808#else
1809 typedef string_msg tstring_msg;
1810#endif
1811
1815 template<class _Elem, class _Traits, class _Ax>
1816 class basic_string_guid : public std::basic_string<_Elem, _Traits, _Ax>
1817 {
1818 public:
1821
1828 basic_string_guid(_In_ const GUID &guid, _In_z_ _Printf_format_string_ const _Elem *format)
1829 {
1830 sprintf<_Elem, _Traits, _Ax>(*this, format,
1831 guid.Data1,
1832 guid.Data2,
1833 guid.Data3,
1834 guid.Data4[0], guid.Data4[1],
1835 guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
1836 }
1837
1839 };
1840
1844 class string_guid : public basic_string_guid<char, std::char_traits<char>, std::allocator<char> >
1845 {
1846 public:
1849
1855 string_guid(_In_ const GUID &guid) :
1856 basic_string_guid<char, std::char_traits<char>, std::allocator<char> >(guid, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}")
1857 {}
1858
1860 };
1861
1865 class wstring_guid : public basic_string_guid<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >
1866 {
1867 public:
1870
1876 wstring_guid(_In_ const GUID &guid) :
1877 basic_string_guid<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >(guid, L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}")
1878 {}
1879
1881 };
1882
1886#ifdef _UNICODE
1887 typedef wstring_guid tstring_guid;
1888#else
1889 typedef string_guid tstring_guid;
1890#endif
1891
1893
1896
1897 // winstd::sanitizing_allocator::destroy() member generates _Ptr parameter not used warning for primitive datatypes _Ty.
1898 #pragma warning(push)
1899 #pragma warning(disable: 4100)
1900
1908 template<class _Ty>
1909 class sanitizing_allocator : public std::allocator<_Ty>
1910 {
1911 public:
1912 typedef std::allocator<_Ty> _Mybase;
1913
1917 template<class _Other>
1918 struct rebind
1919 {
1920 typedef sanitizing_allocator<_Other> other;
1921 };
1922
1926 sanitizing_allocator() noexcept : _Mybase()
1927 {}
1928
1932 sanitizing_allocator(_In_ const sanitizing_allocator<_Ty> &_Othr) : _Mybase(_Othr)
1933 {}
1934
1938 template<class _Other>
1939 sanitizing_allocator(_In_ const sanitizing_allocator<_Other> &_Othr) noexcept : _Mybase(_Othr)
1940 {}
1941
1945 void deallocate(_In_ _Ty* const _Ptr, _In_ const std::size_t _Count)
1946 {
1947 // Sanitize then free.
1948 SecureZeroMemory(_Ptr, sizeof(_Ty) * _Count);
1949 _Mybase::deallocate(_Ptr, _Count);
1950 }
1951 };
1952
1953 #pragma warning(pop)
1954
1962 typedef std::basic_string<char, std::char_traits<char>, sanitizing_allocator<char> > sanitizing_string;
1963
1971 typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, sanitizing_allocator<wchar_t> > sanitizing_wstring;
1972
1976#ifdef _UNICODE
1977 typedef sanitizing_wstring sanitizing_tstring;
1978#else
1979 typedef sanitizing_string sanitizing_tstring;
1980#endif
1981
1985 template<size_t N>
1986 class sanitizing_blob
1987 {
1988 public:
1992 sanitizing_blob()
1993 {
1994 ZeroMemory(m_data, N);
1995 }
1996
2000 ~sanitizing_blob()
2001 {
2002 SecureZeroMemory(m_data, N);
2003 }
2004
2005 public:
2006 unsigned char m_data[N];
2007 };
2008
2010}
winstd::basic_string_guid
Base template class to support converting GUID to string.
Definition Common.h:1817
winstd::basic_string_guid::basic_string_guid
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:1828
winstd::basic_string_msg
Base template class to support string formatting using FormatMessage() style templates.
Definition Common.h:1692
winstd::basic_string_msg::basic_string_msg
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:1767
winstd::basic_string_msg::basic_string_msg
basic_string_msg(DWORD dwFlags, LPCTSTR pszFormat, va_list *Arguments)
Initializes a new string and formats its contents using FormatMessage() style.
Definition Common.h:1777
winstd::basic_string_msg::basic_string_msg
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:1739
winstd::basic_string_msg::basic_string_msg
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:1757
winstd::basic_string_msg::basic_string_msg
basic_string_msg(const _Elem *format,...)
Initializes a new string and formats its contents using FormatMessage() style template.
Definition Common.h:1702
winstd::basic_string_msg::basic_string_msg
basic_string_msg(HINSTANCE hInstance, UINT nFormatID,...)
Initializes a new string and formats its contents using FormatMessage() style template in resources.
Definition Common.h:1721
winstd::basic_string_msg::basic_string_msg
basic_string_msg(DWORD dwFlags, LPCTSTR pszFormat, DWORD_PTR *Arguments)
Initializes a new string and formats its contents using FormatMessage() style.
Definition Common.h:1787
winstd::basic_string_printf
Base template class to support string formatting using printf() style templates.
Definition Common.h:1607
winstd::basic_string_printf::basic_string_printf
basic_string_printf(const _Elem *format,...)
Initializes a new string and formats its contents using printf() style template.
Definition Common.h:1617
winstd::basic_string_printf::basic_string_printf
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:1654
winstd::basic_string_printf::basic_string_printf
basic_string_printf(HINSTANCE hInstance, UINT nFormatID,...)
Initializes a new string and formats its contents using printf() style template in resources.
Definition Common.h:1636
winstd::dplhandle
Base abstract template class to support object handle keeping for objects that support trivial handle...
Definition Common.h:1287
winstd::dplhandle::duplicate_internal
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...
winstd::dplhandle::operator=
dplhandle< handle_type, INVAL > & operator=(handle_type h) noexcept
Attaches already available object handle.
Definition Common.h:1324
winstd::dplhandle::duplicate
handle_type duplicate() const
Duplicates and returns a new object handle.
Definition Common.h:1372
winstd::dplhandle::operator=
dplhandle< handle_type, INVAL > & operator=(dplhandle< handle_type, INVAL > &&h) noexcept
Moves the object.
Definition Common.h:1361
winstd::dplhandle::attach_duplicated
void attach_duplicated(handle_type h)
Duplicates an object handle and sets a new object handle.
Definition Common.h:1382
winstd::dplhandle::dplhandle
dplhandle(handle_type h) noexcept
Initializes a new class instance with an already available object handle.
Definition Common.h:1300
winstd::dplhandle::operator=
dplhandle< handle_type, INVAL > & operator=(const dplhandle< handle_type, INVAL > &h) noexcept
Duplicates the object.
Definition Common.h:1335
winstd::dplhandle::dplhandle
dplhandle() noexcept
Initializes a new class instance with the object handle set to INVAL.
Definition Common.h:1292
winstd::globalmem_accessor
Context scope automatic GlobalAlloc (un)access.
Definition Common.h:818
winstd::globalmem_accessor::m_h
HGLOBAL m_h
memory handle
Definition Common.h:854
winstd::globalmem_accessor::~globalmem_accessor
virtual ~globalmem_accessor()
Decrements the lock count associated with a memory object.
Definition Common.h:840
winstd::globalmem_accessor::m_data
T * m_data
memory pointer
Definition Common.h:855
winstd::globalmem_accessor::data
T * data() const noexcept
Return data pointer.
Definition Common.h:848
winstd::globalmem_accessor::globalmem_accessor
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:828
winstd::handle
Base abstract template class to support generic object handle keeping.
Definition Common.h:1024
winstd::handle::operator*
handle_type *& operator*() const
Returns the object handle value when the object handle is a pointer to a value (class,...
Definition Common.h:1112
winstd::handle::free_internal
virtual void free_internal() noexcept=0
Abstract member function that must be implemented by child classes to do the actual object destructio...
winstd::handle::handle
handle() noexcept
Initializes a new class instance with the object handle set to INVAL.
Definition Common.h:1039
winstd::handle::operator>=
bool operator>=(handle_type h) const
Is handle greater than or equal to?
Definition Common.h:1188
winstd::handle::operator->
handle_type operator->() const
Provides object handle member access when the object handle is a pointer to a class or struct.
Definition Common.h:1133
winstd::handle::operator&
handle_type * operator&()
Returns the object handle reference.
Definition Common.h:1122
winstd::handle::handle_type
T handle_type
Datatype of the object handle this template class handles.
Definition Common.h:1029
winstd::handle::handle
handle(handle_type h) noexcept
Initializes a new class instance with an already available object handle.
Definition Common.h:1047
winstd::handle::operator<
bool operator<(handle_type h) const
Is handle less than?
Definition Common.h:1162
winstd::handle::operator=
handle< handle_type, INVAL > & operator=(handle_type h) noexcept
Attaches already available object handle.
Definition Common.h:1073
winstd::handle::operator!
bool operator!() const
Tests if the object handle is invalid.
Definition Common.h:1149
winstd::handle::operator=
handle< handle_type, INVAL > & operator=(handle< handle_type, INVAL > &&h) noexcept
Move assignment.
Definition Common.h:1085
winstd::handle::operator!=
bool operator!=(handle_type h) const
Is handle not equal to?
Definition Common.h:1214
winstd::handle::free
void free()
Destroys the object.
Definition Common.h:1261
winstd::handle::m_h
handle_type m_h
Object handle.
Definition Common.h:1276
winstd::handle::attach
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1239
winstd::handle::operator==
bool operator==(handle_type h) const
Is handle equal to?
Definition Common.h:1227
winstd::handle::handle
handle(handle< handle_type, INVAL > &&h) noexcept
Move constructor.
Definition Common.h:1055
winstd::handle::detach
handle_type detach()
Dismisses the object handle from this class.
Definition Common.h:1251
winstd::handle::operator>
bool operator>(handle_type h) const
Is handle greater than?
Definition Common.h:1201
winstd::handle::operator<=
bool operator<=(handle_type h) const
Is handle less than or equal to?
Definition Common.h:1175
winstd::num_runtime_error
Numerical runtime error.
Definition Common.h:1481
winstd::num_runtime_error::num_runtime_error
num_runtime_error(error_type num, const char *msg=nullptr)
Constructs an exception.
Definition Common.h:1503
winstd::num_runtime_error::num_runtime_error
num_runtime_error(error_type num, const std::string &msg)
Constructs an exception.
Definition Common.h:1492
winstd::num_runtime_error::number
error_type number() const
Returns the error number.
Definition Common.h:1511
winstd::num_runtime_error::error_type
_Tn error_type
Error number type.
Definition Common.h:1483
winstd::num_runtime_error::m_num
error_type m_num
Numeric error code.
Definition Common.h:1517
winstd::ref_unique_ptr< _Ty[], _Dx >::m_own
std::unique_ptr< _Ty[], _Dx > & m_own
Original owner of the pointer.
Definition Common.h:994
winstd::ref_unique_ptr< _Ty[], _Dx >::ref_unique_ptr
ref_unique_ptr(ref_unique_ptr< _Ty[], _Dx > &&other)
Moves object.
Definition Common.h:957
winstd::ref_unique_ptr< _Ty[], _Dx >::~ref_unique_ptr
virtual ~ref_unique_ptr()
Returns ownership of the pointer.
Definition Common.h:967
winstd::ref_unique_ptr< _Ty[], _Dx >::ref_unique_ptr
ref_unique_ptr(std::unique_ptr< _Ty[], _Dx > &owner) noexcept
Takes ownership of the pointer.
Definition Common.h:947
winstd::ref_unique_ptr< _Ty[], _Dx >::m_ptr
_Ty * m_ptr
Pointer.
Definition Common.h:995
winstd::ref_unique_ptr
Helper class for returning pointers to std::unique_ptr.
Definition Common.h:863
winstd::ref_unique_ptr::m_own
std::unique_ptr< _Ty, _Dx > & m_own
Original owner of the pointer.
Definition Common.h:917
winstd::ref_unique_ptr::m_ptr
_Ty * m_ptr
Pointer.
Definition Common.h:918
winstd::ref_unique_ptr::ref_unique_ptr
ref_unique_ptr(ref_unique_ptr< _Ty, _Dx > &&other)
Moves object.
Definition Common.h:880
winstd::ref_unique_ptr::~ref_unique_ptr
~ref_unique_ptr()
Returns ownership of the pointer.
Definition Common.h:890
winstd::ref_unique_ptr::ref_unique_ptr
ref_unique_ptr(std::unique_ptr< _Ty, _Dx > &owner)
Takes ownership of the pointer.
Definition Common.h:870
winstd::sanitizing_allocator
An allocator template that sanitizes each memory block before it is destroyed or reallocated.
Definition Common.h:1910
winstd::sanitizing_allocator::sanitizing_allocator
sanitizing_allocator(const sanitizing_allocator< _Ty > &_Othr)
Construct by copying.
Definition Common.h:1932
winstd::sanitizing_allocator::sanitizing_allocator
sanitizing_allocator(const sanitizing_allocator< _Other > &_Othr) noexcept
Construct from a related allocator.
Definition Common.h:1939
winstd::sanitizing_allocator::deallocate
void deallocate(_Ty *const _Ptr, const std::size_t _Count)
Deallocate object at _Ptr sanitizing its content first.
Definition Common.h:1945
winstd::sanitizing_allocator::_Mybase
std::allocator< _Ty > _Mybase
Base type.
Definition Common.h:1912
winstd::sanitizing_allocator::sanitizing_allocator
sanitizing_allocator() noexcept
Construct default allocator.
Definition Common.h:1926
winstd::sanitizing_blob
Sanitizing BLOB.
Definition Common.h:1987
winstd::sanitizing_blob::sanitizing_blob
sanitizing_blob()
Constructs uninitialized BLOB.
Definition Common.h:1992
winstd::sanitizing_blob::~sanitizing_blob
~sanitizing_blob()
Sanitizes BLOB.
Definition Common.h:2000
winstd::string_guid
Single-byte character implementation of a class to support converting GUID to string.
Definition Common.h:1845
winstd::string_guid::string_guid
string_guid(const GUID &guid)
Initializes a new string and formats its contents to string representation of given GUID.
Definition Common.h:1855
winstd::win_runtime_error
Windows runtime error.
Definition Common.h:1524
winstd::win_runtime_error::win_runtime_error
win_runtime_error(const char *msg)
Constructs an exception using GetLastError()
Definition Common.h:1571
winstd::win_runtime_error::win_runtime_error
win_runtime_error(error_type num, const char *msg)
Constructs an exception.
Definition Common.h:1549
winstd::win_runtime_error::win_runtime_error
win_runtime_error(error_type num)
Constructs an exception.
Definition Common.h:1531
winstd::win_runtime_error::win_runtime_error
win_runtime_error()
Constructs an exception using GetLastError()
Definition Common.h:1555
winstd::win_runtime_error::message
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:1581
winstd::win_runtime_error::win_runtime_error
win_runtime_error(const std::string &msg)
Constructs an exception using GetLastError()
Definition Common.h:1563
winstd::win_runtime_error::win_runtime_error
win_runtime_error(error_type num, const std::string &msg)
Constructs an exception.
Definition Common.h:1540
winstd::wstring_guid
Wide character implementation of a class to support converting GUID to string.
Definition Common.h:1866
winstd::wstring_guid::wstring_guid
wstring_guid(const GUID &guid)
Initializes a new string and formats its contents to string representation of given GUID.
Definition Common.h:1876
winstd::load_msg_from_res
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:1416
winstd::fmt_msg_from_res
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:1447
WINSTD_NONCOPYABLE
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
WINSTD_STACK_BUFFER_BYTES
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition Common.h:94
winstd::tstring
std::string tstring
Multi-byte / Wide-character string (according to _UNICODE)
Definition Common.h:727
winstd::get_ptr
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:929
WINSTD_NONMOVABLE
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition Common.h:75
winstd::sanitizing_wstring
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:1971
winstd::sanitizing_tstring
sanitizing_string sanitizing_tstring
Multi-byte / Wide-character sanitizing string (according to _UNICODE)
Definition Common.h:1979
winstd::sanitizing_string
std::basic_string< char, std::char_traits< char >, sanitizing_allocator< char > > sanitizing_string
A sanitizing variant of std::string.
Definition Common.h:1962
SecureWideCharToMultiByte
static int SecureWideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, std::basic_string< char, _Traits, _Ax > &sMultiByteStr, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar) noexcept
Maps a UTF-16 (wide character) string to a std::string. The new character string is not necessarily f...
Definition Common.h:429
winstd::wstring_printf
basic_string_printf< wchar_t, std::char_traits< wchar_t >, std::allocator< wchar_t > > wstring_printf
Wide character implementation of a class to support string formatting using printf() style templates.
Definition Common.h:1676
MultiByteToWideChar
static int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, std::basic_string< wchar_t, _Traits, _Ax > &sWideCharStr) noexcept
Maps a character string to a UTF-16 (wide character) std::wstring. The character string is not necess...
Definition Common.h:518
FormatMessageW
static DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, std::basic_string< wchar_t, _Traits, _Ax > &str, va_list *Arguments)
Formats a message string.
Definition Common.h:703
FormatMessageA
static DWORD FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, std::basic_string< char, _Traits, _Ax > &str, va_list *Arguments)
Formats a message string.
Definition Common.h:688
winstd::tstring_guid
string_guid tstring_guid
Multi-byte / Wide-character string GUID (according to _UNICODE)
Definition Common.h:1889
winstd::wstring_msg
basic_string_msg< wchar_t, std::char_traits< wchar_t >, std::allocator< wchar_t > > wstring_msg
Wide character implementation of a class to support string formatting using FormatMessage() style tem...
Definition Common.h:1801
winstd::string_printf
basic_string_printf< char, std::char_traits< char >, std::allocator< char > > string_printf
Single-byte character implementation of a class to support string formatting using printf() style tem...
Definition Common.h:1671
SecureMultiByteToWideChar
static int SecureMultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, std::basic_string< wchar_t, _Traits, _Ax > &sWideCharStr) noexcept
Maps a character string to a UTF-16 (wide character) std::wstring. The character string is not necess...
Definition Common.h:599
winstd::tstring_printf
string_printf tstring_printf
Multi-byte / Wide-character formatted string (according to _UNICODE)
Definition Common.h:1684
WideCharToMultiByte
static int WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, std::basic_string< char, _Traits, _Ax > &sMultiByteStr, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar) noexcept
Maps a UTF-16 (wide character) string to a std::string. The new character string is not necessarily f...
Definition Common.h:348
sprintf
static int sprintf(std::basic_string< _Elem, _Traits, _Ax > &str, const _Elem *format,...)
Formats string using printf().
Definition Common.h:333
vsprintf
static int vsprintf(std::basic_string< char, _Traits, _Ax > &str, const char *format, va_list arg)
Formats string using printf().
Definition Common.h:256
winstd::string_msg
basic_string_msg< char, std::char_traits< char >, std::allocator< char > > string_msg
Single-byte character implementation of a class to support string formatting using FormatMessage() st...
Definition Common.h:1796
winstd::tstring_msg
string_msg tstring_msg
Multi-byte / Wide-character formatted string (according to _UNICODE)
Definition Common.h:1809
winstd::handle::invalid
static const T invalid
Invalid handle value.
Definition Common.h:1034
winstd::GlobalFree_delete
Deleter for unique_ptr using GlobalFree.
Definition Common.h:796
winstd::GlobalFree_delete::GlobalFree_delete
GlobalFree_delete()
Default construct.
Definition Common.h:800
winstd::GlobalFree_delete::operator()
void operator()(HGLOBAL _Ptr) const
Delete a pointer.
Definition Common.h:807
winstd::LocalFree_delete< _Ty[]>::LocalFree_delete
LocalFree_delete() noexcept
Default construct.
Definition Common.h:770
winstd::LocalFree_delete< _Ty[]>::_Myt
LocalFree_delete< _Ty > _Myt
This type.
Definition Common.h:765
winstd::LocalFree_delete< _Ty[]>::operator()
void operator()(_Other *) const
Delete a pointer of another type.
Definition Common.h:786
winstd::LocalFree_delete< _Ty[]>::operator()
void operator()(_Ty *_Ptr) const noexcept
Delete a pointer.
Definition Common.h:775
winstd::LocalFree_delete
Deleter for unique_ptr using LocalFree.
Definition Common.h:735
winstd::LocalFree_delete::_Myt
LocalFree_delete< _Ty > _Myt
This type.
Definition Common.h:736
winstd::LocalFree_delete::LocalFree_delete
LocalFree_delete(const LocalFree_delete< _Ty2 > &)
Construct from another LocalFree_delete.
Definition Common.h:746
winstd::LocalFree_delete::operator()
void operator()(_Ty *_Ptr) const
Delete a pointer.
Definition Common.h:753
winstd::LocalFree_delete::LocalFree_delete
LocalFree_delete()
Default construct.
Definition Common.h:741
winstd::sanitizing_allocator::rebind
Convert this type to sanitizing_allocator<_Other>
Definition Common.h:1919
winstd::sanitizing_allocator::rebind::other
sanitizing_allocator< _Other > other
Other type.
Definition Common.h:1920