19#pragma warning(disable: 4505)
25template<
class _Traits,
class _Ax>
26static DWORD
GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_string<char, _Traits, _Ax> &sValue)
noexcept
34 if (dwResult < _countof(szStackBuffer)) {
36 sValue.assign(szStackBuffer, dwResult);
41 std::unique_ptr<char[]> szBuffer(
new char[dwCapacity]);
43 if (dwResult < dwCapacity) {
44 sValue.assign(szBuffer.get(), dwResult);
56template<
class _Traits,
class _Ax>
57static DWORD
GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
noexcept
63 if (dwResult < _countof(szStackBuffer)) {
65 sValue.assign(szStackBuffer, dwResult);
70 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[dwCapacity]);
72 if (dwResult < dwCapacity) {
73 sValue.assign(szBuffer.get(), dwResult);
81template<
class _Traits,
class _Ax>
82static _Success_(
return != 0) int
GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<
char, _Traits, _Ax> &sValue) noexcept
89 iResult = ::GetWindowTextLengthA(hWnd);
95 sValue.assign(szBuffer, iResult);
98 std::unique_ptr<char[]> szBuffer(
new char[++iResult]);
100 sValue.assign(szBuffer.get(), iResult);
114template<
class _Traits,
class _Ax>
115static _Success_(
return != 0) int
GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue) noexcept
122 iResult = ::GetWindowTextLengthW(hWnd);
128 sValue.assign(szBuffer, iResult);
131 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[++iResult]);
133 sValue.assign(szBuffer.get(), iResult);
143template<
class _Ty,
class _Ax>
144static _Success_(
return != 0) BOOL
GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept
149 DWORD dwVerInfoSize = ::GetFileVersionInfoSizeA(lptstrFilename, &dwHandle);
150 if (dwVerInfoSize != 0) {
152 aValue.resize((dwVerInfoSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
153 return ::GetFileVersionInfoA(lptstrFilename, dwHandle, dwVerInfoSize, aValue.data());
163template<
class _Ty,
class _Ax>
164static _Success_(
return != 0) BOOL
GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept
169 DWORD dwVerInfoSize = ::GetFileVersionInfoSizeW(lptstrFilename, &dwHandle);
170 if (dwVerInfoSize != 0) {
172 aValue.resize((dwVerInfoSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
173 return ::GetFileVersionInfoW(lptstrFilename, dwHandle, dwVerInfoSize, aValue.data());
179template<
class _Traits,
class _Ax>
184 for (SIZE_T sSizeOut = SIZETAdd(strlen(lpSrc), 0x100);;) {
185 if (sSizeOut > DWORD_MAX)
186 throw std::invalid_argument(
"String too big");
187 DWORD dwSizeIn =
static_cast<DWORD
>(sSizeOut);
188 std::unique_ptr<char[]> szBuffer(
new char[(
size_t)dwSizeIn + 2]);
193 }
else if (sSizeOut <= dwSizeIn) {
195 sValue.assign(szBuffer.get(), sSizeOut - 1);
196 return static_cast<DWORD
>(sSizeOut);
209template<
class _Traits,
class _Ax>
210static _Success_(
return != 0) DWORD
ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue)
212 for (SIZE_T sSizeOut = SIZETAdd(wcslen(lpSrc), 0x100);;) {
213 if (sSizeOut > DWORD_MAX)
214 throw std::invalid_argument(
"String too big");
215 DWORD dwSizeIn =
static_cast<DWORD
>(sSizeOut);
216 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[(
size_t)dwSizeIn + 1]);
221 }
else if (sSizeOut <= dwSizeIn) {
223 sValue.assign(szBuffer.get(), sSizeOut - 1);
224 return static_cast<DWORD
>(sSizeOut);
233template<
class _Traits,
class _Ax>
234static VOID
GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<char, _Traits, _Ax> &str)
noexcept
238 sprintf(str,
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
242 lpGuid->Data4[0], lpGuid->Data4[1],
243 lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
252template<
class _Traits,
class _Ax>
253static VOID
GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &str)
noexcept
257 sprintf(str, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
261 lpGuid->Data4[0], lpGuid->Data4[1],
262 lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
267#define GuidToString GuidToStringW
269#define GuidToString GuidToStringA
273static _Success_(
return) BOOL
StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL)
noexcept
278 unsigned long long ullTmp;
280 if (!lpszGuid || !lpGuid || *lpszGuid !=
'{')
return FALSE;
283 g.Data1 = strtoul(lpszGuid, &lpszEnd, 16);
284 if (errno == ERANGE)
return FALSE;
287 if (*lpszGuid !=
'-')
return FALSE;
290 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
291 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
292 g.Data2 =
static_cast<unsigned short>(ulTmp);
295 if (*lpszGuid !=
'-')
return FALSE;
298 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
299 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
300 g.Data3 =
static_cast<unsigned short>(ulTmp);
303 if (*lpszGuid !=
'-')
return FALSE;
306 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
307 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
308 g.Data4[0] =
static_cast<unsigned char>((ulTmp >> 8) & 0xff);
309 g.Data4[1] =
static_cast<unsigned char>( ulTmp & 0xff);
312 if (*lpszGuid !=
'-')
return FALSE;
315 ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
316 if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF)
return FALSE;
317 g.Data4[2] =
static_cast<unsigned char>((ullTmp >> 40) & 0xff);
318 g.Data4[3] =
static_cast<unsigned char>((ullTmp >> 32) & 0xff);
319 g.Data4[4] =
static_cast<unsigned char>((ullTmp >> 24) & 0xff);
320 g.Data4[5] =
static_cast<unsigned char>((ullTmp >> 16) & 0xff);
321 g.Data4[6] =
static_cast<unsigned char>((ullTmp >> 8) & 0xff);
322 g.Data4[7] =
static_cast<unsigned char>( ullTmp & 0xff);
325 if (*lpszGuid !=
'}')
return FALSE;
329 *lpszGuidEnd = lpszGuid;
346static _Success_(
return) BOOL
StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL)
noexcept
351 unsigned long long ullTmp;
353 if (!lpszGuid || !lpGuid || *lpszGuid !=
'{')
return FALSE;
356 g.Data1 = wcstoul(lpszGuid, &lpszEnd, 16);
357 if (errno == ERANGE)
return FALSE;
360 if (*lpszGuid !=
'-')
return FALSE;
363 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
364 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
365 g.Data2 =
static_cast<unsigned short>(ulTmp);
368 if (*lpszGuid !=
'-')
return FALSE;
371 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
372 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
373 g.Data3 =
static_cast<unsigned short>(ulTmp);
376 if (*lpszGuid !=
'-')
return FALSE;
379 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
380 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
381 g.Data4[0] =
static_cast<unsigned char>((ulTmp >> 8) & 0xff);
382 g.Data4[1] =
static_cast<unsigned char>( ulTmp & 0xff);
385 if (*lpszGuid !=
'-')
return FALSE;
388 ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
389 if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF)
return FALSE;
390 g.Data4[2] =
static_cast<unsigned char>((ullTmp >> 40) & 0xff);
391 g.Data4[3] =
static_cast<unsigned char>((ullTmp >> 32) & 0xff);
392 g.Data4[4] =
static_cast<unsigned char>((ullTmp >> 24) & 0xff);
393 g.Data4[5] =
static_cast<unsigned char>((ullTmp >> 16) & 0xff);
394 g.Data4[6] =
static_cast<unsigned char>((ullTmp >> 8) & 0xff);
395 g.Data4[7] =
static_cast<unsigned char>( ullTmp & 0xff);
398 if (*lpszGuid !=
'}')
return FALSE;
402 *lpszGuidEnd = lpszGuid;
410#define StringToGuid StringToGuidW
412#define StringToGuid StringToGuidA
433template<
class _Traits,
class _Ax>
434static LSTATUS
RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<char, _Traits, _Ax> &sValue)
noexcept
438 DWORD dwSize =
sizeof(aStackBuffer), dwType;
442 if (lResult == ERROR_SUCCESS) {
443 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
445 dwSize /=
sizeof(CHAR);
446 sValue.assign(
reinterpret_cast<LPCSTR
>(aStackBuffer), dwSize &&
reinterpret_cast<LPCSTR
>(aStackBuffer)[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
447 }
else if (dwType == REG_EXPAND_SZ) {
450 lResult = ::GetLastError();
453 lResult = ERROR_INVALID_DATA;
455 }
else if (lResult == ERROR_MORE_DATA) {
456 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
458 std::unique_ptr<CHAR[]> szBuffer(
new CHAR[dwSize /
sizeof(CHAR)]);
459 if ((lResult =
::RegQueryValueExA(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
460 dwSize /=
sizeof(CHAR);
461 sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
463 }
else if (dwType == REG_EXPAND_SZ) {
465 std::unique_ptr<CHAR[]> szBuffer(
new CHAR[dwSize /
sizeof(CHAR)]);
466 if ((lResult =
::RegQueryValueExA(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
468 lResult = ::GetLastError();
472 lResult = ERROR_INVALID_DATA;
497template<
class _Traits,
class _Ax>
498static LSTATUS
RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
noexcept
502 DWORD dwSize =
sizeof(aStackBuffer), dwType;
506 if (lResult == ERROR_SUCCESS) {
507 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
509 dwSize /=
sizeof(WCHAR);
510 sValue.assign(
reinterpret_cast<LPCWSTR
>(aStackBuffer), dwSize &&
reinterpret_cast<LPCWSTR
>(aStackBuffer)[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
511 }
else if (dwType == REG_EXPAND_SZ) {
514 lResult = ::GetLastError();
517 lResult = ERROR_INVALID_DATA;
519 }
else if (lResult == ERROR_MORE_DATA) {
520 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
522 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[dwSize /
sizeof(WCHAR)]);
523 if ((lResult =
::RegQueryValueExW(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
524 dwSize /=
sizeof(WCHAR);
525 sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
527 }
else if (dwType == REG_EXPAND_SZ) {
529 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[dwSize /
sizeof(WCHAR)]);
530 if ((lResult =
::RegQueryValueExW(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
532 lResult = ::GetLastError();
536 lResult = ERROR_INVALID_DATA;
544template<
class _Ty,
class _Ax>
545static LSTATUS
RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData)
noexcept
549 DWORD dwSize =
sizeof(aStackBuffer);
552 lResult =
RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, aStackBuffer, &dwSize);
553 if (lResult == ERROR_SUCCESS) {
555 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
556 memcpy(aData.data(), aStackBuffer, dwSize);
557 }
else if (lResult == ERROR_MORE_DATA) {
559 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
560 lResult =
RegQueryValueExA(hKey, lpValueName, lpReserved, NULL,
reinterpret_cast<LPBYTE
>(aData.data()), &dwSize);
571template<
class _Ty,
class _Ax>
572static LSTATUS
RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData)
noexcept
576 DWORD dwSize =
sizeof(aStackBuffer);
579 lResult =
RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, aStackBuffer, &dwSize);
580 if (lResult == ERROR_SUCCESS) {
582 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
583 memcpy(aData.data(), aStackBuffer, dwSize);
584 }
else if (lResult == ERROR_MORE_DATA) {
586 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
587 lResult =
RegQueryValueExW(hKey, lpValueName, lpReserved, NULL,
reinterpret_cast<LPBYTE
>(aData.data()), &dwSize);
593#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
596template<
class _Traits,
class _Ax>
597static LSTATUS
RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_z_ LPCSTR pszValue, _Out_ std::basic_string<char, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCSTR pszDirectory)
noexcept
602 return ERROR_CALL_NOT_IMPLEMENTED;
610template<
class _Traits,
class _Ax>
611static LSTATUS
RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR pszValue, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sOut, _In_ DWORD Flags, _In_opt_z_ LPCWSTR pszDirectory)
noexcept
617 Flags &= ~REG_MUI_STRING_TRUNCATE;
620 lResult =
RegLoadMUIStringW(hKey, pszValue, szStackBuffer,
sizeof(szStackBuffer), &dwSize, Flags, pszDirectory);
621 if (lResult == ERROR_SUCCESS) {
623 sOut.assign(szStackBuffer, wcsnlen(szStackBuffer, dwSize/
sizeof(
wchar_t)));
624 }
else if (lResult == ERROR_MORE_DATA) {
626 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[(dwSize +
sizeof(
wchar_t) - 1)/
sizeof(
wchar_t)]);
627 sOut.assign(szBuffer.get(), (lResult =
RegLoadMUIStringW(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? wcsnlen(szBuffer.get(), dwSize/
sizeof(
wchar_t)) : 0);
640template<
class _Traits,
class _Ax>
641static _Success_(
return > 0) int
NormalizeString(_In_ NORM_FORM NormForm, _In_ LPCWSTR lpSrcString, _In_
int cwSrcLength, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sDstString) noexcept
646 int cch =
::NormalizeString(NormForm, lpSrcString, cwSrcLength, szStackBuffer, _countof(szStackBuffer));
649 sDstString.assign(szStackBuffer, cwSrcLength != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
651 switch (::GetLastError()) {
652 case ERROR_INSUFFICIENT_BUFFER:
653 for (
int i = 10; i--;) {
656 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[cch]);
657 cch =
::NormalizeString(NormForm, lpSrcString, cwSrcLength, szBuffer.get(), cch);
659 sDstString.assign(szBuffer.get(), cwSrcLength != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
662 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
683template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
684static _Success_(
return > 0) int
NormalizeString(_In_ NORM_FORM NormForm, _In_ const std::basic_string<
wchar_t, _Traits1, _Ax1> &sSrcString, _Out_ std::basic_string<
wchar_t, _Traits2, _Ax2> &sDstString) noexcept
689 int cch =
::NormalizeString(NormForm, sSrcString.c_str(), (
int)sSrcString.length(), szStackBuffer, _countof(szStackBuffer));
692 sDstString.assign(szStackBuffer, cch);
694 switch (::GetLastError()) {
695 case ERROR_INSUFFICIENT_BUFFER:
696 for (
int i = 10; i--;) {
699 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[cch]);
700 cch =
::NormalizeString(NormForm, sSrcString.c_str(), (
int)sSrcString.length(), szBuffer.get(), cch);
702 sDstString.assign(szBuffer.get(), cch);
705 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
722template<
class _Traits,
class _Ax>
723static _Success_(
return != 0) int WINAPI
LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string<
char, _Traits, _Ax> &sBuffer) noexcept
727 int i =
LoadStringA(hInstance, uID,
reinterpret_cast<LPSTR
>(&pszStr), 0);
729 sBuffer.assign(pszStr, i);
740template<
class _Traits,
class _Ax>
741static _Success_(
return != 0) int WINAPI
LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sBuffer) noexcept
745 int i =
LoadStringW(hInstance, uID,
reinterpret_cast<LPWSTR
>(&pszStr), 0);
747 sBuffer.assign(pszStr, i);
761 try {
vsprintf(str, lpOutputString, arg); }
catch (...) {
return; }
762 OutputDebugStringA(str.c_str());
773 try {
vsprintf(str, lpOutputString, arg); }
catch (...) {
return; }
774 OutputDebugStringW(str.c_str());
785 va_start(arg, lpOutputString);
798 va_start(arg, lpOutputString);
804template<
class _Traits,
class _Ax>
805static _Success_(
return != 0) int
GetDateFormatA(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCSTR lpFormat, _Out_ std::basic_string<
char, _Traits, _Ax> &sDate) noexcept
807 int iResult =
GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
810 std::unique_ptr<char[]> szBuffer(
new char[iResult]);
811 iResult =
GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
812 sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
824template<
class _Traits,
class _Ax>
825static _Success_(
return != 0) int
GetDateFormatW(_In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_z_ LPCWSTR lpFormat, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sDate) noexcept
827 int iResult =
GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
830 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[iResult]);
831 iResult =
GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
832 sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
840template<
class _Traits,
class _Ax>
841static _Success_(
return != 0) BOOL
LookupAccountSidA(_In_opt_z_ LPCSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<
char, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<
char, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept
845 DWORD dwNameLen = 0, dwRefDomainLen = 0;
849 NULL, &dwRefDomainLen,
853 if (sName ) sName ->clear();
854 if (sReferencedDomainName) sReferencedDomainName->clear();
856 }
else if (GetLastError() == ERROR_MORE_DATA) {
858 std::unique_ptr<char[]> bufName (
new char[dwNameLen ]);
859 std::unique_ptr<char[]> bufRefDomain(
new char[dwRefDomainLen]);
861 bufName .get(), &dwNameLen ,
862 bufRefDomain.get(), &dwRefDomainLen,
865 if (sName ) sName ->assign(bufName .get(), dwNameLen - 1);
866 if (sReferencedDomainName) sReferencedDomainName->assign(bufRefDomain.get(), dwRefDomainLen - 1);
879template<
class _Traits,
class _Ax>
880static _Success_(
return != 0) BOOL
LookupAccountSidW(_In_opt_z_ LPCWSTR lpSystemName, _In_ PSID lpSid, _Out_opt_ std::basic_string<
wchar_t, _Traits, _Ax> *sName, _Out_opt_ std::basic_string<
wchar_t, _Traits, _Ax> *sReferencedDomainName, _Out_ PSID_NAME_USE peUse) noexcept
884 DWORD dwNameLen = 0, dwRefDomainLen = 0;
888 NULL, &dwRefDomainLen,
892 if (sName ) sName ->clear();
893 if (sReferencedDomainName) sReferencedDomainName->clear();
895 }
else if (GetLastError() == ERROR_MORE_DATA) {
897 std::unique_ptr<wchar_t[]> bufName (
new wchar_t[dwNameLen ]);
898 std::unique_ptr<wchar_t[]> bufRefDomain(
new wchar_t[dwRefDomainLen]);
900 bufName .get(), &dwNameLen ,
901 bufRefDomain.get(), &dwRefDomainLen,
904 if (sName ) sName ->assign(bufName .get(), dwNameLen - 1);
905 if (sReferencedDomainName) sReferencedDomainName->assign(bufRefDomain.get(), dwRefDomainLen - 1);
918static _Success_(
return != FALSE) BOOL
CreateWellKnownSid(_In_ WELL_KNOWN_SID_TYPE WellKnownSidType, _In_opt_ PSID DomainSid, _Inout_ std::unique_ptr<SID> &Sid)
921 DWORD dwSize =
sizeof(szStackBuffer);
925 Sid.reset((SID*)
new BYTE[dwSize]);
926 memcpy(Sid.get(), szStackBuffer, dwSize);
928 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
930 Sid.reset((SID*)
new BYTE[dwSize]);
942static _Success_(
return != 0) BOOL
GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation) noexcept
947 if (
GetTokenInformation(TokenHandle, TokenInformationClass, szStackBuffer,
sizeof(szStackBuffer), &dwSize)) {
949 TokenInformation.reset((_Ty*)(
new BYTE[dwSize]));
950 memcpy(TokenInformation.get(), szStackBuffer, dwSize);
952 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
954 TokenInformation.reset((_Ty*)(
new BYTE[dwSize]));
955 return GetTokenInformation(TokenHandle, TokenInformationClass, TokenInformation.get(), dwSize, &dwSize);
965template<
class _Traits,
class _Ax>
966static _Success_(
return != 0) BOOL
QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<
char, _Traits, _Ax>& sExeName)
969 DWORD dwSize = _countof(szStackBuffer);
974 sExeName.assign(szStackBuffer, dwSize);
977 for (DWORD dwCapacity = 2 *
WINSTD_STACK_BUFFER_BYTES /
sizeof(
char); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
979 std::unique_ptr<char[]> szBuffer(
new char[dwCapacity]);
982 sExeName.assign(szBuffer.get(), dwSize);
994template<
class _Traits,
class _Ax>
995static _Success_(
return != 0) BOOL
QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<
wchar_t, _Traits, _Ax>& sExeName)
998 DWORD dwSize = _countof(szStackBuffer);
1003 sExeName.assign(szStackBuffer, dwSize);
1006 for (DWORD dwCapacity = 2 *
WINSTD_STACK_BUFFER_BYTES /
sizeof(
wchar_t); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
1008 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[dwCapacity]);
1009 dwSize = dwCapacity;
1011 sExeName.assign(szBuffer.get(), dwSize);
1030 template<HANDLE INVALID>
1145 if (!UnmapViewOfFile(_Ptr))
1174 InitializeCriticalSection(&
m_data);
1184 DeleteCriticalSection(&
m_data);
1192 operator LPCRITICAL_SECTION() noexcept
1271 PROCESS_HEAP_ENTRY e;
1273 while (HeapWalk(
m_h, &e) != FALSE) {
1274 if ((e.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
1276 _T(
"Allocated block%s%s\n")
1277 _T(
" Data portion begins at: %#p\n Size: %d bytes\n")
1278 _T(
" Overhead: %d bytes\n Region index: %d\n"),
1279 (e.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0 ?
tstring_printf(_T(
", movable with HANDLE %#p"), e.Block.hMem).c_str() : _T(
""),
1280 (e.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0 ? _T(
", DDESHARE") : _T(
""),
1290 const DWORD dwResult = GetLastError();
1291 if (dwResult != ERROR_NO_MORE_ITEMS)
1316 template <
class _Ty>
1333 template <
class _Other>
1354 template <
class _Other>
1380 UNREFERENCED_PARAMETER(size);
1382 HeapFree(
m_heap, 0, ptr);
1393 ::new ((
void*)ptr) _Ty(val);
1404 ::new ((
void*)ptr) _Ty(std::forward<_Ty>(val));
1447 if (!ActivateActCtx(hActCtx, &
m_cookie))
1515 m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
1533 TOKEN_PRIVILEGES privileges = { 1, {{{ 0, 0 }, SE_PRIVILEGE_ENABLED }} };
1534 if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &privileges.Privileges[0].Luid) ||
1535 !ImpersonateSelf(SecurityImpersonation))
1540 if (!OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES, FALSE, &h))
1543 if (!AdjustTokenPrivileges(thread_token, FALSE, &privileges,
sizeof(privileges), NULL, NULL))
1548 PROCESSENTRY32 entry = {
sizeof(PROCESSENTRY32) };
1551 while (_tcsicmp(entry.szExeFile, TEXT(
"winlogon.exe")) != 0)
1554 process winlogon_process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, entry.th32ProcessID);
1555 if (!winlogon_process)
1557 if (!
OpenProcessToken(winlogon_process, TOKEN_IMPERSONATE | TOKEN_DUPLICATE, &h))
1560 if (!DuplicateToken(winlogon_token, SecurityImpersonation, &h))
1563 if (!SetThreadToken(NULL, duplicated_token))
1571 DWORD dwResult = GetLastError();
1573 SetLastError(dwResult);
1590 if (!OpenClipboard(hWndNewOwner))
1634 SetConsoleCtrlHandler(
m_handler, FALSE);
1675 m_proc(std::move(h.m_proc)),
1688 VirtualFreeEx(
m_proc,
m_h, 0, MEM_RELEASE);
1698 if (
this != std::addressof(other)) {
1700 m_proc = std::move(other.m_proc);
1731 _In_ HANDLE hProcess,
1732 _In_opt_ LPVOID lpAddress,
1734 _In_ DWORD flAllocationType,
1735 _In_ DWORD flProtect)
noexcept
1737 handle_type h = VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect);
1753 VirtualFreeEx(
m_proc,
m_h, 0, MEM_RELEASE);
1795 s = RegDeleteKey(
m_h, szSubkey);
1796 if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
1802 s = RegOpenKeyEx(
m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS, &h);
1803 if (s == ERROR_SUCCESS)
1810 TCHAR szName[MAX_PATH];
1811 DWORD dwSize = _countof(szName);
1812 s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
1813 if (s == ERROR_SUCCESS)
1815 else if (s == ERROR_NO_MORE_ITEMS)
1824 s = RegDeleteKey(
m_h, szSubkey);
1825 if (s == ERROR_SUCCESS)
1890 hProcess = INVALID_HANDLE_VALUE;
1891 hThread = INVALID_HANDLE_VALUE;
1901 #pragma warning(push)
1902 #pragma warning(disable: 6001)
1904 if (hProcess != INVALID_HANDLE_VALUE)
1905 CloseHandle(hProcess);
1907 if (hThread != INVALID_HANDLE_VALUE)
1908 CloseHandle(hThread);
1910 #pragma warning(pop)
1943 DeregisterEventSource(
m_h);
1974 CloseServiceHandle(
m_h);
1984#pragma warning(push)
1985#pragma warning(disable: 4505)
1990 _In_ LPCSTR lpSubKey,
1991 _Reserved_ DWORD Reserved,
1992 _In_opt_ LPSTR lpClass,
1993 _In_ DWORD dwOptions,
1994 _In_ REGSAM samDesired,
1995 _In_opt_ CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
1997 _Out_opt_ LPDWORD lpdwDisposition)
2000 LSTATUS s =
RegCreateKeyExA(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition);
2001 if (s == ERROR_SUCCESS)
2013 _In_ LPCWSTR lpSubKey,
2014 _Reserved_ DWORD Reserved,
2015 _In_opt_ LPWSTR lpClass,
2016 _In_ DWORD dwOptions,
2017 _In_ REGSAM samDesired,
2018 _In_opt_ CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2020 _Out_opt_ LPDWORD lpdwDisposition)
2023 LSTATUS s =
RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition);
2024 if (s == ERROR_SUCCESS)
2032 _In_opt_ LPCSTR lpSubKey,
2033 _In_opt_ DWORD ulOptions,
2034 _In_ REGSAM samDesired,
2038 LSTATUS s =
RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, &h);
2039 if (s == ERROR_SUCCESS)
2051 _In_opt_ LPCWSTR lpSubKey,
2052 _In_opt_ DWORD ulOptions,
2053 _In_ REGSAM samDesired,
2057 LSTATUS s =
RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, &h);
2058 if (s == ERROR_SUCCESS)
2072 TokenHandle.attach(h);
2083static BOOL
DuplicateTokenEx(_In_ HANDLE hExistingToken, _In_ DWORD dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpTokenAttributes, _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, _In_ TOKEN_TYPE TokenType, _Inout_
winstd::win_handle<NULL> &NewToken)
2086 if (
DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, &h)) {
2098static BOOL
AllocateAndInitializeSid(_In_ PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, _In_ BYTE nSubAuthorityCount, _In_ DWORD nSubAuthority0, _In_ DWORD nSubAuthority1, _In_ DWORD nSubAuthority2, _In_ DWORD nSubAuthority3, _In_ DWORD nSubAuthority4, _In_ DWORD nSubAuthority5, _In_ DWORD nSubAuthority6, _In_ DWORD nSubAuthority7, _Inout_
winstd::security_id& Sid)
2101 if (
AllocateAndInitializeSid(pIdentifierAuthority, nSubAuthorityCount, nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3, nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, &h)) {
2112 DWORD dwResult =
SetEntriesInAclA(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
2113 if (dwResult == ERROR_SUCCESS)
2115 return ERROR_SUCCESS;
2126 DWORD dwResult =
SetEntriesInAclW(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
2127 if (dwResult == ERROR_SUCCESS)
2129 return ERROR_SUCCESS;
2137template<
class _Traits,
class _Ax>
2138_Success_(
return != 0) BOOL
GetThreadPreferredUILanguages(_In_ DWORD dwFlags, _Out_ PULONG pulNumLanguages, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue)
2141 ULONG ulSize = _countof(szStackBuffer);
2146 sValue.assign(szStackBuffer, ulSize - 1);
2148 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
2153 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[ulSize]);
2155 sValue.assign(szBuffer.get(), ulSize - 1);
Activates given activation context in constructor and deactivates it in destructor.
Definition Win.h:1433
actctx_activator(HANDLE hActCtx) noexcept
Construct the activator and activates the given activation context.
Definition Win.h:1445
virtual ~actctx_activator()
Deactivates activation context and destructs the activator.
Definition Win.h:1456
ULONG_PTR m_cookie
Cookie for context deactivation.
Definition Win.h:1463
Base template class to support string formatting using printf() style templates.
Definition Common.h:1611
Clipboard management.
Definition Win.h:1581
virtual ~clipboard_opener()
Closes the clipboard.
Definition Win.h:1599
clipboard_opener(HWND hWndNewOwner=NULL)
Opens the clipboard for examination and prevents other applications from modifying the clipboard cont...
Definition Win.h:1588
Console control handler stack management.
Definition Win.h:1609
console_ctrl_handler(PHANDLER_ROUTINE HandlerRoutine) noexcept
Construct the console control handler object and pushes the given handler to the console control hand...
Definition Win.h:1621
virtual ~console_ctrl_handler()
Pops console control handler from the console control handler stack.
Definition Win.h:1631
PHANDLER_ROUTINE m_handler
Pointer to console control handler.
Definition Win.h:1639
BOOL m_cookie
Did pushing the console control handler succeed?
Definition Win.h:1638
Critical section wrapper.
Definition Win.h:1162
critical_section() noexcept
Construct the object and initializes a critical section object.
Definition Win.h:1172
CRITICAL_SECTION m_data
Critical section struct.
Definition Win.h:1198
virtual ~critical_section()
Releases all resources used by an unowned critical section object.
Definition Win.h:1182
Event log handle wrapper.
Definition Win.h:1920
void free_internal() noexcept override
Closes an event log handle.
Definition Win.h:1941
virtual ~event_log()
Closes an event log handle.
Definition Win.h:1929
Find-file handle wrapper.
Definition Win.h:1207
virtual ~find_file()
Closes a file search handle.
Definition Win.h:1216
void free_internal() noexcept override
Closes a file search handle.
Definition Win.h:1228
Base abstract template class to support generic object handle keeping.
Definition Common.h:1020
LPVOID handle_type
Datatype of the object handle this template class handles.
Definition Common.h:1025
handle_type m_h
Object handle.
Definition Common.h:1274
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1237
HeapAlloc allocator.
Definition Win.h:1318
SIZE_T size_type
An unsigned integral type that can represent the length of any sequence that an object of template cl...
Definition Win.h:1327
_Ty value_type
A type that is managed by the allocator.
Definition Win.h:1320
heap_allocator(const heap_allocator< _Other > &other)
Constructs allocator from another type.
Definition Win.h:1355
HANDLE m_heap
Heap handle.
Definition Win.h:1426
pointer allocate(size_type count)
Allocates a new memory block.
Definition Win.h:1366
ptrdiff_t difference_type
A signed integral type that can represent the difference between values of pointers to the type of ob...
Definition Win.h:1328
heap_allocator(HANDLE heap)
Constructs allocator.
Definition Win.h:1345
_Ty & reference
A type that provides a reference to the type of object managed by the allocator.
Definition Win.h:1323
void construct(pointer ptr, _Ty &&val)
Calls moving constructor for the element.
Definition Win.h:1402
void deallocate(pointer ptr, size_type size)
Frees memory block.
Definition Win.h:1378
size_type max_size() const
Returns maximum memory block size.
Definition Win.h:1420
void construct(pointer ptr, const _Ty &val)
Calls copying constructor for the element.
Definition Win.h:1391
const _Ty & const_reference
A type that provides a constant reference to type of object managed by the allocator.
Definition Win.h:1325
const _Ty * const_pointer
A type that provides a constant pointer to the type of object managed by the allocator.
Definition Win.h:1324
_Ty * pointer
A type that provides a pointer to the type of object managed by the allocator.
Definition Win.h:1322
void destroy(pointer ptr)
Calls destructor for the element.
Definition Win.h:1412
Heap handle wrapper.
Definition Win.h:1240
bool enumerate() noexcept
Enumerates allocated heap blocks using OutputDebugString()
Definition Win.h:1262
void free_internal() noexcept override
Destroys the heap.
Definition Win.h:1306
virtual ~heap()
Destroys the heap.
Definition Win.h:1249
Base class for thread impersonation of another security context.
Definition Win.h:1470
virtual ~impersonator()
Reverts to current user and destructs the impersonator.
Definition Win.h:1482
impersonator() noexcept
Construct the impersonator.
Definition Win.h:1475
BOOL m_cookie
Did impersonation succeed?
Definition Win.h:1494
Module handle wrapper.
Definition Win.h:1065
void free_internal() noexcept override
Frees the module.
Definition Win.h:1086
virtual ~library()
Frees the module.
Definition Win.h:1074
Registry key wrapper class.
Definition Win.h:1767
void free_internal() noexcept override
Closes a handle to the registry key.
Definition Win.h:1839
bool delete_subkey(LPCTSTR szSubkey)
Deletes the specified registry subkey.
Definition Win.h:1791
virtual ~reg_key()
Closes a handle to the registry key.
Definition Win.h:1776
SC_HANDLE wrapper class.
Definition Win.h:1951
void free_internal() noexcept override
Closes an open object handle.
Definition Win.h:1972
virtual ~sc_handle()
Closes an open object handle.
Definition Win.h:1960
SID wrapper class.
Definition Win.h:1849
void free_internal() noexcept override
Closes a handle to the SID.
Definition Win.h:1870
virtual ~security_id()
Closes a handle to the SID.
Definition Win.h:1858
Lets the calling thread impersonate the security context of the SYSTEM user.
Definition Win.h:1523
system_impersonator() noexcept
Construct the impersonator and impersonates the SYSTEM user.
Definition Win.h:1531
Lets the calling thread impersonate the security context of a logged-on user.
Definition Win.h:1501
user_impersonator(HANDLE hToken) noexcept
Construct the impersonator and impersonates the given user.
Definition Win.h:1513
Memory in virtual address space of a process handle wrapper.
Definition Win.h:1646
vmemory & operator=(vmemory &&other) noexcept
Move assignment.
Definition Win.h:1696
bool alloc(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) noexcept
Reserves, commits, or changes the state of a region of memory within the virtual address space of a s...
Definition Win.h:1730
void free_internal() noexcept override
Frees the memory.
Definition Win.h:1751
void attach(HANDLE proc, handle_type h) noexcept
Sets a new memory handle for the class.
Definition Win.h:1713
virtual ~vmemory()
Frees the memory.
Definition Win.h:1685
vmemory(handle_type h, HANDLE proc) noexcept
Initializes a new class instance with an already available object handle.
Definition Win.h:1663
vmemory() noexcept
Initializes a new class instance with the memory handle set to INVAL.
Definition Win.h:1653
vmemory(vmemory &&h) noexcept
Move constructor.
Definition Win.h:1674
HANDLE m_proc
Handle of memory's process.
Definition Win.h:1757
Windows HANDLE wrapper class.
Definition Win.h:1032
void free_internal() noexcept override
Closes an open object handle.
Definition Win.h:1053
virtual ~win_handle()
Closes an open object handle.
Definition Win.h:1041
Windows runtime error.
Definition Common.h:1528
#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
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition Common.h:75
#define WINSTD_HANDLE_IMPL(C, T, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition Common.h:164
static const HANDLE invalid
Invalid handle value.
Definition Common.h:1030
static int NormalizeString(NORM_FORM NormForm, LPCWSTR lpSrcString, int cwSrcLength, std::basic_string< wchar_t, _Traits, _Ax > &sDstString) noexcept
Normalizes characters of a text string according to Unicode 4.0 TR#15.
Definition Win.h:641
static DWORD ExpandEnvironmentStringsW(LPCWSTR lpSrc, std::basic_string< wchar_t, _Traits, _Ax > &sValue)
Expands environment-variable strings, replaces them with the values defined for the current user,...
Definition Win.h:210
static BOOL StringToGuidA(LPCSTR lpszGuid, LPGUID lpGuid, LPCSTR *lpszGuidEnd=NULL) noexcept
Parses string with GUID and stores it to GUID.
Definition Win.h:273
static int GetWindowTextA(HWND hWnd, std::basic_string< char, _Traits, _Ax > &sValue) noexcept
Copies the text of the specified window's title bar (if it has one) into a std::wstring string.
Definition Win.h:82
static LSTATUS RegCreateKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, winstd::reg_key &result, LPDWORD lpdwDisposition)
Creates the specified registry key. If the key already exists, the function opens it.
Definition Win.h:2011
static int WINAPI LoadStringA(HINSTANCE hInstance, UINT uID, std::basic_string< char, _Traits, _Ax > &sBuffer) noexcept
Loads a string resource from the executable file associated with a specified module.
Definition Win.h:723
win_handle< INVALID_HANDLE_VALUE > file
File handle wrapper.
Definition Win.h:1126
static BOOL GetFileVersionInfoA(LPCSTR lptstrFilename, __reserved DWORD dwHandle, std::vector< _Ty, _Ax > &aValue) noexcept
Retrieves version information for the specified file and stores it in a std::vector buffer.
Definition Win.h:144
static LSTATUS RegCreateKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD Reserved, LPSTR lpClass, DWORD dwOptions, REGSAM samDesired, CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes, winstd::reg_key &result, LPDWORD lpdwDisposition)
Creates the specified registry key. If the key already exists, the function opens it.
Definition Win.h:1988
static LSTATUS RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, winstd::reg_key &result)
Opens the specified registry key.
Definition Win.h:2030
static LSTATUS RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, winstd::reg_key &result)
Opens the specified registry key.
Definition Win.h:2049
static VOID GuidToStringA(LPCGUID lpGuid, std::basic_string< char, _Traits, _Ax > &str) noexcept
Formats GUID and stores it in a std::wstring string.
Definition Win.h:234
static BOOL StringToGuidW(LPCWSTR lpszGuid, LPGUID lpGuid, LPCWSTR *lpszGuidEnd=NULL) noexcept
Parses string with GUID and stores it to GUID.
Definition Win.h:346
static LSTATUS RegLoadMUIStringW(HKEY hKey, LPCWSTR pszValue, std::basic_string< wchar_t, _Traits, _Ax > &sOut, DWORD Flags, LPCWSTR pszDirectory) noexcept
Loads the specified string from the specified key and subkey, and stores it in a std::wstring string.
Definition Win.h:611
static BOOL OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, winstd::win_handle< NULL > &TokenHandle)
Opens the access token associated with a process.
Definition Win.h:2068
static DWORD SetEntriesInAclW(ULONG cCountOfExplicitEntries, PEXPLICIT_ACCESS_W pListOfExplicitEntries, PACL OldAcl, std::unique_ptr< ACL, winstd::LocalFree_delete< ACL > > &Acl)
Creates a new access control list (ACL) by merging new access control or audit control information in...
Definition Win.h:2123
static BOOL LookupAccountSidA(LPCSTR lpSystemName, PSID lpSid, std::basic_string< char, _Traits, _Ax > *sName, std::basic_string< char, _Traits, _Ax > *sReferencedDomainName, PSID_NAME_USE peUse) noexcept
Retrieves the name of the account for this SID and the name of the first domain on which this SID is ...
Definition Win.h:841
static DWORD GetModuleFileNameW(HMODULE hModule, std::basic_string< wchar_t, _Traits, _Ax > &sValue) noexcept
Retrieves the fully qualified path for the file that contains the specified module and stores it in a...
Definition Win.h:57
static BOOL LookupAccountSidW(LPCWSTR lpSystemName, PSID lpSid, std::basic_string< wchar_t, _Traits, _Ax > *sName, std::basic_string< wchar_t, _Traits, _Ax > *sReferencedDomainName, PSID_NAME_USE peUse) noexcept
Retrieves the name of the account for this SID and the name of the first domain on which this SID is ...
Definition Win.h:880
static BOOL AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, winstd::security_id &Sid)
Allocates and initializes a security identifier (SID) with up to eight subauthorities.
Definition Win.h:2098
win_handle< INVALID_HANDLE_VALUE > process_snapshot
Process snapshot handle wrapper.
Definition Win.h:1111
static DWORD GetModuleFileNameA(HMODULE hModule, std::basic_string< char, _Traits, _Ax > &sValue) noexcept
Retrieves the fully qualified path for the file that contains the specified module and stores it in a...
Definition Win.h:26
static int GetDateFormatW(LCID Locale, DWORD dwFlags, const SYSTEMTIME *lpDate, LPCWSTR lpFormat, std::basic_string< wchar_t, _Traits, _Ax > &sDate) noexcept
Formats a date as a date string for a locale specified by the locale identifier. The function formats...
Definition Win.h:825
static BOOL CreateWellKnownSid(WELL_KNOWN_SID_TYPE WellKnownSidType, PSID DomainSid, std::unique_ptr< SID > &Sid)
Creates a SID for predefined aliases.
Definition Win.h:918
static int WINAPI LoadStringW(HINSTANCE hInstance, UINT uID, std::basic_string< wchar_t, _Traits, _Ax > &sBuffer) noexcept
Loads a string resource from the executable file associated with a specified module.
Definition Win.h:741
static BOOL GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, std::unique_ptr< _Ty > &TokenInformation) noexcept
Retrieves a specified type of information about an access token. The calling process must have approp...
Definition Win.h:942
static BOOL DuplicateTokenEx(HANDLE hExistingToken, DWORD dwDesiredAccess, LPSECURITY_ATTRIBUTES lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, winstd::win_handle< NULL > &NewToken)
Creates a new access token that duplicates an existing token. This function can create either a prima...
Definition Win.h:2083
static DWORD SetEntriesInAclA(ULONG cCountOfExplicitEntries, PEXPLICIT_ACCESS_A pListOfExplicitEntries, PACL OldAcl, std::unique_ptr< ACL, winstd::LocalFree_delete< ACL > > &Acl)
Creates a new access control list (ACL) by merging new access control or audit control information in...
Definition Win.h:2109
static LSTATUS RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, __reserved LPDWORD lpReserved, LPDWORD lpType, std::vector< _Ty, _Ax > &aData) noexcept
Retrieves the type and data for the specified value name associated with an open registry key and sto...
Definition Win.h:572
static BOOL GetFileVersionInfoW(LPCWSTR lptstrFilename, __reserved DWORD dwHandle, std::vector< _Ty, _Ax > &aValue) noexcept
Retrieves version information for the specified file and stores it in a std::vector buffer.
Definition Win.h:164
win_handle< NULL > event
Event handle wrapper.
Definition Win.h:1156
static LSTATUS RegLoadMUIStringA(HKEY hKey, LPCSTR pszValue, std::basic_string< char, _Traits, _Ax > &sOut, DWORD Flags, LPCSTR pszDirectory) noexcept
Loads the specified string from the specified key and subkey, and stores it in a std::wstring string.
Definition Win.h:597
static VOID OutputDebugStr(LPCSTR lpOutputString,...) noexcept
Formats and sends a string to the debugger for display.
Definition Win.h:782
static BOOL QueryFullProcessImageNameA(HANDLE hProcess, DWORD dwFlags, std::basic_string< char, _Traits, _Ax > &sExeName)
Retrieves the full name of the executable image for the specified process.
Definition Win.h:966
win_handle< NULL > mutex
Mutex handle wrapper.
Definition Win.h:1118
static DWORD ExpandEnvironmentStringsA(LPCSTR lpSrc, std::basic_string< char, _Traits, _Ax > &sValue)
Expands environment-variable strings, replaces them with the values defined for the current user,...
Definition Win.h:180
win_handle< NULL > file_mapping
File mapping.
Definition Win.h:1133
static BOOL QueryFullProcessImageNameW(HANDLE hProcess, DWORD dwFlags, std::basic_string< wchar_t, _Traits, _Ax > &sExeName)
Retrieves the full name of the executable image for the specified process.
Definition Win.h:995
win_handle< NULL > process
Process handle wrapper.
Definition Win.h:1097
static LSTATUS RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, __reserved LPDWORD lpReserved, LPDWORD lpType, std::vector< _Ty, _Ax > &aData) noexcept
Retrieves the type and data for the specified value name associated with an open registry key and sto...
Definition Win.h:545
BOOL GetThreadPreferredUILanguages(DWORD dwFlags, PULONG pulNumLanguages, std::basic_string< wchar_t, _Traits, _Ax > &sValue)
Retrieves the thread preferred UI languages for the current thread.
Definition Win.h:2138
static LSTATUS RegQueryStringValue(HKEY hReg, LPCSTR pszName, std::basic_string< char, _Traits, _Ax > &sValue) noexcept
Queries for a string value in the registry and stores it in a std::string string.
Definition Win.h:434
static int GetWindowTextW(HWND hWnd, std::basic_string< wchar_t, _Traits, _Ax > &sValue) noexcept
Copies the text of the specified window's title bar (if it has one) into a std::wstring string.
Definition Win.h:115
static int GetDateFormatA(LCID Locale, DWORD dwFlags, const SYSTEMTIME *lpDate, LPCSTR lpFormat, std::basic_string< char, _Traits, _Ax > &sDate) noexcept
Formats a date as a date string for a locale specified by the locale identifier. The function formats...
Definition Win.h:805
static VOID GuidToStringW(LPCGUID lpGuid, std::basic_string< wchar_t, _Traits, _Ax > &str) noexcept
Formats GUID and stores it in a std::wstring string.
Definition Win.h:253
static VOID OutputDebugStrV(LPCSTR lpOutputString, va_list arg) noexcept
Formats and sends a string to the debugger for display.
Definition Win.h:758
win_handle< NULL > thread
Thread handle wrapper.
Definition Win.h:1104
Deleter for unique_ptr using LocalFree.
Definition Common.h:731
Deleter for unique_ptr using UnmapViewOfFile.
Definition Win.h:1139
void operator()(void *_Ptr) const
Delete a pointer.
Definition Win.h:1143
A structure that enables an allocator for objects of one type to allocate storage for objects of anot...
Definition Win.h:1335
heap_allocator< _Other > other
Other allocator type.
Definition Win.h:1336