LLVM API Documentation

Win32.h

Go to the documentation of this file.
00001 //===- Win32/Win32.h - Common Win32 Include File ----------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines things specific to Win32 implementations.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 //===----------------------------------------------------------------------===//
00015 //=== WARNING: Implementation here must contain only generic Win32 code that
00016 //===          is guaranteed to work on *all* Win32 variants.
00017 //===----------------------------------------------------------------------===//
00018 
00019 // Require at least Windows 2000 API.
00020 #define _WIN32_WINNT 0x0500
00021 
00022 #include "llvm/Config/config.h"     // Get autoconf configuration settings
00023 #include "windows.h"
00024 #include <cassert>
00025 #include <string>
00026 
00027 inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
00028   if (!ErrMsg)
00029     return true;
00030   char *buffer = NULL;
00031   FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
00032       NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
00033   *ErrMsg = prefix + buffer;
00034   LocalFree(buffer);
00035   return true;
00036 }
00037 
00038 class AutoHandle {
00039   HANDLE handle;
00040 
00041 public:
00042   AutoHandle(HANDLE h) : handle(h) {}
00043 
00044   ~AutoHandle() {
00045     if (handle)
00046       CloseHandle(handle);
00047   }
00048 
00049   operator HANDLE() {
00050     return handle;
00051   }
00052 
00053   AutoHandle &operator=(HANDLE h) {
00054     handle = h;
00055     return *this;
00056   }
00057 };