diff options
Diffstat (limited to 'win32/common/errutil.cpp')
-rw-r--r-- | win32/common/errutil.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/win32/common/errutil.cpp b/win32/common/errutil.cpp new file mode 100644 index 0000000..302b4fa --- /dev/null +++ b/win32/common/errutil.cpp @@ -0,0 +1,106 @@ +/* + * AUTHOR + * N. Nielsen + * + * LICENSE + * This software is in the public domain. + * + * The software is provided "as is", without warranty of any kind, + * express or implied, including but not limited to the warranties + * of merchantability, fitness for a particular purpose, and + * noninfringement. In no event shall the author(s) be liable for any + * claim, damages, or other liability, whether in an action of + * contract, tort, or otherwise, arising from, out of, or in connection + * with the software or the use or other dealings in the software. + * + * SUPPORT + * Send bug reports to: <nielsen@memberwebs.com> + */ + +#include "stdafx.h" +#include "rliberr.h" +#include "errutil.h" + +// rlibError: ------------------------------------------------------------- +// Displays errors from rlib. Assumes we have the appropriate +// error codes compiled in as resources + +HRESULT rlibError(HWND parent, int code, r_script* script) +{ + ASSERT(code < 0); + USES_CONVERSION; + + LPVOID lpMsgBuf; + HRESULT hr = HRESULT_FROM_RLIB(code); + string message; + + DWORD dwRet = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | + FORMAT_MESSAGE_MAX_WIDTH_MASK, GetModuleHandle(NULL), hr, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR)&lpMsgBuf, 0, NULL); + if(dwRet && lpMsgBuf) + { + message.append((LPTSTR)lpMsgBuf); + + // Free the buffer. + ::LocalFree(lpMsgBuf); + + // If there was a specific error message then tack that on + if(script->error) + { + message.append(_T("\n\n")); + message.append(A2T(script->error)); + } + + // If there's an error line then tack that on + if(script->errline != 0) + { + string line; + line.format(_T(" (near line %d)"), script->errline); + message.append(line); + } + + MessageBox(parent, message.c_str(), _T("Rep Droplet"), MB_OK | MB_ICONSTOP); + } + + return hr; +} + + +// errorMessage: ----------------------------------------------------------- +// Displays standard windows errors. + +HRESULT errorMessage(HWND parent, HRESULT hr, LPCTSTR format, ...) +{ + string message; + + va_list ap; + va_start(ap, format); + + message.format_v(format, ap); + + va_end(ap); + + if(FAILED(hr)) + { + LPVOID lpMsgBuf; + + DWORD dwRet = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, hr, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, 0, NULL); + if(dwRet && lpMsgBuf) + { + message.append(_T("\n\n")); + message.append((LPTSTR)lpMsgBuf); + message.resize(message.size() - 2); // Take off new line + + // Free the buffer. + ::LocalFree(lpMsgBuf); + } + } + + MessageBox(parent, message.c_str(), _T("Rep Droplet"), MB_OK | MB_ICONSTOP); + + return hr == S_OK ? E_FAIL : hr; +} |