Add a helper function

llvm-svn: 29049
This commit is contained in:
Chris Lattner 2006-07-07 17:13:10 +00:00
parent 8c8858a6c4
commit 5df249dfea
1 changed files with 10 additions and 0 deletions

View File

@ -24,6 +24,16 @@
#include <cassert> #include <cassert>
#include <string> #include <string>
inline bool GetError(const std::string &Prefix, std::string *Dest) {
if (Dest == 0) return;
char *buffer = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
*Dest = Prefix + buffer;
LocalFree(buffer);
return true;
}
inline void ThrowError(const std::string& msg) { inline void ThrowError(const std::string& msg) {
char *buffer = NULL; char *buffer = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,