Fix residual Visual Studio build problems
[oota-llvm.git] / lib / System / Win32 / DynamicLibrary.cpp
1 //===- Win32/DynamicLibrary.cpp - Win32 DL Implementation -------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the 
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides the Win32 specific implementation of the DynamicLibrary
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "Win32.h"
15
16 namespace llvm {
17 using namespace sys;
18
19 //===----------------------------------------------------------------------===//
20 //=== WARNING: Implementation here must contain only Win32 specific code 
21 //===          and must not be UNIX code
22 //===----------------------------------------------------------------------===//
23
24 DynamicLibrary::DynamicLibrary() : handle(0) {
25   handle = (void*) GetModuleHandle(NULL);
26   
27   if (handle == 0) {
28     ThrowError("Can't GetModuleHandle: ");
29   }
30 }
31
32 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
33   handle = LoadLibrary(filename);
34
35   if (handle == 0) {
36     ThrowError("Can't LoadLibrary: ");
37   }
38 }
39
40 DynamicLibrary::~DynamicLibrary() {
41   assert(handle !=0 && "Invalid DynamicLibrary handle");
42   if (handle)
43     FreeLibrary((HMODULE*)handle);
44 }
45
46 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
47   assert(handle !=0 && "Invalid DynamicLibrary handle");
48   return (void*) GetProcAddress((HMODULE*)handle, symbolName);
49 }
50
51 }
52
53 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab