blob: 15730d43a01ef557f70b039b69d0dc93610e52fe [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
24DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
25 handle = LoadLibrary(filename);
26
27 if (handle == 0) {
28 char Buffer[100];
29 // FIXME: This should use FormatMessage
30 sprintf(Buffer, "Windows error code %d\n", GetLastError());
31 throw std::string(Buffer);
32 }
33}
34
35DynamicLibrary::~DynamicLibrary() {
36 if (handle)
37 FreeLibrary(handle);
38}
39
40void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
41 assert(handle !=0 && "Invalid DynamicLibrary handle");
42 return GetProcAddress(handle, symbolName);
43}
44
45}
46
47// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab