aboutsummaryrefslogtreecommitdiff
path: root/c/common.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-15 16:40:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-15 16:40:49 +0200
commitf61e83d936ebab185b09682f922aa58734153761 (patch)
tree6881c8582a37b32f0ad2763c1e23c73cf6a33404 /c/common.cpp
parentdcb9fabf265068a42231589ba8f83bd09eb46d38 (diff)
downloadEpisodeBrowser-f61e83d936ebab185b09682f922aa58734153761.tar.gz
Add Win32Error exception class.
Diffstat (limited to 'c/common.cpp')
-rw-r--r--c/common.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/c/common.cpp b/c/common.cpp
index dd84742..3a99769 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -29,11 +29,35 @@ TCHAR *TszFromSz(const char *sz, int iCp)
return tsz;
}
+Win32Error::Win32Error(DWORD dwErr)
+{
+ m_dwErr = dwErr;
+ FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ m_dwErr,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&m_szMsg,
+ 0, NULL
+ );
+}
+
+Win32Error::~Win32Error()
+{
+ if (m_szMsg)
+ HeapFree(GetProcessHeap(), 0, m_szMsg);
+}
+
+const char *Win32Error::what(void) const noexcept
+{
+ return m_szMsg;
+}
+
Library::Library(const TCHAR *tszLibrary)
{
m_hModule = LoadLibrary(tszLibrary);
if (!m_hModule)
- throw std::invalid_argument("Library not found.");
+ throw Win32Error(GetLastError());
}
Library::~Library()