blob: cc3376eedf9ef758cfeb6ecbfe91317b611f54bd [file] [log] [blame]
Reid Spencer0de02a62004-11-18 04:33:39 +00001//===- 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
16namespace llvm {
17using namespace sys;
18
19//===----------------------------------------------------------------------===//
20//=== WARNING: Implementation here must contain only Win32 specific code
21//=== and must not be UNIX code
22//===----------------------------------------------------------------------===//
23
Reid Spencer441cc2a2004-11-29 10:39:46 +000024DynamicLibrary::DynamicLibrary() : handle(0) {
Jeff Cohen31127e12004-12-09 05:51:11 +000025 handle = (void*) GetModuleHandle(NULL);
Reid Spencer441cc2a2004-11-29 10:39:46 +000026
Jeff Cohen31127e12004-12-09 05:51:11 +000027 if (handle == 0) {
Reid Spencer441cc2a2004-11-29 10:39:46 +000028 ThrowError("Can't GetModuleHandle: ");
29 }
30}
31
Reid Spencer0de02a62004-11-18 04:33:39 +000032DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
Jeff Cohen31127e12004-12-09 05:51:11 +000033 handle = LoadLibrary(filename);
Reid Spencer0de02a62004-11-18 04:33:39 +000034
Jeff Cohen31127e12004-12-09 05:51:11 +000035 if (handle == 0) {
Reid Spencer441cc2a2004-11-29 10:39:46 +000036 ThrowError("Can't LoadLibrary: ");
Reid Spencer0de02a62004-11-18 04:33:39 +000037 }
38}
39
40DynamicLibrary::~DynamicLibrary() {
Reid Spencer7a453892004-11-20 23:30:55 +000041 assert(handle !=0 && "Invalid DynamicLibrary handle");
Jeff Cohen31127e12004-12-09 05:51:11 +000042 if (handle)
43 FreeLibrary((HMODULE*)handle);
Reid Spencer0de02a62004-11-18 04:33:39 +000044}
45
46void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
47 assert(handle !=0 && "Invalid DynamicLibrary handle");
Jeff Cohen31127e12004-12-09 05:51:11 +000048 return (void*) GetProcAddress((HMODULE*)handle, symbolName);
Reid Spencer0de02a62004-11-18 04:33:39 +000049}
50
51}
52
53// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab