Add a helper function
[oota-llvm.git] / lib / System / Win32 / Win32.h
index 7ed10471de15fe7bea08fb7079025ebb157634e5..d1029916605fcdf7a053f6266cf05cc598602bed 100644 (file)
 #include <cassert>
 #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) {
   char *buffer = NULL;
   FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,