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 sValue.resize(dwCapacity - 1);
43 if (dwResult < dwCapacity) {
44 sValue.resize(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 sValue.resize(dwCapacity - 1);
72 if (dwResult < dwCapacity) {
73 sValue.resize(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);
92 sValue.resize(iResult++);
93 return ::GetWindowTextA(hWnd, &sValue[0], iResult);
105template<
class _Traits,
class _Ax>
106static _Success_(
return != 0) int
GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue) noexcept
113 iResult = ::GetWindowTextLengthW(hWnd);
116 sValue.resize(iResult++);
117 return ::GetWindowTextW(hWnd, &sValue[0], iResult);
125template<
class _Ty,
class _Ax>
126static _Success_(
return != 0) BOOL
GetFileVersionInfoA(_In_z_ LPCSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept
131 DWORD dwVerInfoSize = ::GetFileVersionInfoSizeA(lptstrFilename, &dwHandle);
132 if (dwVerInfoSize != 0) {
134 aValue.resize((dwVerInfoSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
135 return ::GetFileVersionInfoA(lptstrFilename, dwHandle, dwVerInfoSize, aValue.data());
145template<
class _Ty,
class _Ax>
146static _Success_(
return != 0) BOOL
GetFileVersionInfoW(_In_z_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle, _Out_ std::vector<_Ty, _Ax> &aValue) noexcept
151 DWORD dwVerInfoSize = ::GetFileVersionInfoSizeW(lptstrFilename, &dwHandle);
152 if (dwVerInfoSize != 0) {
154 aValue.resize((dwVerInfoSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
155 return ::GetFileVersionInfoW(lptstrFilename, dwHandle, dwVerInfoSize, aValue.data());
161template<
class _Traits,
class _Ax>
166 for (SIZE_T sSizeOut = SIZETAdd(strlen(lpSrc), 0x100);;) {
167 if (sSizeOut > DWORD_MAX)
168 throw std::invalid_argument(
"String too big");
169 DWORD dwSizeIn =
static_cast<DWORD
>(sSizeOut);
170 sValue.resize((
size_t)dwSizeIn + 1);
175 }
else if (sSizeOut <= dwSizeIn) {
177 sValue.resize(sSizeOut - 1);
178 return static_cast<DWORD
>(sSizeOut);
191template<
class _Traits,
class _Ax>
192static _Success_(
return != 0) DWORD
ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue)
194 for (SIZE_T sSizeOut = SIZETAdd(wcslen(lpSrc), 0x100);;) {
195 if (sSizeOut > DWORD_MAX)
196 throw std::invalid_argument(
"String too big");
197 DWORD dwSizeIn =
static_cast<DWORD
>(sSizeOut);
198 sValue.resize(dwSizeIn);
203 }
else if (sSizeOut <= dwSizeIn) {
205 sValue.resize(sSizeOut - 1);
206 return static_cast<DWORD
>(sSizeOut);
215template<
class _Traits,
class _Ax>
216static VOID
GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<char, _Traits, _Ax> &str)
noexcept
220 sprintf(str,
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
224 lpGuid->Data4[0], lpGuid->Data4[1],
225 lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
234template<
class _Traits,
class _Ax>
235static VOID
GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &str)
noexcept
239 sprintf(str, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
243 lpGuid->Data4[0], lpGuid->Data4[1],
244 lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
249#define GuidToString GuidToStringW
251#define GuidToString GuidToStringA
255static _Success_(
return) BOOL
StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL)
noexcept
260 unsigned long long ullTmp;
262 if (!lpszGuid || !lpGuid || *lpszGuid !=
'{')
return FALSE;
265 g.Data1 = strtoul(lpszGuid, &lpszEnd, 16);
266 if (errno == ERANGE)
return FALSE;
269 if (*lpszGuid !=
'-')
return FALSE;
272 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
273 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
274 g.Data2 =
static_cast<unsigned short>(ulTmp);
277 if (*lpszGuid !=
'-')
return FALSE;
280 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
281 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
282 g.Data3 =
static_cast<unsigned short>(ulTmp);
285 if (*lpszGuid !=
'-')
return FALSE;
288 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
289 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
290 g.Data4[0] =
static_cast<unsigned char>((ulTmp >> 8) & 0xff);
291 g.Data4[1] =
static_cast<unsigned char>( ulTmp & 0xff);
294 if (*lpszGuid !=
'-')
return FALSE;
297 ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
298 if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF)
return FALSE;
299 g.Data4[2] =
static_cast<unsigned char>((ullTmp >> 40) & 0xff);
300 g.Data4[3] =
static_cast<unsigned char>((ullTmp >> 32) & 0xff);
301 g.Data4[4] =
static_cast<unsigned char>((ullTmp >> 24) & 0xff);
302 g.Data4[5] =
static_cast<unsigned char>((ullTmp >> 16) & 0xff);
303 g.Data4[6] =
static_cast<unsigned char>((ullTmp >> 8) & 0xff);
304 g.Data4[7] =
static_cast<unsigned char>( ullTmp & 0xff);
307 if (*lpszGuid !=
'}')
return FALSE;
311 *lpszGuidEnd = lpszGuid;
328static _Success_(
return) BOOL
StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL)
noexcept
333 unsigned long long ullTmp;
335 if (!lpszGuid || !lpGuid || *lpszGuid !=
'{')
return FALSE;
338 g.Data1 = wcstoul(lpszGuid, &lpszEnd, 16);
339 if (errno == ERANGE)
return FALSE;
342 if (*lpszGuid !=
'-')
return FALSE;
345 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
346 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
347 g.Data2 =
static_cast<unsigned short>(ulTmp);
350 if (*lpszGuid !=
'-')
return FALSE;
353 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
354 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
355 g.Data3 =
static_cast<unsigned short>(ulTmp);
358 if (*lpszGuid !=
'-')
return FALSE;
361 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
362 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
363 g.Data4[0] =
static_cast<unsigned char>((ulTmp >> 8) & 0xff);
364 g.Data4[1] =
static_cast<unsigned char>( ulTmp & 0xff);
367 if (*lpszGuid !=
'-')
return FALSE;
370 ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
371 if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF)
return FALSE;
372 g.Data4[2] =
static_cast<unsigned char>((ullTmp >> 40) & 0xff);
373 g.Data4[3] =
static_cast<unsigned char>((ullTmp >> 32) & 0xff);
374 g.Data4[4] =
static_cast<unsigned char>((ullTmp >> 24) & 0xff);
375 g.Data4[5] =
static_cast<unsigned char>((ullTmp >> 16) & 0xff);
376 g.Data4[6] =
static_cast<unsigned char>((ullTmp >> 8) & 0xff);
377 g.Data4[7] =
static_cast<unsigned char>( ullTmp & 0xff);
380 if (*lpszGuid !=
'}')
return FALSE;
384 *lpszGuidEnd = lpszGuid;
392#define StringToGuid StringToGuidW
394#define StringToGuid StringToGuidA
415template<
class _Traits,
class _Ax>
416static LSTATUS
RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<char, _Traits, _Ax> &sValue)
noexcept
420 DWORD dwSize =
sizeof(aStackBuffer), dwType;
424 if (lResult == ERROR_SUCCESS) {
425 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
427 dwSize /=
sizeof(CHAR);
428 sValue.assign(
reinterpret_cast<LPCSTR
>(aStackBuffer), dwSize &&
reinterpret_cast<LPCSTR
>(aStackBuffer)[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
429 }
else if (dwType == REG_EXPAND_SZ) {
432 lResult = ::GetLastError();
435 lResult = ERROR_INVALID_DATA;
437 }
else if (lResult == ERROR_MORE_DATA) {
438 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
440 sValue.resize(dwSize /
sizeof(CHAR));
441 if ((lResult =
::RegQueryValueExA(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(&sValue[0]), &dwSize)) == ERROR_SUCCESS) {
442 dwSize /=
sizeof(CHAR);
443 sValue.resize(dwSize && sValue[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
445 }
else if (dwType == REG_EXPAND_SZ) {
447 std::unique_ptr<CHAR[]> szBuffer(
new CHAR[dwSize /
sizeof(CHAR) + 1]);
448 if ((lResult =
::RegQueryValueExA(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
449 dwSize /=
sizeof(CHAR);
450 szBuffer[dwSize] = 0;
452 lResult = ::GetLastError();
456 lResult = ERROR_INVALID_DATA;
481template<
class _Traits,
class _Ax>
482static LSTATUS
RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
noexcept
486 DWORD dwSize =
sizeof(aStackBuffer), dwType;
490 if (lResult == ERROR_SUCCESS) {
491 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
493 dwSize /=
sizeof(WCHAR);
494 sValue.assign(
reinterpret_cast<LPCWSTR
>(aStackBuffer), dwSize &&
reinterpret_cast<LPCWSTR
>(aStackBuffer)[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
495 }
else if (dwType == REG_EXPAND_SZ) {
498 lResult = ::GetLastError();
501 lResult = ERROR_INVALID_DATA;
503 }
else if (lResult == ERROR_MORE_DATA) {
504 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
506 sValue.resize(dwSize /
sizeof(WCHAR));
507 if ((lResult =
::RegQueryValueExW(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(&sValue[0]), &dwSize)) == ERROR_SUCCESS) {
508 dwSize /=
sizeof(WCHAR);
509 sValue.resize(dwSize && sValue[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
511 }
else if (dwType == REG_EXPAND_SZ) {
513 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[dwSize /
sizeof(WCHAR) + 1]);
514 if ((lResult =
::RegQueryValueExW(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
515 dwSize /=
sizeof(WCHAR);
516 szBuffer[dwSize] = 0;
518 lResult = ::GetLastError();
522 lResult = ERROR_INVALID_DATA;
530template<
class _Ty,
class _Ax>
531static LSTATUS
RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData)
noexcept
535 DWORD dwSize =
sizeof(aStackBuffer);
538 lResult =
RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, aStackBuffer, &dwSize);
539 if (lResult == ERROR_SUCCESS) {
541 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
542 memcpy(aData.data(), aStackBuffer, dwSize);
543 }
else if (lResult == ERROR_MORE_DATA) {
545 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
546 lResult =
RegQueryValueExA(hKey, lpValueName, lpReserved, NULL,
reinterpret_cast<LPBYTE
>(aData.data()), &dwSize);
557template<
class _Ty,
class _Ax>
558static LSTATUS
RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData)
noexcept
562 DWORD dwSize =
sizeof(aStackBuffer);
565 lResult =
RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, aStackBuffer, &dwSize);
566 if (lResult == ERROR_SUCCESS) {
568 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
569 memcpy(aData.data(), aStackBuffer, dwSize);
570 }
else if (lResult == ERROR_MORE_DATA) {
572 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
573 lResult =
RegQueryValueExW(hKey, lpValueName, lpReserved, NULL,
reinterpret_cast<LPBYTE
>(aData.data()), &dwSize);
579#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
582template<
class _Traits,
class _Ax>
583static 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
588 return ERROR_CALL_NOT_IMPLEMENTED;
596template<
class _Traits,
class _Ax>
597static 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
603 Flags &= ~REG_MUI_STRING_TRUNCATE;
606 lResult =
RegLoadMUIStringW(hKey, pszValue, szStackBuffer,
sizeof(szStackBuffer), &dwSize, Flags, pszDirectory);
607 if (lResult == ERROR_SUCCESS) {
609 sOut.assign(szStackBuffer, wcsnlen(szStackBuffer, dwSize/
sizeof(
wchar_t)));
610 }
else if (lResult == ERROR_MORE_DATA) {
612 sOut.resize((dwSize +
sizeof(
wchar_t) - 1)/
sizeof(
wchar_t) - 1);
613 sOut.resize((lResult =
RegLoadMUIStringW(hKey, pszValue, &sOut[0], dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? wcsnlen(&sOut[0], dwSize/
sizeof(
wchar_t)) : 0);
626template<
class _Traits,
class _Ax>
627static _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
632 int cch =
::NormalizeString(NormForm, lpSrcString, cwSrcLength, szStackBuffer, _countof(szStackBuffer));
635 sDstString.assign(szStackBuffer, cwSrcLength != -1 ? wcsnlen(szStackBuffer, cch) : (
size_t)cch - 1);
637 switch (::GetLastError()) {
638 case ERROR_INSUFFICIENT_BUFFER:
639 for (
int i = 10; i--;) {
642 sDstString.resize((
size_t)cch - 1);
643 cch =
::NormalizeString(NormForm, lpSrcString, cwSrcLength, &sDstString[0], cch);
645 sDstString.resize(cwSrcLength != -1 ? wcsnlen(&sDstString[0], cch) : (
size_t)cch - 1);
648 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
669template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
670static _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
675 int cch =
::NormalizeString(NormForm, sSrcString.c_str(), (
int)sSrcString.length(), szStackBuffer, _countof(szStackBuffer));
678 sDstString.assign(szStackBuffer, cch);
680 switch (::GetLastError()) {
681 case ERROR_INSUFFICIENT_BUFFER:
682 for (
int i = 10; i--;) {
685 sDstString.resize(cch);
686 cch =
::NormalizeString(NormForm, sSrcString.c_str(), (
int)sSrcString.length(), &sDstString[0], cch);
689 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
706template<
class _Traits,
class _Ax>
707static _Success_(
return != 0) int WINAPI
LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string<
char, _Traits, _Ax> &sBuffer) noexcept
711 int i =
LoadStringA(hInstance, uID,
reinterpret_cast<LPSTR
>(&pszStr), 0);
713 sBuffer.assign(pszStr, i);
724template<
class _Traits,
class _Ax>
725static _Success_(
return != 0) int WINAPI
LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sBuffer) noexcept
729 int i =
LoadStringW(hInstance, uID,
reinterpret_cast<LPWSTR
>(&pszStr), 0);
731 sBuffer.assign(pszStr, i);
745 try {
vsprintf(str, lpOutputString, arg); }
catch (...) {
return; }
746 OutputDebugStringA(str.c_str());
757 try {
vsprintf(str, lpOutputString, arg); }
catch (...) {
return; }
758 OutputDebugStringW(str.c_str());
769 va_start(arg, lpOutputString);
782 va_start(arg, lpOutputString);
788template<
class _Traits,
class _Ax>
789static _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
791 int iResult =
GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
794 sDate.resize(iResult - 1);
795 return GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, &sDate[0], iResult);
806template<
class _Traits,
class _Ax>
807static _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
809 int iResult =
GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
812 sDate.resize(iResult - 1);
813 return GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, &sDate[0], iResult);
820template<
class _Traits,
class _Ax>
821static _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
825 DWORD dwNameLen = 0, dwRefDomainLen = 0;
829 NULL, &dwRefDomainLen,
833 if (sName ) sName ->clear();
834 if (sReferencedDomainName) sReferencedDomainName->clear();
836 }
else if (GetLastError() == ERROR_MORE_DATA) {
838 std::unique_ptr<char[]> bufName (
new char[dwNameLen ]);
839 std::unique_ptr<char[]> bufRefDomain(
new char[dwRefDomainLen]);
841 bufName .get(), &dwNameLen ,
842 bufRefDomain.get(), &dwRefDomainLen,
845 if (sName ) sName ->assign(bufName .get(), dwNameLen - 1);
846 if (sReferencedDomainName) sReferencedDomainName->assign(bufRefDomain.get(), dwRefDomainLen - 1);
859template<
class _Traits,
class _Ax>
860static _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
864 DWORD dwNameLen = 0, dwRefDomainLen = 0;
868 NULL, &dwRefDomainLen,
872 if (sName ) sName ->clear();
873 if (sReferencedDomainName) sReferencedDomainName->clear();
875 }
else if (GetLastError() == ERROR_MORE_DATA) {
877 std::unique_ptr<wchar_t[]> bufName (
new wchar_t[dwNameLen ]);
878 std::unique_ptr<wchar_t[]> bufRefDomain(
new wchar_t[dwRefDomainLen]);
880 bufName .get(), &dwNameLen ,
881 bufRefDomain.get(), &dwRefDomainLen,
884 if (sName ) sName ->assign(bufName .get(), dwNameLen - 1);
885 if (sReferencedDomainName) sReferencedDomainName->assign(bufRefDomain.get(), dwRefDomainLen - 1);
898static _Success_(
return != FALSE) BOOL
CreateWellKnownSid(_In_ WELL_KNOWN_SID_TYPE WellKnownSidType, _In_opt_ PSID DomainSid, _Inout_ std::unique_ptr<SID> &Sid)
901 DWORD dwSize =
sizeof(szStackBuffer);
905 Sid.reset((SID*)
new BYTE[dwSize]);
906 memcpy(Sid.get(), szStackBuffer, dwSize);
908 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
910 Sid.reset((SID*)
new BYTE[dwSize]);
922static _Success_(
return != 0) BOOL
GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation) noexcept
927 if (
GetTokenInformation(TokenHandle, TokenInformationClass, szStackBuffer,
sizeof(szStackBuffer), &dwSize)) {
929 TokenInformation.reset((_Ty*)(
new BYTE[dwSize]));
930 memcpy(TokenInformation.get(), szStackBuffer, dwSize);
932 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
934 TokenInformation.reset((_Ty*)(
new BYTE[dwSize]));
935 return GetTokenInformation(TokenHandle, TokenInformationClass, TokenInformation.get(), dwSize, &dwSize);
945template<
class _Traits,
class _Ax>
946static _Success_(
return != 0) BOOL
QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<
char, _Traits, _Ax>& sExeName)
949 DWORD dwSize = _countof(szStackBuffer);
954 sExeName.assign(szStackBuffer, dwSize);
957 for (DWORD dwCapacity = 2 *
WINSTD_STACK_BUFFER_BYTES /
sizeof(
char); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
959 sExeName.resize(dwCapacity - 1);
962 sExeName.resize(dwSize);
974template<
class _Traits,
class _Ax>
975static _Success_(
return != 0) BOOL
QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<
wchar_t, _Traits, _Ax>& sExeName)
978 DWORD dwSize = _countof(szStackBuffer);
983 sExeName.assign(szStackBuffer, dwSize);
986 for (DWORD dwCapacity = 2 *
WINSTD_STACK_BUFFER_BYTES /
sizeof(
wchar_t); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
988 sExeName.resize(dwCapacity - 1);
991 sExeName.resize(dwSize);
1010 template<HANDLE INVALID>
1117 mutex_locker(_In_ HANDLE hMutex, _In_ DWORD dwMilliseconds = INFINITE) : m_h(hMutex)
1119 switch (WaitForSingleObject(m_h, dwMilliseconds)) {
1121 case WAIT_ABANDONED:
1124 throw std::runtime_error(
"timeout");
1169 if (!UnmapViewOfFile(_Ptr))
1198 InitializeCriticalSection(&
m_data);
1208 DeleteCriticalSection(&
m_data);
1216 operator LPCRITICAL_SECTION() noexcept
1295 PROCESS_HEAP_ENTRY e;
1297 while (HeapWalk(
m_h, &e) != FALSE) {
1298 if ((e.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
1300 _T(
"Allocated block%s%s\n")
1301 _T(
" Data portion begins at: %#p\n Size: %d bytes\n")
1302 _T(
" Overhead: %d bytes\n Region index: %d\n"),
1303 (e.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0 ?
tstring_printf(_T(
", movable with HANDLE %#p"), e.Block.hMem).c_str() : _T(
""),
1304 (e.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0 ? _T(
", DDESHARE") : _T(
""),
1314 const DWORD dwResult = GetLastError();
1315 if (dwResult != ERROR_NO_MORE_ITEMS)
1340 template <
class _Ty>
1357 template <
class _Other>
1377 template <
class _Other>
1402 UNREFERENCED_PARAMETER(size);
1404 HeapFree(
m_heap, 0, ptr);
1415 ::new ((
void*)ptr) _Ty(val);
1426 ::new ((
void*)ptr) _Ty(std::forward<_Ty>(val));
1469 if (!ActivateActCtx(hActCtx, &
m_cookie))
1537 m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
1555 TOKEN_PRIVILEGES privileges = { 1, {{{ 0, 0 }, SE_PRIVILEGE_ENABLED }} };
1556 if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &privileges.Privileges[0].Luid) ||
1557 !ImpersonateSelf(SecurityImpersonation))
1562 if (!OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES, FALSE, &h))
1565 if (!AdjustTokenPrivileges(thread_token, FALSE, &privileges,
sizeof(privileges), NULL, NULL))
1570 PROCESSENTRY32 entry = {
sizeof(PROCESSENTRY32) };
1573 while (_tcsicmp(entry.szExeFile, TEXT(
"winlogon.exe")) != 0)
1576 process winlogon_process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, entry.th32ProcessID);
1577 if (!winlogon_process)
1579 if (!
OpenProcessToken(winlogon_process, TOKEN_IMPERSONATE | TOKEN_DUPLICATE, &h))
1582 if (!DuplicateToken(winlogon_token, SecurityImpersonation, &h))
1585 if (!SetThreadToken(NULL, duplicated_token))
1611 if (!OpenClipboard(hWndNewOwner))
1655 SetConsoleCtrlHandler(
m_handler, FALSE);
1694 m_proc(std::move(h.m_proc)),
1706 VirtualFreeEx(
m_proc,
m_h, 0, MEM_RELEASE);
1716 if (
this != std::addressof(other)) {
1718 m_proc = std::move(other.m_proc);
1749 _In_ HANDLE hProcess,
1750 _In_opt_ LPVOID lpAddress,
1752 _In_ DWORD flAllocationType,
1753 _In_ DWORD flProtect)
noexcept
1755 handle_type h = VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect);
1771 VirtualFreeEx(
m_proc,
m_h, 0, MEM_RELEASE);
1813 s = RegDeleteKey(
m_h, szSubkey);
1814 if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
1820 s = RegOpenKeyEx(
m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS, &h);
1821 if (s == ERROR_SUCCESS)
1828 TCHAR szName[MAX_PATH];
1829 DWORD dwSize = _countof(szName);
1830 s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
1831 if (s == ERROR_SUCCESS)
1833 else if (s == ERROR_NO_MORE_ITEMS)
1842 s = RegDeleteKey(
m_h, szSubkey);
1843 if (s == ERROR_SUCCESS)
1908 hProcess = INVALID_HANDLE_VALUE;
1909 hThread = INVALID_HANDLE_VALUE;
1919 #pragma warning(push)
1920 #pragma warning(disable: 6001)
1922 if (hProcess != INVALID_HANDLE_VALUE)
1923 CloseHandle(hProcess);
1925 if (hThread != INVALID_HANDLE_VALUE)
1926 CloseHandle(hThread);
1928 #pragma warning(pop)
1961 DeregisterEventSource(
m_h);
1992 CloseServiceHandle(
m_h);
2002#pragma warning(push)
2003#pragma warning(disable: 4505)
2008 _In_ LPCSTR lpSubKey,
2009 _Reserved_ DWORD Reserved,
2010 _In_opt_ LPSTR lpClass,
2011 _In_ DWORD dwOptions,
2012 _In_ REGSAM samDesired,
2013 _In_opt_ CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2015 _Out_opt_ LPDWORD lpdwDisposition)
2018 LSTATUS s =
RegCreateKeyExA(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition);
2019 if (s == ERROR_SUCCESS)
2031 _In_ LPCWSTR lpSubKey,
2032 _Reserved_ DWORD Reserved,
2033 _In_opt_ LPWSTR lpClass,
2034 _In_ DWORD dwOptions,
2035 _In_ REGSAM samDesired,
2036 _In_opt_ CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2038 _Out_opt_ LPDWORD lpdwDisposition)
2041 LSTATUS s =
RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition);
2042 if (s == ERROR_SUCCESS)
2050 _In_opt_ LPCSTR lpSubKey,
2051 _In_opt_ DWORD ulOptions,
2052 _In_ REGSAM samDesired,
2056 LSTATUS s =
RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, &h);
2057 if (s == ERROR_SUCCESS)
2069 _In_opt_ LPCWSTR lpSubKey,
2070 _In_opt_ DWORD ulOptions,
2071 _In_ REGSAM samDesired,
2075 LSTATUS s =
RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, &h);
2076 if (s == ERROR_SUCCESS)
2090 TokenHandle.attach(h);
2101static 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)
2104 if (
DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, &h)) {
2116static 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)
2119 if (
AllocateAndInitializeSid(pIdentifierAuthority, nSubAuthorityCount, nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3, nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, &h)) {
2130 DWORD dwResult =
SetEntriesInAclA(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
2131 if (dwResult == ERROR_SUCCESS)
2133 return ERROR_SUCCESS;
2144 DWORD dwResult =
SetEntriesInAclW(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
2145 if (dwResult == ERROR_SUCCESS)
2147 return ERROR_SUCCESS;
2155template<
class _Traits,
class _Ax>
2156_Success_(
return != 0) BOOL
GetThreadPreferredUILanguages(_In_ DWORD dwFlags, _Out_ PULONG pulNumLanguages, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue)
2159 ULONG ulSize = _countof(szStackBuffer);
2164 sValue.assign(szStackBuffer, ulSize - 1);
2166 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
2171 sValue.resize(ulSize - 1);
Activates given activation context in constructor and deactivates it in destructor.
Definition Win.h:1455
actctx_activator(HANDLE hActCtx) noexcept
Construct the activator and activates the given activation context.
Definition Win.h:1467
virtual ~actctx_activator()
Deactivates activation context and destructs the activator.
Definition Win.h:1478
ULONG_PTR m_cookie
Cookie for context deactivation.
Definition Win.h:1485
Base template class to support string formatting using printf() style templates.
Definition Common.h:1485
Clipboard management.
Definition Win.h:1602
virtual ~clipboard_opener()
Closes the clipboard.
Definition Win.h:1620
clipboard_opener(HWND hWndNewOwner=NULL)
Opens the clipboard for examination and prevents other applications from modifying the clipboard cont...
Definition Win.h:1609
Console control handler stack management.
Definition Win.h:1630
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:1642
virtual ~console_ctrl_handler()
Pops console control handler from the console control handler stack.
Definition Win.h:1652
PHANDLER_ROUTINE m_handler
Pointer to console control handler.
Definition Win.h:1660
BOOL m_cookie
Did pushing the console control handler succeed?
Definition Win.h:1659
Critical section wrapper.
Definition Win.h:1186
critical_section() noexcept
Construct the object and initializes a critical section object.
Definition Win.h:1196
CRITICAL_SECTION m_data
Critical section struct.
Definition Win.h:1222
virtual ~critical_section()
Releases all resources used by an unowned critical section object.
Definition Win.h:1206
Event log handle wrapper.
Definition Win.h:1938
void free_internal() noexcept override
Closes an event log handle.
Definition Win.h:1959
virtual ~event_log()
Closes an event log handle.
Definition Win.h:1947
Find-file handle wrapper.
Definition Win.h:1231
virtual ~find_file()
Closes a file search handle.
Definition Win.h:1240
void free_internal() noexcept override
Closes a file search handle.
Definition Win.h:1252
Base abstract template class to support generic object handle keeping.
Definition Common.h:874
handle_type m_h
Definition Common.h:1126
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1089
LPVOID handle_type
Definition Common.h:879
HeapAlloc allocator.
Definition Win.h:1342
_Ty value_type
A type that is managed by the allocator.
Definition Win.h:1344
heap_allocator(const heap_allocator< _Other > &other)
Constructs allocator from another type.
Definition Win.h:1378
_Ty * pointer
A type that provides a pointer to the type of object managed by the allocator.
Definition Win.h:1346
const _Ty * const_pointer
A type that provides a constant pointer to the type of object managed by the allocator.
Definition Win.h:1348
HANDLE m_heap
Heap handle.
Definition Win.h:1448
pointer allocate(size_type count)
Allocates a new memory block.
Definition Win.h:1388
_Ty & reference
A type that provides a reference to the type of object managed by the allocator.
Definition Win.h:1347
heap_allocator(HANDLE heap)
Constructs allocator.
Definition Win.h:1369
void construct(pointer ptr, _Ty &&val)
Calls moving constructor for the element.
Definition Win.h:1424
void deallocate(pointer ptr, size_type size)
Frees memory block.
Definition Win.h:1400
size_type max_size() const
Returns maximum memory block size.
Definition Win.h:1442
void construct(pointer ptr, const _Ty &val)
Calls copying constructor for the element.
Definition Win.h:1413
const _Ty & const_reference
A type that provides a constant reference to type of object managed by the allocator.
Definition Win.h:1349
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:1351
void destroy(pointer ptr)
Calls destructor for the element.
Definition Win.h:1434
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:1352
Heap handle wrapper.
Definition Win.h:1264
bool enumerate() noexcept
Enumerates allocated heap blocks using OutputDebugString()
Definition Win.h:1286
void free_internal() noexcept override
Destroys the heap.
Definition Win.h:1330
virtual ~heap()
Destroys the heap.
Definition Win.h:1273
Base class for thread impersonation of another security context.
Definition Win.h:1492
virtual ~impersonator()
Reverts to current user and destructs the impersonator.
Definition Win.h:1504
impersonator() noexcept
Construct the impersonator.
Definition Win.h:1497
BOOL m_cookie
Did impersonation succeed?
Definition Win.h:1516
Saves GetLastError and restores SetLastError when going out of scope.
Definition Common.h:1374
Module handle wrapper.
Definition Win.h:1045
void free_internal() noexcept override
Frees the module.
Definition Win.h:1066
virtual ~library()
Frees the module.
Definition Win.h:1054
Locks given mutex in constructor and releases it in destructor.
Definition Win.h:1104
virtual ~mutex_locker()
Releases ownership of the mutex object.
Definition Win.h:1135
mutex_locker(HANDLE hMutex, DWORD dwMilliseconds=INFINITE)
Waits until the specified mutex is in the signaled state or the time-out interval elapses.
Definition Win.h:1117
Registry key wrapper class.
Definition Win.h:1785
void free_internal() noexcept override
Closes a handle to the registry key.
Definition Win.h:1857
bool delete_subkey(LPCTSTR szSubkey)
Deletes the specified registry subkey.
Definition Win.h:1809
virtual ~reg_key()
Closes a handle to the registry key.
Definition Win.h:1794
SC_HANDLE wrapper class.
Definition Win.h:1969
void free_internal() noexcept override
Closes an open object handle.
Definition Win.h:1990
virtual ~sc_handle()
Closes an open object handle.
Definition Win.h:1978
SID wrapper class.
Definition Win.h:1867
void free_internal() noexcept override
Closes a handle to the SID.
Definition Win.h:1888
virtual ~security_id()
Closes a handle to the SID.
Definition Win.h:1876
Lets the calling thread impersonate the security context of the SYSTEM user.
Definition Win.h:1545
system_impersonator() noexcept
Construct the impersonator and impersonates the SYSTEM user.
Definition Win.h:1553
Lets the calling thread impersonate the security context of a logged-on user.
Definition Win.h:1523
user_impersonator(HANDLE hToken) noexcept
Construct the impersonator and impersonates the given user.
Definition Win.h:1535
Memory in virtual address space of a process handle wrapper.
Definition Win.h:1667
vmemory & operator=(vmemory &&other) noexcept
Move assignment.
Definition Win.h:1714
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:1748
void free_internal() noexcept override
Frees the memory.
Definition Win.h:1769
void attach(HANDLE proc, handle_type h) noexcept
Sets a new memory handle for the class.
Definition Win.h:1731
virtual ~vmemory()
Frees the memory.
Definition Win.h:1703
vmemory(handle_type h, HANDLE proc) noexcept
Initializes a new class instance with an already available object handle.
Definition Win.h:1683
vmemory() noexcept
Initializes a new class instance with the memory handle set to INVAL.
Definition Win.h:1674
vmemory(vmemory &&h) noexcept
Move constructor.
Definition Win.h:1693
HANDLE m_proc
Handle of memory's process.
Definition Win.h:1775
Windows HANDLE wrapper class.
Definition Win.h:1012
void free_internal() noexcept override
Closes an open object handle.
Definition Win.h:1033
virtual ~win_handle()
Closes an open object handle.
Definition Win.h:1021
Windows runtime error.
Definition Common.h:1403
#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
Definition Common.h:884
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:627
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:192
static BOOL StringToGuidA(LPCSTR lpszGuid, LPGUID lpGuid, LPCSTR *lpszGuidEnd=NULL) noexcept
Parses string with GUID and stores it to GUID.
Definition Win.h:255
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:2029
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:707
win_handle< INVALID_HANDLE_VALUE > file
File handle wrapper.
Definition Win.h:1150
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:126
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:2006
static LSTATUS RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, winstd::reg_key &result)
Opens the specified registry key.
Definition Win.h:2048
static LSTATUS RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, winstd::reg_key &result)
Opens the specified registry key.
Definition Win.h:2067
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:216
static BOOL StringToGuidW(LPCWSTR lpszGuid, LPGUID lpGuid, LPCWSTR *lpszGuidEnd=NULL) noexcept
Parses string with GUID and stores it to GUID.
Definition Win.h:328
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:597
static BOOL OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, winstd::win_handle< NULL > &TokenHandle)
Opens the access token associated with a process.
Definition Win.h:2086
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:2141
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:821
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:860
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:2116
win_handle< INVALID_HANDLE_VALUE > process_snapshot
Process snapshot handle wrapper.
Definition Win.h:1091
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:807
static BOOL CreateWellKnownSid(WELL_KNOWN_SID_TYPE WellKnownSidType, PSID DomainSid, std::unique_ptr< SID > &Sid)
Creates a SID for predefined aliases.
Definition Win.h:898
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:725
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:922
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:2101
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:2127
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:558
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:146
win_handle< NULL > event
Event handle wrapper.
Definition Win.h:1180
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:583
static VOID OutputDebugStr(LPCSTR lpOutputString,...) noexcept
Formats and sends a string to the debugger for display.
Definition Win.h:766
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:946
win_handle< NULL > mutex
Mutex handle wrapper.
Definition Win.h:1098
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:162
win_handle< NULL > file_mapping
File mapping.
Definition Win.h:1157
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:975
win_handle< NULL > process
Process handle wrapper.
Definition Win.h:1077
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:531
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:2156
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:416
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:106
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:789
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:235
static VOID OutputDebugStrV(LPCSTR lpOutputString, va_list arg) noexcept
Formats and sends a string to the debugger for display.
Definition Win.h:742
win_handle< NULL > thread
Thread handle wrapper.
Definition Win.h:1084
Deleter for unique_ptr using LocalFree.
Definition Common.h:739
Deleter for unique_ptr using UnmapViewOfFile.
Definition Win.h:1163
void operator()(void *_Ptr) const
Delete a pointer.
Definition Win.h:1167
A structure that enables an allocator for objects of one type to allocate storage for objects of anot...
Definition Win.h:1359
heap_allocator< _Other > other
Other allocator type.
Definition Win.h:1360