summaryrefslogtreecommitdiff
path: root/src/win32/errormsg.cpp
blob: 1b58ea3581abf2606a8a145c01141f65bda61e2d (plain)
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
#include "errormsg.hpp"

using namespace std;

#define WIN32_MEAN_AND_LEAN
#include <windows.h>

string getLastError( )
{
	LPTSTR buf;
	DWORD size;

	DWORD lastErr = GetLastError( );
	
	if( !FormatMessage(
		FORMAT_MESSAGE_ALLOCATE_BUFFER |
		FORMAT_MESSAGE_FROM_SYSTEM |
		FORMAT_MESSAGE_IGNORE_INSERTS |
		FORMAT_MESSAGE_MAX_WIDTH_MASK,
		NULL, lastErr, 0, (LPTSTR)&buf,
		0, NULL ) ) {
		return "<no message available>";
	}
	
	return string( buf );
}