2004-09-15 13:48:11 +08:00
|
|
|
//===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2004-09-15 13:48:11 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2004-09-15 13:48:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2005-07-13 10:15:18 +08:00
|
|
|
// This file defines things specific to Win32 implementations.
|
2004-09-15 13:48:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2005-07-13 10:15:18 +08:00
|
|
|
//=== WARNING: Implementation here must contain only generic Win32 code that
|
|
|
|
//=== is guaranteed to work on *all* Win32 variants.
|
2004-09-15 13:48:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2005-07-13 10:15:18 +08:00
|
|
|
// Require at least Windows 2000 API.
|
|
|
|
#define _WIN32_WINNT 0x0500
|
2010-11-09 23:11:19 +08:00
|
|
|
#define _WIN32_IE 0x0500 // MinGW at it again.
|
2010-11-09 23:11:07 +08:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2005-07-13 10:15:18 +08:00
|
|
|
|
2010-11-09 23:10:29 +08:00
|
|
|
#include "llvm/Config/config.h" // Get build system configuration settings
|
2010-11-09 23:10:56 +08:00
|
|
|
#include <Windows.h>
|
2010-11-09 23:11:19 +08:00
|
|
|
#include <ShlObj.h>
|
2004-09-15 13:48:11 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <string>
|
|
|
|
|
2006-08-23 15:30:48 +08:00
|
|
|
inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
|
2006-08-21 14:02:44 +08:00
|
|
|
if (!ErrMsg)
|
2006-08-23 15:30:48 +08:00
|
|
|
return true;
|
2006-08-21 14:02:44 +08:00
|
|
|
char *buffer = NULL;
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
|
2006-09-02 04:35:17 +08:00
|
|
|
*ErrMsg = prefix + buffer;
|
2006-08-21 14:02:44 +08:00
|
|
|
LocalFree(buffer);
|
2006-08-23 15:30:48 +08:00
|
|
|
return true;
|
2006-08-21 14:02:44 +08:00
|
|
|
}
|
2007-03-05 13:22:08 +08: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;
|
|
|
|
}
|
|
|
|
};
|
2010-12-06 12:28:13 +08:00
|
|
|
|
|
|
|
template <class HandleType, HandleType InvalidHandle,
|
|
|
|
class DeleterType, DeleterType D>
|
|
|
|
class ScopedHandle {
|
|
|
|
HandleType Handle;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ScopedHandle() : Handle(InvalidHandle) {}
|
|
|
|
ScopedHandle(HandleType handle) : Handle(handle) {}
|
|
|
|
|
|
|
|
~ScopedHandle() {
|
|
|
|
if (Handle != InvalidHandle)
|
|
|
|
D(Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleType take() {
|
|
|
|
HandleType temp = Handle;
|
|
|
|
Handle = InvalidHandle;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HandleType() const { return Handle; }
|
|
|
|
|
|
|
|
ScopedHandle &operator=(HandleType handle) {
|
|
|
|
Handle = handle;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*unspecified_bool_type)();
|
|
|
|
static void unspecified_bool_true() {}
|
|
|
|
|
|
|
|
// True if Handle is valid.
|
|
|
|
operator unspecified_bool_type() const {
|
|
|
|
return Handle == InvalidHandle ? 0 : unspecified_bool_true;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef ScopedHandle<HANDLE, INVALID_HANDLE_VALUE,
|
|
|
|
BOOL (WINAPI*)(HANDLE), ::FindClose>
|
|
|
|
ScopedFindHandle;
|
|
|
|
};
|