From d807e150ba7939730ee293ec69d3104197e801ff Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 1 Oct 2024 16:38:14 +0200 Subject: [PATCH] Stop using get_ptr after moved to stdex Signed-off-by: Simon Rozman --- include/WinStd/Common.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index 65c24ff9..9c35ad7d 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -687,10 +687,12 @@ static _Success_(return != 0) int SecureMultiByteToWideChar(_In_ UINT CodePage, template static DWORD FormatMessageA(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments) { - std::unique_ptr > lpBuffer; - DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast((LPSTR*)get_ptr(lpBuffer)), 0, Arguments); - if (dwResult) - str.assign(lpBuffer.get(), dwResult); + LPSTR lpBuffer; + DWORD dwResult = FormatMessageA(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast(&lpBuffer), 0, Arguments); + if (dwResult) { + str.assign(lpBuffer, dwResult); + LocalFree(lpBuffer); + } return dwResult; } @@ -702,10 +704,12 @@ static DWORD FormatMessageA(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ template static DWORD FormatMessageW(_In_ DWORD dwFlags, _In_opt_ LPCVOID lpSource, _In_ DWORD dwMessageId, _In_ DWORD dwLanguageId, _Inout_ std::basic_string &str, _In_opt_ va_list *Arguments) { - std::unique_ptr > lpBuffer; - DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast((LPWSTR*)get_ptr(lpBuffer)), 0, Arguments); - if (dwResult) - str.assign(lpBuffer.get(), dwResult); + LPWSTR lpBuffer; + DWORD dwResult = FormatMessageW(dwFlags | FORMAT_MESSAGE_ALLOCATE_BUFFER, lpSource, dwMessageId, dwLanguageId, reinterpret_cast(&lpBuffer), 0, Arguments); + if (dwResult) { + str.assign(lpBuffer, dwResult); + LocalFree(lpBuffer); + } return dwResult; }