-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathError.cpp
43 lines (36 loc) · 939 Bytes
/
Error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "StdAfx.h"
#include "Error.h"
extern bool g_bThreadEnd;
// Function that displays the error message obtained by GetLastError()
void CError::LastError(HWND hWnd)
{
g_bThreadEnd = true;
LPTSTR lpMsgBuf = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
lpMsgBuf,
0,
nullptr);
if (lpMsgBuf)
{
MessageBox(hWnd, lpMsgBuf, _T("Error"), MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
}
void CError::Message(HWND hWnd, LPCTSTR mes, ...)
{
TCHAR string[1024];
va_list list;
va_start(list, mes);
wvsprintf(string, mes, list);
va_end(list);
g_bThreadEnd = true;
MessageBox(hWnd, string, _T("Error"), MB_OK | MB_ICONSTOP);
}
void CError::bad_alloc(HWND hWnd)
{
g_bThreadEnd = TRUE;
Message(hWnd, _T("You do not have enough free memory..."));
}