summaryrefslogtreecommitdiff
path: root/src/libcrawler/win32/errormsg.cpp
blob: c0a65d84d7c67bc5b3ba87f88073756c6ec8a5a2 (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 "win32/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 );
}