1 //===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines things specific to Win32 implementations.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic Win32 code that
16 //=== is guaranteed to work on *all* Win32 variants.
17 //===----------------------------------------------------------------------===//
19 // mingw-w64 tends to define it as 0x0502 in its headers.
22 // Require at least Windows XP(5.1) API.
23 #define _WIN32_WINNT 0x0501
24 #define _WIN32_IE 0x0600 // MinGW at it again.
25 #define WIN32_LEAN_AND_MEAN
27 #include "llvm/Config/config.h" // Get build system configuration settings
28 #include "llvm/Support/Compiler.h"
35 inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
39 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
40 NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
41 *ErrMsg = prefix + buffer;
46 template <typename HandleTraits>
48 typedef typename HandleTraits::handle_type handle_type;
51 ScopedHandle(const ScopedHandle &other); // = delete;
52 void operator=(const ScopedHandle &other); // = delete;
55 : Handle(HandleTraits::GetInvalid()) {}
57 explicit ScopedHandle(handle_type h)
61 if (HandleTraits::IsValid(Handle))
62 HandleTraits::Close(Handle);
66 handle_type t = Handle;
67 Handle = HandleTraits::GetInvalid();
71 ScopedHandle &operator=(handle_type h) {
72 if (HandleTraits::IsValid(Handle))
73 HandleTraits::Close(Handle);
78 // True if Handle is valid.
79 LLVM_EXPLICIT operator bool() const {
80 return HandleTraits::IsValid(Handle) ? true : false;
83 operator handle_type() const {
88 struct CommonHandleTraits {
89 typedef HANDLE handle_type;
91 static handle_type GetInvalid() {
92 return INVALID_HANDLE_VALUE;
95 static void Close(handle_type h) {
99 static bool IsValid(handle_type h) {
100 return h != GetInvalid();
104 struct JobHandleTraits : CommonHandleTraits {
105 static handle_type GetInvalid() {
110 struct CryptContextTraits : CommonHandleTraits {
111 typedef HCRYPTPROV handle_type;
113 static handle_type GetInvalid() {
117 static void Close(handle_type h) {
118 ::CryptReleaseContext(h, 0);
121 static bool IsValid(handle_type h) {
122 return h != GetInvalid();
126 struct FindHandleTraits : CommonHandleTraits {
127 static void Close(handle_type h) {
132 struct FileHandleTraits : CommonHandleTraits {};
134 typedef ScopedHandle<CommonHandleTraits> ScopedCommonHandle;
135 typedef ScopedHandle<FileHandleTraits> ScopedFileHandle;
136 typedef ScopedHandle<CryptContextTraits> ScopedCryptContext;
137 typedef ScopedHandle<FindHandleTraits> ScopedFindHandle;
138 typedef ScopedHandle<JobHandleTraits> ScopedJobHandle;
142 class SmallVectorImpl;
145 typename SmallVectorImpl<T>::const_pointer
146 c_str(SmallVectorImpl<T> &str) {
151 } // end namespace llvm.