LLVM API Documentation
00001 //===- Win32/DynamicLibrary.cpp - Win32 DL Implementation -------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Reid Spencer and is distributed under the 00006 // University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file provides the Win32 specific implementation of the DynamicLibrary 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "Win32.h" 00015 #include <windef.h> 00016 00017 namespace llvm { 00018 using namespace sys; 00019 00020 //===----------------------------------------------------------------------===// 00021 //=== WARNING: Implementation here must contain only Win32 specific code 00022 //=== and must not be UNIX code 00023 //===----------------------------------------------------------------------===// 00024 00025 DynamicLibrary::DynamicLibrary() : handle(0) { 00026 handle = new HMODULE; 00027 *((HMODULE*)handle) = GetModuleHandle(NULL); 00028 00029 if (*((HMODULE*)handle) == 0) { 00030 ThrowError("Can't GetModuleHandle: "); 00031 } 00032 } 00033 00034 DynamicLibrary::DynamicLibrary(const char*filename) : handle(0) { 00035 handle = new HMODULE; 00036 *((HMODULE*)handle) = LoadLibrary(filename); 00037 00038 if (*((HMODULE*)handle) == 0) { 00039 ThrowError("Can't LoadLibrary: "); 00040 } 00041 } 00042 00043 DynamicLibrary::~DynamicLibrary() { 00044 assert(handle !=0 && "Invalid DynamicLibrary handle"); 00045 if (*((HMODULE*)handle)) 00046 FreeLibrary(*((HMODULE*)handle)); 00047 delete (HMODULE*)handle; 00048 } 00049 00050 void *DynamicLibrary::GetAddressOfSymbol(const char *symbolName) { 00051 assert(handle !=0 && "Invalid DynamicLibrary handle"); 00052 return (void*) GetProcAddress(*((HMODULE*)handle), symbolName); 00053 } 00054 00055 } 00056 00057 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab