aboutsummaryrefslogtreecommitdiff
path: root/c/common.cpp
diff options
context:
space:
mode:
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()