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