From 96cafdac487e5393e970cd9ec9d51ce89598c799 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 21 Mar 2024 20:31:49 +0100 Subject: [PATCH] Log actual error codes from CreateFileW failures. --- src/KM_fileio.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp index 14bb16a..e38d030 100644 --- a/src/KM_fileio.cpp +++ b/src/KM_fileio.cpp @@ -916,10 +916,17 @@ Kumu::FileReader::OpenRead(const std::string& filename) const NULL // no template file ); + HRESULT const last_error = GetLastError(); + ::SetErrorMode(prev); - return ( m_Handle == INVALID_HANDLE_VALUE ) ? - Kumu::RESULT_FILEOPEN : Kumu::RESULT_OK; + if (m_Handle == INVALID_HANDLE_VALUE) + { + DefaultLogSink().Error("CreateFileW failed: %lu", last_error); + return Kumu::RESULT_FILEOPEN; + } + + return Kumu::RESULT_OK; } // @@ -1054,11 +1061,16 @@ Kumu::FileWriter::OpenWrite(const std::string& filename) NULL // no template file ); + HRESULT const last_error = GetLastError(); + ::SetErrorMode(prev); - if ( m_Handle == INVALID_HANDLE_VALUE ) - return Kumu::RESULT_FILEOPEN; - + if (m_Handle == INVALID_HANDLE_VALUE) + { + DefaultLogSink().Error("CreateFileW failed: %lu\n", last_error); + return Kumu::RESULT_FILEOPEN; + } + m_IOVec = new h__iovec; return Kumu::RESULT_OK; } -- 2.30.2