From f799bcfd141e2fc36c468478692a01d52f761080 Mon Sep 17 00:00:00 2001 From: Peter Stuer Date: Wed, 20 Nov 2024 12:51:07 +0100 Subject: [PATCH] Improved error reporting. --- HostObjectImpl.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/HostObjectImpl.cpp b/HostObjectImpl.cpp index 43511f8..eec6196 100644 --- a/HostObjectImpl.cpp +++ b/HostObjectImpl.cpp @@ -649,7 +649,9 @@ STDMETHODIMP HostObject::ReadAllText(BSTR filePath, __int32 codePage, BSTR * tex LARGE_INTEGER FileSize; - if (GetFileSizeEx(hFile, &FileSize)) + HRESULT hr = S_OK; + + if (::GetFileSizeEx(hFile, &FileSize)) { std::string Text; @@ -659,11 +661,15 @@ STDMETHODIMP HostObject::ReadAllText(BSTR filePath, __int32 codePage, BSTR * tex if (::ReadFile(hFile, (void *) Text.c_str(), FileSize.LowPart, &BytesRead, nullptr) && (BytesRead == FileSize.LowPart)) *text = ::SysAllocString(::CodePageToWide((uint32_t) codePage, Text).c_str()); + else + hr = HRESULT_FROM_WIN32(::GetLastError()); } + else + hr = HRESULT_FROM_WIN32(::GetLastError()); ::CloseHandle(hFile); - return S_OK; + return hr; } #pragma region IDispatch