1 //===- Win32/DynamicLibrary.cpp - Win32 DL Implementation -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file provides the Win32 specific implementation of the DynamicLibrary
12 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
21 //=== WARNING: Implementation here must contain only Win32 specific code
22 //=== and must not be UNIX code
23 //===----------------------------------------------------------------------===//
25 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) {
27 *((HMODULE*)handle) = LoadLibrary(filename);
29 if (*((HMODULE*)handle) == 0) {
31 // FIXME: This should use FormatMessage
32 sprintf(Buffer, "Windows error code %d\n", GetLastError());
33 throw std::string(Buffer);
37 DynamicLibrary::~DynamicLibrary() {
38 assert(handle !=0 && "Invalid DynamicLibrary handle");
39 if (*((HMODULE*)handle))
40 FreeLibrary(*((HMODULE*)handle));
41 delete (HMODULE*)handle;
44 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) {
45 assert(handle !=0 && "Invalid DynamicLibrary handle");
46 return (void*) GetProcAddress(*((HMODULE*)handle), symbolName);
51 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab