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>
180static _Success_(
return != 0) DWORD
ExpandEnvironmentStringsA(_In_z_ LPCSTR lpSrc, _Out_ std::basic_string<
char, _Traits, _Ax> &sValue) noexcept
184 for (DWORD dwSizeOut = (DWORD)strlen(lpSrc) + 0x100;;) {
185 DWORD dwSizeIn = dwSizeOut;
186 std::unique_ptr<char[]> szBuffer(
new char[(
size_t)dwSizeIn + 2]);
188 if (dwSizeOut == 0) {
191 }
else if (dwSizeOut <= dwSizeIn) {
193 sValue.assign(szBuffer.get(), dwSizeOut - 1);
207template<
class _Traits,
class _Ax>
208static _Success_(
return != 0) DWORD
ExpandEnvironmentStringsW(_In_z_ LPCWSTR lpSrc, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue) noexcept
210 for (DWORD dwSizeOut = (DWORD)wcslen(lpSrc) + 0x100;;) {
211 DWORD dwSizeIn = dwSizeOut;
212 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[(
size_t)dwSizeIn + 1]);
214 if (dwSizeOut == 0) {
217 }
else if (dwSizeOut <= dwSizeIn) {
219 sValue.assign(szBuffer.get(), dwSizeOut - 1);
229template<
class _Traits,
class _Ax>
230static VOID
GuidToStringA(_In_ LPCGUID lpGuid, _Out_ std::basic_string<char, _Traits, _Ax> &str)
noexcept
234 sprintf(str,
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
238 lpGuid->Data4[0], lpGuid->Data4[1],
239 lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
248template<
class _Traits,
class _Ax>
249static VOID
GuidToStringW(_In_ LPCGUID lpGuid, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &str)
noexcept
253 sprintf(str, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
257 lpGuid->Data4[0], lpGuid->Data4[1],
258 lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4], lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
263#define GuidToString GuidToStringW
265#define GuidToString GuidToStringA
269static _Success_(
return) BOOL
StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd = NULL)
noexcept
274 unsigned long long ullTmp;
276 if (!lpszGuid || !lpGuid || *lpszGuid !=
'{')
return FALSE;
279 g.Data1 = strtoul(lpszGuid, &lpszEnd, 16);
280 if (errno == ERANGE)
return FALSE;
283 if (*lpszGuid !=
'-')
return FALSE;
286 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
287 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
288 g.Data2 =
static_cast<unsigned short>(ulTmp);
291 if (*lpszGuid !=
'-')
return FALSE;
294 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
295 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
296 g.Data3 =
static_cast<unsigned short>(ulTmp);
299 if (*lpszGuid !=
'-')
return FALSE;
302 ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
303 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
304 g.Data4[0] =
static_cast<unsigned char>((ulTmp >> 8) & 0xff);
305 g.Data4[1] =
static_cast<unsigned char>( ulTmp & 0xff);
308 if (*lpszGuid !=
'-')
return FALSE;
311 ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
312 if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF)
return FALSE;
313 g.Data4[2] =
static_cast<unsigned char>((ullTmp >> 40) & 0xff);
314 g.Data4[3] =
static_cast<unsigned char>((ullTmp >> 32) & 0xff);
315 g.Data4[4] =
static_cast<unsigned char>((ullTmp >> 24) & 0xff);
316 g.Data4[5] =
static_cast<unsigned char>((ullTmp >> 16) & 0xff);
317 g.Data4[6] =
static_cast<unsigned char>((ullTmp >> 8) & 0xff);
318 g.Data4[7] =
static_cast<unsigned char>( ullTmp & 0xff);
321 if (*lpszGuid !=
'}')
return FALSE;
325 *lpszGuidEnd = lpszGuid;
342static _Success_(
return) BOOL
StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd = NULL)
noexcept
347 unsigned long long ullTmp;
349 if (!lpszGuid || !lpGuid || *lpszGuid !=
'{')
return FALSE;
352 g.Data1 = wcstoul(lpszGuid, &lpszEnd, 16);
353 if (errno == ERANGE)
return FALSE;
356 if (*lpszGuid !=
'-')
return FALSE;
359 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
360 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
361 g.Data2 =
static_cast<unsigned short>(ulTmp);
364 if (*lpszGuid !=
'-')
return FALSE;
367 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
368 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
369 g.Data3 =
static_cast<unsigned short>(ulTmp);
372 if (*lpszGuid !=
'-')
return FALSE;
375 ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
376 if (errno == ERANGE || ulTmp > 0xFFFF)
return FALSE;
377 g.Data4[0] =
static_cast<unsigned char>((ulTmp >> 8) & 0xff);
378 g.Data4[1] =
static_cast<unsigned char>( ulTmp & 0xff);
381 if (*lpszGuid !=
'-')
return FALSE;
384 ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
385 if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF)
return FALSE;
386 g.Data4[2] =
static_cast<unsigned char>((ullTmp >> 40) & 0xff);
387 g.Data4[3] =
static_cast<unsigned char>((ullTmp >> 32) & 0xff);
388 g.Data4[4] =
static_cast<unsigned char>((ullTmp >> 24) & 0xff);
389 g.Data4[5] =
static_cast<unsigned char>((ullTmp >> 16) & 0xff);
390 g.Data4[6] =
static_cast<unsigned char>((ullTmp >> 8) & 0xff);
391 g.Data4[7] =
static_cast<unsigned char>( ullTmp & 0xff);
394 if (*lpszGuid !=
'}')
return FALSE;
398 *lpszGuidEnd = lpszGuid;
406#define StringToGuid StringToGuidW
408#define StringToGuid StringToGuidA
429template<
class _Traits,
class _Ax>
430static LSTATUS
RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_ std::basic_string<char, _Traits, _Ax> &sValue)
noexcept
434 DWORD dwSize =
sizeof(aStackBuffer), dwType;
438 if (lResult == ERROR_SUCCESS) {
439 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
441 dwSize /=
sizeof(CHAR);
442 sValue.assign(
reinterpret_cast<LPCSTR
>(aStackBuffer), dwSize &&
reinterpret_cast<LPCSTR
>(aStackBuffer)[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
443 }
else if (dwType == REG_EXPAND_SZ) {
446 lResult = ::GetLastError();
449 lResult = ERROR_INVALID_DATA;
451 }
else if (lResult == ERROR_MORE_DATA) {
452 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
454 std::unique_ptr<CHAR[]> szBuffer(
new CHAR[dwSize /
sizeof(CHAR)]);
455 if ((lResult =
::RegQueryValueExA(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
456 dwSize /=
sizeof(CHAR);
457 sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
459 }
else if (dwType == REG_EXPAND_SZ) {
461 std::unique_ptr<CHAR[]> szBuffer(
new CHAR[dwSize /
sizeof(CHAR)]);
462 if ((lResult =
::RegQueryValueExA(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
464 lResult = ::GetLastError();
468 lResult = ERROR_INVALID_DATA;
493template<
class _Traits,
class _Ax>
494static LSTATUS
RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
noexcept
498 DWORD dwSize =
sizeof(aStackBuffer), dwType;
502 if (lResult == ERROR_SUCCESS) {
503 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
505 dwSize /=
sizeof(WCHAR);
506 sValue.assign(
reinterpret_cast<LPCWSTR
>(aStackBuffer), dwSize &&
reinterpret_cast<LPCWSTR
>(aStackBuffer)[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
507 }
else if (dwType == REG_EXPAND_SZ) {
510 lResult = ::GetLastError();
513 lResult = ERROR_INVALID_DATA;
515 }
else if (lResult == ERROR_MORE_DATA) {
516 if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
518 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[dwSize /
sizeof(WCHAR)]);
519 if ((lResult =
::RegQueryValueExW(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
520 dwSize /=
sizeof(WCHAR);
521 sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
523 }
else if (dwType == REG_EXPAND_SZ) {
525 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[dwSize /
sizeof(WCHAR)]);
526 if ((lResult =
::RegQueryValueExW(hReg, pszName, NULL, NULL,
reinterpret_cast<LPBYTE
>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
528 lResult = ::GetLastError();
532 lResult = ERROR_INVALID_DATA;
540template<
class _Ty,
class _Ax>
541static LSTATUS
RegQueryValueExA(_In_ HKEY hKey, _In_opt_z_ LPCSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData)
noexcept
545 DWORD dwSize =
sizeof(aStackBuffer);
548 lResult =
RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, aStackBuffer, &dwSize);
549 if (lResult == ERROR_SUCCESS) {
551 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
552 memcpy(aData.data(), aStackBuffer, dwSize);
553 }
else if (lResult == ERROR_MORE_DATA) {
555 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
556 lResult =
RegQueryValueExA(hKey, lpValueName, lpReserved, NULL,
reinterpret_cast<LPBYTE
>(aData.data()), &dwSize);
567template<
class _Ty,
class _Ax>
568static LSTATUS
RegQueryValueExW(_In_ HKEY hKey, _In_opt_z_ LPCWSTR lpValueName, __reserved LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ std::vector<_Ty, _Ax> &aData)
noexcept
572 DWORD dwSize =
sizeof(aStackBuffer);
575 lResult =
RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, aStackBuffer, &dwSize);
576 if (lResult == ERROR_SUCCESS) {
578 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
579 memcpy(aData.data(), aStackBuffer, dwSize);
580 }
else if (lResult == ERROR_MORE_DATA) {
582 aData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
583 lResult =
RegQueryValueExW(hKey, lpValueName, lpReserved, NULL,
reinterpret_cast<LPBYTE
>(aData.data()), &dwSize);
589#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
592template<
class _Traits,
class _Ax>
593static 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
598 return ERROR_CALL_NOT_IMPLEMENTED;
606template<
class _Traits,
class _Ax>
607static 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
613 Flags &= ~REG_MUI_STRING_TRUNCATE;
616 lResult =
RegLoadMUIStringW(hKey, pszValue, szStackBuffer,
sizeof(szStackBuffer), &dwSize, Flags, pszDirectory);
617 if (lResult == ERROR_SUCCESS) {
619 sOut.assign(szStackBuffer, wcsnlen(szStackBuffer, dwSize/
sizeof(
wchar_t)));
620 }
else if (lResult == ERROR_MORE_DATA) {
622 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[(dwSize +
sizeof(
wchar_t) - 1)/
sizeof(
wchar_t)]);
623 sOut.assign(szBuffer.get(), (lResult =
RegLoadMUIStringW(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? wcsnlen(szBuffer.get(), dwSize/
sizeof(
wchar_t)) : 0);
636template<
class _Traits,
class _Ax>
637static _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
642 int cch =
::NormalizeString(NormForm, lpSrcString, cwSrcLength, szStackBuffer, _countof(szStackBuffer));
645 sDstString.assign(szStackBuffer, cwSrcLength != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
647 switch (::GetLastError()) {
648 case ERROR_INSUFFICIENT_BUFFER:
649 for (
int i = 10; i--;) {
652 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[cch]);
653 cch =
::NormalizeString(NormForm, lpSrcString, cwSrcLength, szBuffer.get(), cch);
655 sDstString.assign(szBuffer.get(), cwSrcLength != -1 ? wcsnlen(szStackBuffer, cch) : (size_t)cch - 1);
658 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
679template<
class _Traits1,
class _Ax1,
class _Traits2,
class _Ax2>
680static _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
685 int cch =
::NormalizeString(NormForm, sSrcString.c_str(), (
int)sSrcString.length(), szStackBuffer, _countof(szStackBuffer));
688 sDstString.assign(szStackBuffer, cch);
690 switch (::GetLastError()) {
691 case ERROR_INSUFFICIENT_BUFFER:
692 for (
int i = 10; i--;) {
695 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[cch]);
696 cch =
::NormalizeString(NormForm, sSrcString.c_str(), (
int)sSrcString.length(), szBuffer.get(), cch);
698 sDstString.assign(szBuffer.get(), cch);
701 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
718template<
class _Traits,
class _Ax>
719static _Success_(
return != 0) int WINAPI
LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string<
char, _Traits, _Ax> &sBuffer) noexcept
723 int i =
LoadStringA(hInstance, uID,
reinterpret_cast<LPSTR
>(&pszStr), 0);
725 sBuffer.assign(pszStr, i);
736template<
class _Traits,
class _Ax>
737static _Success_(
return != 0) int WINAPI
LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sBuffer) noexcept
741 int i =
LoadStringW(hInstance, uID,
reinterpret_cast<LPWSTR
>(&pszStr), 0);
743 sBuffer.assign(pszStr, i);
757 try {
vsprintf(str, lpOutputString, arg); }
catch (...) {
return; }
758 OutputDebugStringA(str.c_str());
769 try {
vsprintf(str, lpOutputString, arg); }
catch (...) {
return; }
770 OutputDebugStringW(str.c_str());
781 va_start(arg, lpOutputString);
794 va_start(arg, lpOutputString);
800template<
class _Traits,
class _Ax>
801static _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
803 int iResult =
GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
806 std::unique_ptr<char[]> szBuffer(
new char[iResult]);
807 iResult =
GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
808 sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
820template<
class _Traits,
class _Ax>
821static _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
823 int iResult =
GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
826 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[iResult]);
827 iResult =
GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
828 sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
836template<
class _Traits,
class _Ax>
837static _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
841 DWORD dwNameLen = 0, dwRefDomainLen = 0;
845 NULL, &dwRefDomainLen,
849 if (sName ) sName ->clear();
850 if (sReferencedDomainName) sReferencedDomainName->clear();
852 }
else if (GetLastError() == ERROR_MORE_DATA) {
854 std::unique_ptr<char[]> bufName (
new char[dwNameLen ]);
855 std::unique_ptr<char[]> bufRefDomain(
new char[dwRefDomainLen]);
857 bufName .get(), &dwNameLen ,
858 bufRefDomain.get(), &dwRefDomainLen,
861 if (sName ) sName ->assign(bufName .get(), dwNameLen - 1);
862 if (sReferencedDomainName) sReferencedDomainName->assign(bufRefDomain.get(), dwRefDomainLen - 1);
875template<
class _Traits,
class _Ax>
876static _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
880 DWORD dwNameLen = 0, dwRefDomainLen = 0;
884 NULL, &dwRefDomainLen,
888 if (sName ) sName ->clear();
889 if (sReferencedDomainName) sReferencedDomainName->clear();
891 }
else if (GetLastError() == ERROR_MORE_DATA) {
893 std::unique_ptr<wchar_t[]> bufName (
new wchar_t[dwNameLen ]);
894 std::unique_ptr<wchar_t[]> bufRefDomain(
new wchar_t[dwRefDomainLen]);
896 bufName .get(), &dwNameLen ,
897 bufRefDomain.get(), &dwRefDomainLen,
900 if (sName ) sName ->assign(bufName .get(), dwNameLen - 1);
901 if (sReferencedDomainName) sReferencedDomainName->assign(bufRefDomain.get(), dwRefDomainLen - 1);
914static _Success_(
return != FALSE) BOOL
CreateWellKnownSid(_In_ WELL_KNOWN_SID_TYPE WellKnownSidType, _In_opt_ PSID DomainSid, _Inout_ std::unique_ptr<SID> &Sid)
917 DWORD dwSize =
sizeof(szStackBuffer);
921 Sid.reset((SID*)
new BYTE[dwSize]);
922 memcpy(Sid.get(), szStackBuffer, dwSize);
924 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
926 Sid.reset((SID*)
new BYTE[dwSize]);
938static _Success_(
return != 0) BOOL
GetTokenInformation(_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_ std::unique_ptr<_Ty> &TokenInformation) noexcept
943 if (
GetTokenInformation(TokenHandle, TokenInformationClass, szStackBuffer,
sizeof(szStackBuffer), &dwSize)) {
945 TokenInformation.reset((_Ty*)(
new BYTE[dwSize]));
946 memcpy(TokenInformation.get(), szStackBuffer, dwSize);
948 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
950 TokenInformation.reset((_Ty*)(
new BYTE[dwSize]));
951 return GetTokenInformation(TokenHandle, TokenInformationClass, TokenInformation.get(), dwSize, &dwSize);
961template<
class _Traits,
class _Ax>
962static _Success_(
return != 0) BOOL
QueryFullProcessImageNameA(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<
char, _Traits, _Ax>& sExeName)
965 DWORD dwSize = _countof(szStackBuffer);
970 sExeName.assign(szStackBuffer, dwSize);
973 for (DWORD dwCapacity = 2 *
WINSTD_STACK_BUFFER_BYTES /
sizeof(
char); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
975 std::unique_ptr<char[]> szBuffer(
new char[dwCapacity]);
978 sExeName.assign(szBuffer.get(), dwSize);
990template<
class _Traits,
class _Ax>
991static _Success_(
return != 0) BOOL
QueryFullProcessImageNameW(_In_ HANDLE hProcess, _In_ DWORD dwFlags, _Inout_ std::basic_string<
wchar_t, _Traits, _Ax>& sExeName)
994 DWORD dwSize = _countof(szStackBuffer);
999 sExeName.assign(szStackBuffer, dwSize);
1002 for (DWORD dwCapacity = 2 *
WINSTD_STACK_BUFFER_BYTES /
sizeof(
wchar_t); GetLastError() == ERROR_INSUFFICIENT_BUFFER; dwCapacity *= 2) {
1004 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[dwCapacity]);
1005 dwSize = dwCapacity;
1007 sExeName.assign(szBuffer.get(), dwSize);
1026 template<HANDLE INVALID>
1153 if (!UnmapViewOfFile(_Ptr))
1175 if (!UnmapViewOfFile(_Ptr))
1182 template<
class _Other>
1185 if (!UnmapViewOfFile(_Ptr))
1214 InitializeCriticalSection(&
m_data);
1224 DeleteCriticalSection(&
m_data);
1232 operator LPCRITICAL_SECTION() noexcept
1311 PROCESS_HEAP_ENTRY e;
1313 while (HeapWalk(
m_h, &e) != FALSE) {
1314 if ((e.wFlags & PROCESS_HEAP_ENTRY_BUSY) != 0) {
1316 _T(
"Allocated block%s%s\n")
1317 _T(
" Data portion begins at: %#p\n Size: %d bytes\n")
1318 _T(
" Overhead: %d bytes\n Region index: %d\n"),
1319 (e.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) != 0 ?
tstring_printf(_T(
", movable with HANDLE %#p"), e.Block.hMem).c_str() : _T(
""),
1320 (e.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) != 0 ? _T(
", DDESHARE") : _T(
""),
1330 const DWORD dwResult = GetLastError();
1331 if (dwResult != ERROR_NO_MORE_ITEMS)
1356 template <
class _Ty>
1373 template <
class _Other>
1394 template <
class _Other>
1420 UNREFERENCED_PARAMETER(size);
1422 HeapFree(
m_heap, 0, ptr);
1433 ::new ((
void*)ptr) _Ty(val);
1444 ::new ((
void*)ptr) _Ty(std::forward<_Ty>(val));
1487 if (!ActivateActCtx(hActCtx, &
m_cookie))
1555 m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
1573 TOKEN_PRIVILEGES privileges = { 1, {{{ 0, 0 }, SE_PRIVILEGE_ENABLED }} };
1574 if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &privileges.Privileges[0].Luid) ||
1575 !ImpersonateSelf(SecurityImpersonation))
1580 if (!OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES, FALSE, &h))
1583 if (!AdjustTokenPrivileges(thread_token, FALSE, &privileges,
sizeof(privileges), NULL, NULL))
1588 PROCESSENTRY32 entry = {
sizeof(PROCESSENTRY32) };
1591 while (_tcsicmp(entry.szExeFile, TEXT(
"winlogon.exe")) != 0)
1594 process winlogon_process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, entry.th32ProcessID);
1595 if (!winlogon_process)
1597 if (!
OpenProcessToken(winlogon_process, TOKEN_IMPERSONATE | TOKEN_DUPLICATE, &h))
1600 if (!DuplicateToken(winlogon_token, SecurityImpersonation, &h))
1603 if (!SetThreadToken(NULL, duplicated_token))
1611 DWORD dwResult = GetLastError();
1613 SetLastError(dwResult);
1630 if (!OpenClipboard(hWndNewOwner))
1674 SetConsoleCtrlHandler(
m_handler, FALSE);
1715 m_proc(std::move(h.m_proc)),
1728 VirtualFreeEx(
m_proc,
m_h, 0, MEM_RELEASE);
1738 if (
this != std::addressof(other)) {
1740 m_proc = std::move(other.m_proc);
1771 _In_ HANDLE hProcess,
1772 _In_opt_ LPVOID lpAddress,
1774 _In_ DWORD flAllocationType,
1775 _In_ DWORD flProtect)
noexcept
1777 handle_type h = VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect);
1793 VirtualFreeEx(
m_proc,
m_h, 0, MEM_RELEASE);
1835 s = RegDeleteKey(
m_h, szSubkey);
1836 if (s == ERROR_SUCCESS || s == ERROR_FILE_NOT_FOUND)
1842 s = RegOpenKeyEx(
m_h, szSubkey, 0, KEY_ENUMERATE_SUB_KEYS, &h);
1843 if (s == ERROR_SUCCESS)
1850 TCHAR szName[MAX_PATH];
1851 DWORD dwSize = _countof(szName);
1852 s = RegEnumKeyEx(k, 0, szName, &dwSize, NULL, NULL, NULL, NULL);
1853 if (s == ERROR_SUCCESS)
1855 else if (s == ERROR_NO_MORE_ITEMS)
1864 s = RegDeleteKey(
m_h, szSubkey);
1865 if (s == ERROR_SUCCESS)
1930 hProcess = INVALID_HANDLE_VALUE;
1931 hThread = INVALID_HANDLE_VALUE;
1941 #pragma warning(push)
1942 #pragma warning(disable: 6001)
1944 if (hProcess != INVALID_HANDLE_VALUE)
1945 CloseHandle(hProcess);
1947 if (hThread != INVALID_HANDLE_VALUE)
1948 CloseHandle(hThread);
1950 #pragma warning(pop)
1983 DeregisterEventSource(
m_h);
2014 CloseServiceHandle(
m_h);
2024#pragma warning(push)
2025#pragma warning(disable: 4505)
2030 _In_ LPCSTR lpSubKey,
2031 _Reserved_ DWORD Reserved,
2032 _In_opt_ LPSTR lpClass,
2033 _In_ DWORD dwOptions,
2034 _In_ REGSAM samDesired,
2035 _In_opt_ CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2037 _Out_opt_ LPDWORD lpdwDisposition)
2040 LSTATUS s =
RegCreateKeyExA(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition);
2041 if (s == ERROR_SUCCESS)
2053 _In_ LPCWSTR lpSubKey,
2054 _Reserved_ DWORD Reserved,
2055 _In_opt_ LPWSTR lpClass,
2056 _In_ DWORD dwOptions,
2057 _In_ REGSAM samDesired,
2058 _In_opt_ CONST LPSECURITY_ATTRIBUTES lpSecurityAttributes,
2060 _Out_opt_ LPDWORD lpdwDisposition)
2063 LSTATUS s =
RegCreateKeyExW(hKey, lpSubKey, Reserved, lpClass, dwOptions, samDesired, lpSecurityAttributes, &h, lpdwDisposition);
2064 if (s == ERROR_SUCCESS)
2072 _In_opt_ LPCSTR lpSubKey,
2073 _In_opt_ DWORD ulOptions,
2074 _In_ REGSAM samDesired,
2078 LSTATUS s =
RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, &h);
2079 if (s == ERROR_SUCCESS)
2091 _In_opt_ LPCWSTR lpSubKey,
2092 _In_opt_ DWORD ulOptions,
2093 _In_ REGSAM samDesired,
2097 LSTATUS s =
RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, &h);
2098 if (s == ERROR_SUCCESS)
2112 TokenHandle.attach(h);
2123static 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)
2126 if (
DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, &h)) {
2138static 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)
2141 if (
AllocateAndInitializeSid(pIdentifierAuthority, nSubAuthorityCount, nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3, nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, &h)) {
2152 DWORD dwResult =
SetEntriesInAclA(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
2153 if (dwResult == ERROR_SUCCESS)
2155 return ERROR_SUCCESS;
2166 DWORD dwResult =
SetEntriesInAclW(cCountOfExplicitEntries, pListOfExplicitEntries, OldAcl, &h);
2167 if (dwResult == ERROR_SUCCESS)
2169 return ERROR_SUCCESS;
2177template<
class _Traits,
class _Ax>
2178_Success_(
return != 0) BOOL
GetThreadPreferredUILanguages(_In_ DWORD dwFlags, _Out_ PULONG pulNumLanguages, _Out_ std::basic_string<
wchar_t, _Traits, _Ax> &sValue)
2181 ULONG ulSize = _countof(szStackBuffer);
2186 sValue.assign(szStackBuffer, ulSize - 1);
2188 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
2193 std::unique_ptr<WCHAR[]> szBuffer(
new WCHAR[ulSize]);
2195 sValue.assign(szBuffer.get(), ulSize - 1);
Activates given activation context in constructor and deactivates it in destructor.
Definition Win.h:1473
actctx_activator(HANDLE hActCtx) noexcept
Construct the activator and activates the given activation context.
Definition Win.h:1485
virtual ~actctx_activator()
Deactivates activation context and destructs the activator.
Definition Win.h:1496
ULONG_PTR m_cookie
Cookie for context deactivation.
Definition Win.h:1503
Base template class to support string formatting using printf() style templates.
Definition Common.h:1504
Clipboard management.
Definition Win.h:1621
virtual ~clipboard_opener()
Closes the clipboard.
Definition Win.h:1639
clipboard_opener(HWND hWndNewOwner=NULL)
Opens the clipboard for examination and prevents other applications from modifying the clipboard cont...
Definition Win.h:1628
Console control handler stack management.
Definition Win.h:1649
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:1661
virtual ~console_ctrl_handler()
Pops console control handler from the console control handler stack.
Definition Win.h:1671
PHANDLER_ROUTINE m_handler
Pointer to console control handler.
Definition Win.h:1679
BOOL m_cookie
Did pushing the console control handler succeed?
Definition Win.h:1678
Critical section wrapper.
Definition Win.h:1202
critical_section() noexcept
Construct the object and initializes a critical section object.
Definition Win.h:1212
CRITICAL_SECTION m_data
Critical section struct.
Definition Win.h:1238
virtual ~critical_section()
Releases all resources used by an unowned critical section object.
Definition Win.h:1222
Event log handle wrapper.
Definition Win.h:1960
void free_internal() noexcept override
Closes an event log handle.
Definition Win.h:1981
virtual ~event_log()
Closes an event log handle.
Definition Win.h:1969
Find-file handle wrapper.
Definition Win.h:1247
virtual ~find_file()
Closes a file search handle.
Definition Win.h:1256
void free_internal() noexcept override
Closes a file search handle.
Definition Win.h:1268
Base abstract template class to support generic object handle keeping.
Definition Common.h:983
LPVOID handle_type
Datatype of the object handle this template class handles.
Definition Common.h:988
handle_type m_h
Object handle.
Definition Common.h:1237
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1200
HeapAlloc allocator.
Definition Win.h:1358
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:1367
_Ty value_type
A type that is managed by the allocator.
Definition Win.h:1360
heap_allocator(const heap_allocator< _Other > &other)
Constructs allocator from another type.
Definition Win.h:1395
HANDLE m_heap
Heap handle.
Definition Win.h:1466
pointer allocate(size_type count)
Allocates a new memory block.
Definition Win.h:1406
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:1368
heap_allocator(HANDLE heap)
Constructs allocator.
Definition Win.h:1385
_Ty & reference
A type that provides a reference to the type of object managed by the allocator.
Definition Win.h:1363
void construct(pointer ptr, _Ty &&val)
Calls moving constructor for the element.
Definition Win.h:1442
void deallocate(pointer ptr, size_type size)
Frees memory block.
Definition Win.h:1418
size_type max_size() const
Returns maximum memory block size.
Definition Win.h:1460
void construct(pointer ptr, const _Ty &val)
Calls copying constructor for the element.
Definition Win.h:1431
const _Ty & const_reference
A type that provides a constant reference to type of object managed by the allocator.
Definition Win.h:1365
const _Ty * const_pointer
A type that provides a constant pointer to the type of object managed by the allocator.
Definition Win.h:1364
_Ty * pointer
A type that provides a pointer to the type of object managed by the allocator.
Definition Win.h:1362
void destroy(pointer ptr)
Calls destructor for the element.
Definition Win.h:1452
Heap handle wrapper.
Definition Win.h:1280
bool enumerate() noexcept
Enumerates allocated heap blocks using OutputDebugString()
Definition Win.h:1302
void free_internal() noexcept override
Destroys the heap.
Definition Win.h:1346
virtual ~heap()
Destroys the heap.
Definition Win.h:1289
Base class for thread impersonation of another security context.
Definition Win.h:1510
virtual ~impersonator()
Reverts to current user and destructs the impersonator.
Definition Win.h:1522
impersonator() noexcept
Construct the impersonator.
Definition Win.h:1515
BOOL m_cookie
Did impersonation succeed?
Definition Win.h:1534
Module handle wrapper.
Definition Win.h:1061
void free_internal() noexcept override
Frees the module.
Definition Win.h:1082
virtual ~library()
Frees the module.
Definition Win.h:1070
Registry key wrapper class.
Definition Win.h:1807
void free_internal() noexcept override
Closes a handle to the registry key.
Definition Win.h:1879
bool delete_subkey(LPCTSTR szSubkey)
Deletes the specified registry subkey.
Definition Win.h:1831
virtual ~reg_key()
Closes a handle to the registry key.
Definition Win.h:1816
SC_HANDLE wrapper class.
Definition Win.h:1991
void free_internal() noexcept override
Closes an open object handle.
Definition Win.h:2012
virtual ~sc_handle()
Closes an open object handle.
Definition Win.h:2000
SID wrapper class.
Definition Win.h:1889
void free_internal() noexcept override
Closes a handle to the SID.
Definition Win.h:1910
virtual ~security_id()
Closes a handle to the SID.
Definition Win.h:1898
Lets the calling thread impersonate the security context of the SYSTEM user.
Definition Win.h:1563
system_impersonator() noexcept
Construct the impersonator and impersonates the SYSTEM user.
Definition Win.h:1571
Lets the calling thread impersonate the security context of a logged-on user.
Definition Win.h:1541
user_impersonator(HANDLE hToken) noexcept
Construct the impersonator and impersonates the given user.
Definition Win.h:1553
Memory in virtual address space of a process handle wrapper.
Definition Win.h:1686
vmemory & operator=(vmemory &&other) noexcept
Move assignment.
Definition Win.h:1736
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:1770
void free_internal() noexcept override
Frees the memory.
Definition Win.h:1791
void attach(HANDLE proc, handle_type h) noexcept
Sets a new memory handle for the class.
Definition Win.h:1753
virtual ~vmemory()
Frees the memory.
Definition Win.h:1725
vmemory(handle_type h, HANDLE proc) noexcept
Initializes a new class instance with an already available object handle.
Definition Win.h:1703
vmemory() noexcept
Initializes a new class instance with the memory handle set to INVAL.
Definition Win.h:1693
vmemory(vmemory &&h) noexcept
Move constructor.
Definition Win.h:1714
HANDLE m_proc
Handle of memory's process.
Definition Win.h:1797
Windows HANDLE wrapper class.
Definition Win.h:1028
void free_internal() noexcept override
Closes an open object handle.
Definition Win.h:1049
virtual ~win_handle()
Closes an open object handle.
Definition Win.h:1037
Windows runtime error.
Definition Common.h:1422
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:66
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition Common.h:93
#define WINSTD_NONMOVABLE(C)
Declares a class as non-movable.
Definition Common.h:74
#define WINSTD_HANDLE_IMPL(C, INVAL)
Implements default constructors and operators to prevent their auto-generation by compiler.
Definition Common.h:163
static const HANDLE invalid
Invalid handle value.
Definition Common.h:993
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:637
static DWORD ExpandEnvironmentStringsA(LPCSTR lpSrc, std::basic_string< char, _Traits, _Ax > &sValue) noexcept
Expands environment-variable strings, replaces them with the values defined for the current user,...
Definition Win.h:180
static BOOL StringToGuidA(LPCSTR lpszGuid, LPGUID lpGuid, LPCSTR *lpszGuidEnd=NULL) noexcept
Parses string with GUID and stores it to GUID.
Definition Win.h:269
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:2051
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:719
win_handle< INVALID_HANDLE_VALUE > file
File handle wrapper.
Definition Win.h:1122
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:2028
static LSTATUS RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, winstd::reg_key &result)
Opens the specified registry key.
Definition Win.h:2070
static LSTATUS RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, winstd::reg_key &result)
Opens the specified registry key.
Definition Win.h:2089
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:230
static BOOL StringToGuidW(LPCWSTR lpszGuid, LPGUID lpGuid, LPCWSTR *lpszGuidEnd=NULL) noexcept
Parses string with GUID and stores it to GUID.
Definition Win.h:342
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:607
static BOOL OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, winstd::win_handle< NULL > &TokenHandle)
Opens the access token associated with a process.
Definition Win.h:2108
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:2163
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:837
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:876
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:2138
win_handle< INVALID_HANDLE_VALUE > process_snapshot
Process snapshot handle wrapper.
Definition Win.h:1107
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:821
static BOOL CreateWellKnownSid(WELL_KNOWN_SID_TYPE WellKnownSidType, PSID DomainSid, std::unique_ptr< SID > &Sid)
Creates a SID for predefined aliases.
Definition Win.h:914
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:737
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:938
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:2123
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:2149
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:568
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:1196
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:593
static VOID OutputDebugStr(LPCSTR lpOutputString,...) noexcept
Formats and sends a string to the debugger for display.
Definition Win.h:778
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:962
win_handle< NULL > mutex
Mutex handle wrapper.
Definition Win.h:1114
win_handle< NULL > file_mapping
File mapping.
Definition Win.h:1129
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:991
win_handle< NULL > process
Process handle wrapper.
Definition Win.h:1093
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:541
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:2178
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:430
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:801
static DWORD ExpandEnvironmentStringsW(LPCWSTR lpSrc, std::basic_string< wchar_t, _Traits, _Ax > &sValue) noexcept
Expands environment-variable strings, replaces them with the values defined for the current user,...
Definition Win.h:208
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:249
static VOID OutputDebugStrV(LPCSTR lpOutputString, va_list arg) noexcept
Formats and sends a string to the debugger for display.
Definition Win.h:754
win_handle< NULL > thread
Thread handle wrapper.
Definition Win.h:1100
Deleter for unique_ptr using LocalFree.
Definition Common.h:694
UnmapViewOfFile_delete()
Default construct.
Definition Win.h:1168
void operator()(_Other *) const
Delete a pointer of another type.
Definition Win.h:1183
void operator()(_Ty *_Ptr) const
Delete a pointer.
Definition Win.h:1173
UnmapViewOfFile_delete< _Ty > _Myt
This type.
Definition Win.h:1163
Deleter for unique_ptr using UnmapViewOfFile.
Definition Win.h:1135
UnmapViewOfFile_delete(const UnmapViewOfFile_delete< _Ty2 > &)
Construct from another UnmapViewOfFile_delete.
Definition Win.h:1146
void operator()(_Ty *_Ptr) const
Delete a pointer.
Definition Win.h:1151
UnmapViewOfFile_delete< _Ty > _Myt
This type.
Definition Win.h:1136
UnmapViewOfFile_delete()
Default construct.
Definition Win.h:1141
A structure that enables an allocator for objects of one type to allocate storage for objects of anot...
Definition Win.h:1375
heap_allocator< _Other > other
Other allocator type.
Definition Win.h:1376