PLplot  5.15.0
ltdl_win32.c
Go to the documentation of this file.
1 // Contains all prototypes for driver functions.
2 //
3 // Copyright (C) 2008 Werner Smekal
4 //
5 // This file is part of PLplot.
6 //
7 // PLplot is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // PLplot is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with PLplot; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 //
22 
27 
28 #include <windows.h>
29 #include <stdlib.h>
30 #include "ltdl_win32.h"
31 #include "plplot.h"
32 
33 // (static) pointer to the last handle, which contains a pointer
34 // to a possible previous handle
36 
37 // buffer for error messages
38 char errortext[512];
39 
40 
43 void lt_dlinit( void )
44 {
45  lastHandle = NULL;
46 }
47 
48 
51 void lt_dlexit( void )
52 {
53  lt_dlhandle prev;
54 
55  while ( lastHandle != NULL )
56  {
57  if ( lastHandle->hinstLib )
58  FreeLibrary( lastHandle->hinstLib );
59  prev = lastHandle->previousHandle;
60  free( lastHandle );
61  lastHandle = prev;
62  }
63 }
64 
65 
74 lt_dlhandle lt_dlopenext( char* dllname )
75 {
76  lt_dlhandle dlhandle = (lt_dlhandle) malloc( sizeof ( struct __dlhandle ) );
77  memset( dlhandle, '\0', sizeof ( struct __dlhandle ) );
78 
79  dlhandle->hinstLib = LoadLibraryA( dllname );
80  if ( !dlhandle->hinstLib )
81  {
82  free( dlhandle );
83  return NULL;
84  }
85 
86  dlhandle->previousHandle = lastHandle;
87  lastHandle = dlhandle;
88 
89  return dlhandle;
90 }
91 
92 
98 {
99  strncpy( errortext, "No error information", 512 );
100 
101  return errortext;
102 }
103 
104 
112 void* lt_dlsym( lt_dlhandle dlhandle, PLCHAR_VECTOR symbol )
113 {
114  if ( dlhandle->hinstLib )
115  {
116 #ifdef __BORLANDC__
117  unsigned int bufferLength = strlen( symbol ) + 2;
118  char * buffer = (char *) malloc( bufferLength );
119  void * retPointer;
120 
121  buffer[0] = '_';
122  strncpy( &buffer[1], symbol, bufferLength - 2 );
123  buffer[bufferLength - 1] = '\0';
124  retPointer = GetProcAddress( dlhandle->hinstLib, buffer );
125  free( buffer );
126  return retPointer;
127 #else
128  return GetProcAddress( dlhandle->hinstLib, symbol );
129 #endif
130  }
131  else
132  return NULL;
133 }
134 
142 {
143  return 0;
144 }
HINSTANCE hinstLib
Definition: ltdl_win32.h:31
const char * PLCHAR_VECTOR
Definition: plplot.h:243
char errortext[512]
Definition: ltdl_win32.c:38
lt_dlhandle lastHandle
Definition: ltdl_win32.c:35
void lt_dlexit(void)
Definition: ltdl_win32.c:51
int lt_dlmakeresident(lt_dlhandle handle)
Definition: ltdl_win32.c:141
struct __dlhandle * previousHandle
Definition: ltdl_win32.h:32
static PLINT * buffer
Definition: plfill.c:74
lt_dlhandle lt_dlopenext(char *dllname)
Definition: ltdl_win32.c:74
PLCHAR_VECTOR lt_dlerror()
Definition: ltdl_win32.c:97
void lt_dlinit(void)
Definition: ltdl_win32.c:43
struct __dlhandle * lt_dlhandle
Definition: ltdl_win32.h:34
void * lt_dlsym(lt_dlhandle dlhandle, PLCHAR_VECTOR symbol)
Definition: ltdl_win32.c:112