auto keyword removed where not necessary
This commit is contained in:
parent
3b4448dcf4
commit
7b0b38aab3
@ -360,7 +360,7 @@ inline int vsprintf(_Out_ std::basic_string<_Elem, _Traits, _Ax> &str, _In_z_ _P
|
|||||||
} else {
|
} else {
|
||||||
for (size_t capacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; capacity *= 2) {
|
for (size_t capacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; capacity *= 2) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto buf = std::unique_ptr<_Elem[]>(new _Elem[capacity]);
|
std::unique_ptr<_Elem[]> buf(new _Elem[capacity]);
|
||||||
count = vsnprintf(buf.get(), capacity - 1, format, arg);
|
count = vsnprintf(buf.get(), capacity - 1, format, arg);
|
||||||
if (count >= 0) {
|
if (count >= 0) {
|
||||||
str.assign(buf.get(), count);
|
str.assign(buf.get(), count);
|
||||||
|
@ -168,7 +168,7 @@ inline BOOL CredProtectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszCredentials, _In_ DWO
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto buf = std::unique_ptr<_Elem[]>(new _Elem[dwSize]);
|
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]);
|
||||||
if (CredProtectA(fAsSelf, const_cast<LPSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
|
if (CredProtectA(fAsSelf, const_cast<LPSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
|
||||||
sProtectedCredentials.assign(buf.get(), dwSize - 1);
|
sProtectedCredentials.assign(buf.get(), dwSize - 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -192,7 +192,7 @@ inline BOOL CredProtectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszCredentials, _In_ DW
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto buf = std::unique_ptr<_Elem[]>(new _Elem[dwSize]);
|
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]);
|
||||||
if (CredProtectW(fAsSelf, const_cast<LPWSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
|
if (CredProtectW(fAsSelf, const_cast<LPWSTR>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
|
||||||
sProtectedCredentials.assign(buf.get(), dwSize - 1);
|
sProtectedCredentials.assign(buf.get(), dwSize - 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -216,7 +216,7 @@ inline BOOL CredUnprotectA(_In_ BOOL fAsSelf, _In_ LPCSTR pszProtectedCredential
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto buf = std::unique_ptr<_Elem[]>(new _Elem[dwSize]);
|
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]);
|
||||||
if (CredUnprotectA(fAsSelf, const_cast<LPSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
|
if (CredUnprotectA(fAsSelf, const_cast<LPSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
|
||||||
sCredentials.assign(buf.get(), dwSize);
|
sCredentials.assign(buf.get(), dwSize);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -240,7 +240,7 @@ inline BOOL CredUnprotectW(_In_ BOOL fAsSelf, _In_ LPCWSTR pszProtectedCredentia
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
} else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto buf = std::unique_ptr<_Elem[]>(new _Elem[dwSize]);
|
std::unique_ptr<_Elem[]> buf(new _Elem[dwSize]);
|
||||||
if (CredUnprotectW(fAsSelf, const_cast<LPWSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
|
if (CredUnprotectW(fAsSelf, const_cast<LPWSTR>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
|
||||||
sCredentials.assign(buf.get(), dwSize);
|
sCredentials.assign(buf.get(), dwSize);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -151,7 +151,7 @@ inline DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwT
|
|||||||
DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
|
DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
|
||||||
|
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize]);
|
||||||
dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize);
|
dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize);
|
||||||
sNameString.assign(szBuffer.get(), dwSize - 1);
|
sNameString.assign(szBuffer.get(), dwSize - 1);
|
||||||
return dwSize;
|
return dwSize;
|
||||||
@ -165,7 +165,7 @@ inline DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwT
|
|||||||
DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
|
DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0);
|
||||||
|
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize]);
|
||||||
dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize);
|
dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, szBuffer.get(), dwSize);
|
||||||
sNameString.assign(szBuffer.get(), dwSize - 1);
|
sNameString.assign(szBuffer.get(), dwSize - 1);
|
||||||
return dwSize;
|
return dwSize;
|
||||||
|
@ -130,7 +130,7 @@ inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_ s
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer.get(), &dwSize);
|
uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -158,7 +158,7 @@ inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer.get(), &dwSize);
|
uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -186,7 +186,7 @@ inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer.get(), &dwSize);
|
uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -214,7 +214,7 @@ inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to read the string data into and read it.
|
// Allocate buffer on heap to read the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer.get(), &dwSize);
|
uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -242,7 +242,7 @@ inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_s
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer.get(), &dwSize);
|
uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -270,7 +270,7 @@ inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, std::basic_s
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer.get(), &dwSize);
|
uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -318,7 +318,7 @@ inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Ou
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer.get(), &dwSize);
|
uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -346,7 +346,7 @@ inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _O
|
|||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
} else if (uiResult == ERROR_MORE_DATA) {
|
} else if (uiResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer.get(), &dwSize);
|
uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
|
||||||
return uiResult;
|
return uiResult;
|
||||||
@ -372,7 +372,7 @@ inline INSTALLSTATE MsiGetComponentPathA(_In_ LPCSTR szProduct, _In_ LPCSTR szCo
|
|||||||
return state;
|
return state;
|
||||||
} else if (state == INSTALLSTATE_MOREDATA) {
|
} else if (state == INSTALLSTATE_MOREDATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
state = ::MsiGetComponentPathA(szProduct, szComponent, szBuffer.get(), &dwSize);
|
state = ::MsiGetComponentPathA(szProduct, szComponent, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
|
sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
|
||||||
return state;
|
return state;
|
||||||
@ -398,7 +398,7 @@ inline INSTALLSTATE MsiGetComponentPathW(_In_ LPCWSTR szProduct, _In_ LPCWSTR sz
|
|||||||
return state;
|
return state;
|
||||||
} else if (state == INSTALLSTATE_MOREDATA) {
|
} else if (state == INSTALLSTATE_MOREDATA) {
|
||||||
// Allocate buffer on heap to format the string data into and read it.
|
// Allocate buffer on heap to format the string data into and read it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++dwSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++dwSize]);
|
||||||
state = ::MsiGetComponentPathW(szProduct, szComponent, szBuffer.get(), &dwSize);
|
state = ::MsiGetComponentPathW(szProduct, szComponent, szBuffer.get(), &dwSize);
|
||||||
sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
|
sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
|
||||||
return state;
|
return state;
|
||||||
|
@ -374,7 +374,7 @@ BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_st
|
|||||||
} else {
|
} else {
|
||||||
if (::GetLastError() == ERROR_MORE_DATA) {
|
if (::GetLastError() == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap and retry.
|
// Allocate buffer on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[ulSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[ulSize]);
|
||||||
if (::GetUserNameExA(NameFormat, szBuffer.get(), &ulSize)) {
|
if (::GetUserNameExA(NameFormat, szBuffer.get(), &ulSize)) {
|
||||||
sName.assign(szBuffer.get(), ulSize);
|
sName.assign(szBuffer.get(), ulSize);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -403,7 +403,7 @@ BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ std::basic_st
|
|||||||
} else {
|
} else {
|
||||||
if (::GetLastError() == ERROR_MORE_DATA) {
|
if (::GetLastError() == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap and retry.
|
// Allocate buffer on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[ulSize]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[ulSize]);
|
||||||
if (::GetUserNameExW(NameFormat, szBuffer.get(), &ulSize)) {
|
if (::GetUserNameExW(NameFormat, szBuffer.get(), &ulSize)) {
|
||||||
sName.assign(szBuffer.get(), ulSize);
|
sName.assign(szBuffer.get(), ulSize);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -178,7 +178,7 @@ inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_st
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Increment size and allocate buffer.
|
// Increment size and allocate buffer.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSize += 1024]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize += 1024]);
|
||||||
|
|
||||||
// Try!
|
// Try!
|
||||||
DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer.get(), pReserved);
|
DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer.get(), pReserved);
|
||||||
|
@ -730,7 +730,7 @@ inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ std::basic_strin
|
|||||||
} else {
|
} else {
|
||||||
for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; dwCapacity *= 2) {
|
for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; dwCapacity *= 2) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwCapacity]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwCapacity]);
|
||||||
dwResult = ::GetModuleFileNameA(hModule, szBuffer.get(), dwCapacity);
|
dwResult = ::GetModuleFileNameA(hModule, szBuffer.get(), dwCapacity);
|
||||||
if (dwResult < dwCapacity) {
|
if (dwResult < dwCapacity) {
|
||||||
sValue.assign(szBuffer.get(), dwResult);
|
sValue.assign(szBuffer.get(), dwResult);
|
||||||
@ -755,7 +755,7 @@ inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ std::basic_strin
|
|||||||
} else {
|
} else {
|
||||||
for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; dwCapacity *= 2) {
|
for (DWORD dwCapacity = 2*WINSTD_STACK_BUFFER_BYTES/sizeof(_Elem);; dwCapacity *= 2) {
|
||||||
// Allocate on heap and retry.
|
// Allocate on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwCapacity]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwCapacity]);
|
||||||
dwResult = ::GetModuleFileNameW(hModule, szBuffer.get(), dwCapacity);
|
dwResult = ::GetModuleFileNameW(hModule, szBuffer.get(), dwCapacity);
|
||||||
if (dwResult < dwCapacity) {
|
if (dwResult < dwCapacity) {
|
||||||
sValue.assign(szBuffer.get(), dwResult);
|
sValue.assign(szBuffer.get(), dwResult);
|
||||||
@ -783,7 +783,7 @@ inline int GetWindowTextA(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits
|
|||||||
sValue.assign(szBuffer, iResult);
|
sValue.assign(szBuffer, iResult);
|
||||||
} else {
|
} else {
|
||||||
// Allocate buffer on heap and read the string data into it.
|
// Allocate buffer on heap and read the string data into it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++iResult]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++iResult]);
|
||||||
iResult = ::GetWindowTextA(hWnd, szBuffer.get(), iResult);
|
iResult = ::GetWindowTextA(hWnd, szBuffer.get(), iResult);
|
||||||
sValue.assign(szBuffer.get(), iResult);
|
sValue.assign(szBuffer.get(), iResult);
|
||||||
}
|
}
|
||||||
@ -812,7 +812,7 @@ inline int GetWindowTextW(_In_ HWND hWnd, _Out_ std::basic_string<_Elem, _Traits
|
|||||||
sValue.assign(szBuffer, iResult);
|
sValue.assign(szBuffer, iResult);
|
||||||
} else {
|
} else {
|
||||||
// Allocate buffer on heap and read the string data into it.
|
// Allocate buffer on heap and read the string data into it.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[++iResult]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[++iResult]);
|
||||||
iResult = ::GetWindowTextW(hWnd, szBuffer.get(), iResult);
|
iResult = ::GetWindowTextW(hWnd, szBuffer.get(), iResult);
|
||||||
sValue.assign(szBuffer.get(), iResult);
|
sValue.assign(szBuffer.get(), iResult);
|
||||||
}
|
}
|
||||||
@ -863,7 +863,7 @@ inline DWORD ExpandEnvironmentStringsW(_In_ LPCSTR lpSrc, std::basic_string<_Ele
|
|||||||
|
|
||||||
for (DWORD dwSizeOut = (DWORD)strlen(lpSrc) + 0x100;;) {
|
for (DWORD dwSizeOut = (DWORD)strlen(lpSrc) + 0x100;;) {
|
||||||
DWORD dwSizeIn = dwSizeOut;
|
DWORD dwSizeIn = dwSizeOut;
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSizeIn + 2]); // Note: ANSI version requires one extra char.
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSizeIn + 2]); // Note: ANSI version requires one extra char.
|
||||||
dwSizeOut = ::ExpandEnvironmentStringsA(lpSrc, szBuffer.get(), dwSizeIn);
|
dwSizeOut = ::ExpandEnvironmentStringsA(lpSrc, szBuffer.get(), dwSizeIn);
|
||||||
if (dwSizeOut == 0) {
|
if (dwSizeOut == 0) {
|
||||||
// Error.
|
// Error.
|
||||||
@ -887,7 +887,7 @@ inline DWORD ExpandEnvironmentStringsW(_In_ LPCWSTR lpSrc, std::basic_string<_El
|
|||||||
|
|
||||||
for (DWORD dwSizeOut = (DWORD)wcslen(lpSrc) + 0x100;;) {
|
for (DWORD dwSizeOut = (DWORD)wcslen(lpSrc) + 0x100;;) {
|
||||||
DWORD dwSizeIn = dwSizeOut;
|
DWORD dwSizeIn = dwSizeOut;
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSizeIn + 1]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSizeIn + 1]);
|
||||||
dwSizeOut = ::ExpandEnvironmentStringsW(lpSrc, szBuffer.get(), dwSizeIn);
|
dwSizeOut = ::ExpandEnvironmentStringsW(lpSrc, szBuffer.get(), dwSizeIn);
|
||||||
if (dwSizeOut == 0) {
|
if (dwSizeOut == 0) {
|
||||||
// Error.
|
// Error.
|
||||||
@ -957,7 +957,7 @@ inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_
|
|||||||
} else if (lResult == ERROR_MORE_DATA) {
|
} else if (lResult == ERROR_MORE_DATA) {
|
||||||
if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
|
if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
|
||||||
// The value is REG_SZ or REG_MULTI_SZ. Read it now.
|
// The value is REG_SZ or REG_MULTI_SZ. Read it now.
|
||||||
auto szBuffer = std::unique_ptr<CHAR[]>(new CHAR[dwSize / sizeof(CHAR)]);
|
std::unique_ptr<CHAR[]> szBuffer(new CHAR[dwSize / sizeof(CHAR)]);
|
||||||
if ((lResult = ::RegQueryValueExA(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
if ((lResult = ::RegQueryValueExA(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
||||||
dwSize /= sizeof(CHAR);
|
dwSize /= sizeof(CHAR);
|
||||||
sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
|
sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
|
||||||
@ -965,7 +965,7 @@ inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_
|
|||||||
sValue.clear();
|
sValue.clear();
|
||||||
} else if (dwType == REG_EXPAND_SZ) {
|
} else if (dwType == REG_EXPAND_SZ) {
|
||||||
// The value is REG_EXPAND_SZ. Read it and expand environment variables.
|
// The value is REG_EXPAND_SZ. Read it and expand environment variables.
|
||||||
auto szBuffer = std::unique_ptr<CHAR[]>(new CHAR[dwSize / sizeof(CHAR)]);
|
std::unique_ptr<CHAR[]> szBuffer(new CHAR[dwSize / sizeof(CHAR)]);
|
||||||
if ((lResult = ::RegQueryValueExA(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
if ((lResult = ::RegQueryValueExA(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
||||||
if (::ExpandEnvironmentStringsA(szBuffer.get(), sValue) == 0)
|
if (::ExpandEnvironmentStringsA(szBuffer.get(), sValue) == 0)
|
||||||
lResult = ::GetLastError();
|
lResult = ::GetLastError();
|
||||||
@ -1006,7 +1006,7 @@ inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_
|
|||||||
} else if (lResult == ERROR_MORE_DATA) {
|
} else if (lResult == ERROR_MORE_DATA) {
|
||||||
if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
|
if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
|
||||||
// The value is REG_SZ or REG_MULTI_SZ. Read it now.
|
// The value is REG_SZ or REG_MULTI_SZ. Read it now.
|
||||||
auto szBuffer = std::unique_ptr<WCHAR[]>(new WCHAR[dwSize / sizeof(WCHAR)]);
|
std::unique_ptr<WCHAR[]> szBuffer(new WCHAR[dwSize / sizeof(WCHAR)]);
|
||||||
if ((lResult = ::RegQueryValueExW(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
if ((lResult = ::RegQueryValueExW(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
||||||
dwSize /= sizeof(WCHAR);
|
dwSize /= sizeof(WCHAR);
|
||||||
sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
|
sValue.assign(szBuffer.get(), dwSize && szBuffer[dwSize - 1] == 0 ? dwSize - 1 : dwSize);
|
||||||
@ -1014,7 +1014,7 @@ inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_
|
|||||||
sValue.clear();
|
sValue.clear();
|
||||||
} else if (dwType == REG_EXPAND_SZ) {
|
} else if (dwType == REG_EXPAND_SZ) {
|
||||||
// The value is REG_EXPAND_SZ. Read it and expand environment variables.
|
// The value is REG_EXPAND_SZ. Read it and expand environment variables.
|
||||||
auto szBuffer = std::unique_ptr<WCHAR[]>(new WCHAR[dwSize / sizeof(WCHAR)]);
|
std::unique_ptr<WCHAR[]> szBuffer(new WCHAR[dwSize / sizeof(WCHAR)]);
|
||||||
if ((lResult = ::RegQueryValueExW(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
if ((lResult = ::RegQueryValueExW(hReg, pszName, NULL, NULL, reinterpret_cast<LPBYTE>(szBuffer.get()), &dwSize)) == ERROR_SUCCESS) {
|
||||||
if (::ExpandEnvironmentStringsW(szBuffer.get(), sValue) == 0)
|
if (::ExpandEnvironmentStringsW(szBuffer.get(), sValue) == 0)
|
||||||
lResult = ::GetLastError();
|
lResult = ::GetLastError();
|
||||||
@ -1102,7 +1102,7 @@ inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_ LPCSTR pszValue, _Out_
|
|||||||
sOut.assign(szStackBuffer, dwSize);
|
sOut.assign(szStackBuffer, dwSize);
|
||||||
} else if (lResult == ERROR_MORE_DATA) {
|
} else if (lResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap and retry.
|
// Allocate buffer on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSize + 1]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize + 1]);
|
||||||
sOut.assign(szBuffer.get(), (lResult = RegLoadMUIStringA(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? dwSize : 0);
|
sOut.assign(szBuffer.get(), (lResult = RegLoadMUIStringA(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? dwSize : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1128,7 +1128,7 @@ inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_ LPCWSTR pszValue, _Out
|
|||||||
sOut.assign(szStackBuffer, dwSize);
|
sOut.assign(szStackBuffer, dwSize);
|
||||||
} else if (lResult == ERROR_MORE_DATA) {
|
} else if (lResult == ERROR_MORE_DATA) {
|
||||||
// Allocate buffer on heap and retry.
|
// Allocate buffer on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[dwSize + 1]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[dwSize + 1]);
|
||||||
sOut.assign(szBuffer.get(), (lResult = RegLoadMUIStringW(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? dwSize : 0);
|
sOut.assign(szBuffer.get(), (lResult = RegLoadMUIStringW(hKey, pszValue, szBuffer.get(), dwSize, &dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? dwSize : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1151,7 +1151,7 @@ inline int WideCharToMultiByte(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_cou
|
|||||||
} else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
} else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
// Query the required output size. Allocate buffer. Then convert again.
|
// Query the required output size. Allocate buffer. Then convert again.
|
||||||
cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
|
cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, NULL, 0, lpDefaultChar, lpUsedDefaultChar);
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[cch]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[cch]);
|
||||||
cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szBuffer.get(), cch, lpDefaultChar, lpUsedDefaultChar);
|
cch = ::WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, szBuffer.get(), cch, lpDefaultChar, lpUsedDefaultChar);
|
||||||
sMultiByteStr.assign(szBuffer.get(), cchWideChar != -1 ? strnlen(szBuffer.get(), cch) : cch - 1);
|
sMultiByteStr.assign(szBuffer.get(), cchWideChar != -1 ? strnlen(szBuffer.get(), cch) : cch - 1);
|
||||||
}
|
}
|
||||||
@ -1173,7 +1173,7 @@ inline int MultiByteToWideChar(_In_ UINT CodePage, _In_ DWORD dwFlags, _In_z_cou
|
|||||||
} else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
} else if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
||||||
// Query the required output size. Allocate buffer. Then convert again.
|
// Query the required output size. Allocate buffer. Then convert again.
|
||||||
cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0);
|
cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, NULL, 0);
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[cch]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[cch]);
|
||||||
cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szBuffer.get(), cch);
|
cch = ::MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr, cbMultiByte, szBuffer.get(), cch);
|
||||||
sWideCharStr.assign(szBuffer.get(), cbMultiByte != -1 ? wcsnlen(szBuffer.get(), cch) : cch - 1);
|
sWideCharStr.assign(szBuffer.get(), cbMultiByte != -1 ? wcsnlen(szBuffer.get(), cch) : cch - 1);
|
||||||
}
|
}
|
||||||
@ -1249,7 +1249,7 @@ template<class _Elem, class _Traits, class _Ax> inline int GetDateFormatA(_In_ L
|
|||||||
int iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
|
int iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
|
||||||
if (iResult) {
|
if (iResult) {
|
||||||
// Allocate buffer on heap and retry.
|
// Allocate buffer on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[iResult]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[iResult]);
|
||||||
iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
|
iResult = GetDateFormatA(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
|
||||||
sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
|
sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
|
||||||
return iResult;
|
return iResult;
|
||||||
@ -1264,7 +1264,7 @@ template<class _Elem, class _Traits, class _Ax> inline int GetDateFormatW(_In_ L
|
|||||||
int iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
|
int iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, NULL, 0);
|
||||||
if (iResult) {
|
if (iResult) {
|
||||||
// Allocate buffer on heap and retry.
|
// Allocate buffer on heap and retry.
|
||||||
auto szBuffer = std::unique_ptr<_Elem[]>(new _Elem[iResult]);
|
std::unique_ptr<_Elem[]> szBuffer(new _Elem[iResult]);
|
||||||
iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
|
iResult = GetDateFormatW(Locale, dwFlags, lpDate, lpFormat, szBuffer.get(), iResult);
|
||||||
sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
|
sDate.assign(szBuffer.get(), iResult ? iResult - 1 : 0);
|
||||||
return iResult;
|
return iResult;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user