2004-09-15 05:48:11 +00:00
|
|
|
//===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-09-15 05:48:11 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-07-13 02:15:18 +00:00
|
|
|
// This file was developed by Jeff Cohen and is distributed under the
|
2004-09-15 05:48:11 +00:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-09-15 05:48:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2005-07-13 02:15:18 +00:00
|
|
|
// This file defines things specific to Win32 implementations.
|
2004-09-15 05:48:11 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2005-07-13 02:15:18 +00:00
|
|
|
//=== WARNING: Implementation here must contain only generic Win32 code that
|
|
|
|
//=== is guaranteed to work on *all* Win32 variants.
|
2004-09-15 05:48:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-07-13 02:15:18 +00:00
|
|
|
// Require at least Windows 2000 API.
|
|
|
|
#define _WIN32_WINNT 0x0500
|
|
|
|
|
2004-09-15 05:48:11 +00:00
|
|
|
#include "llvm/Config/config.h" // Get autoconf configuration settings
|
|
|
|
#include "windows.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <string>
|
|
|
|
|
2006-08-23 07:30:48 +00:00
|
|
|
inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
|
2006-08-21 06:02:44 +00:00
|
|
|
if (!ErrMsg)
|
2006-08-23 07:30:48 +00:00
|
|
|
return true;
|
2006-08-21 06:02:44 +00:00
|
|
|
char *buffer = NULL;
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
|
2006-09-01 20:35:17 +00:00
|
|
|
*ErrMsg = prefix + buffer;
|
2006-08-21 06:02:44 +00:00
|
|
|
LocalFree(buffer);
|
2006-08-23 07:30:48 +00:00
|
|
|
return true;
|
2006-08-21 06:02:44 +00:00
|
|
|
}
|
2007-03-05 05:22:08 +00:00
|
|
|
|
|
|
|
class AutoHandle {
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoHandle(HANDLE h) : handle(h) {}
|
|
|
|
|
|
|
|
~AutoHandle() {
|
|
|
|
if (handle)
|
|
|
|
CloseHandle(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HANDLE() {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoHandle &operator=(HANDLE h) {
|
|
|
|
handle = h;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|