PLplot 5.9.6
|
00001 /* $Id$ 00002 * 00003 * Contains all prototypes for driver functions. 00004 * 00005 * Copyright (C) 2008 Werner Smekal 00006 * 00007 * This file is part of PLplot. 00008 * 00009 * PLplot is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU Library General Public License as published 00011 * by the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * PLplot is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU Library General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Library General Public License 00020 * along with PLplot; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 */ 00024 00025 #include <windows.h> 00026 #include <stdlib.h> 00027 #include "ltdl_win32.h" 00028 00029 /* (static) pointer to the last handle, which contains a pointer 00030 * to a possible previous handle */ 00031 lt_dlhandle lastHandle = NULL; 00032 00033 /* buffer for error messages */ 00034 char errortext[512]; 00035 00036 00037 /* initialise variables */ 00038 void lt_dlinit( void ) 00039 { 00040 lastHandle = NULL; 00041 } 00042 00043 00044 /* on exit free library handles and release allocate memory */ 00045 void lt_dlexit( void ) 00046 { 00047 lt_dlhandle prev; 00048 00049 while ( lastHandle != NULL ) 00050 { 00051 if ( lastHandle->hinstLib ) 00052 FreeLibrary( lastHandle->hinstLib ); 00053 prev = lastHandle->previousHandle; 00054 free( lastHandle ); 00055 lastHandle = prev; 00056 } 00057 } 00058 00059 00060 /* try to open shared library with given dllname. If there is 00061 * no extension given LoadLibrary() assumes .dll. The library 00062 * must be somewhere in the path or in the current directory. */ 00063 lt_dlhandle lt_dlopenext( char* dllname ) 00064 { 00065 lt_dlhandle dlhandle = malloc( sizeof ( struct __dlhandle ) ); 00066 memset( dlhandle, '\0', sizeof ( struct __dlhandle ) ); 00067 00068 dlhandle->hinstLib = LoadLibrary( dllname ); 00069 if ( !dlhandle->hinstLib ) 00070 { 00071 free( dlhandle ); 00072 return NULL; 00073 } 00074 00075 dlhandle->previousHandle = lastHandle; 00076 lastHandle = dlhandle; 00077 00078 return dlhandle; 00079 } 00080 00081 00082 /* return last error occured. Needs some work :). */ 00083 const char* lt_dlerror() 00084 { 00085 strncpy( errortext, "No error information", 512 ); 00086 00087 return errortext; 00088 } 00089 00090 00091 /* load symbol from library */ 00092 void* lt_dlsym( lt_dlhandle dlhandle, const char* symbol ) 00093 { 00094 if ( dlhandle->hinstLib ) 00095 { 00096 #ifdef __BORLANDC__ 00097 unsigned int bufferLength = strlen( symbol ) + 2; 00098 char * buffer = (char*) malloc( bufferLength ); 00099 void * retPointer; 00100 00101 buffer[0] = '_'; 00102 strncpy( &buffer[1], symbol, bufferLength - 2 ); 00103 buffer[bufferLength - 1] = '\0'; 00104 retPointer = GetProcAddress( dlhandle->hinstLib, buffer ); 00105 free( buffer ); 00106 return retPointer; 00107 #else 00108 return GetProcAddress( dlhandle->hinstLib, symbol ); 00109 #endif 00110 } 00111 else 00112 return NULL; 00113 }