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 // 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 
32 // (static) pointer to the last handle, which contains a pointer
33 // to a possible previous handle
35 
36 // buffer for error messages
37 char errortext[512];
38 
39 
42 void lt_dlinit( void )
43 {
44  lastHandle = NULL;
45 }
46 
47 
50 void lt_dlexit( void )
51 {
52  lt_dlhandle prev;
53 
54  while ( lastHandle != NULL )
55  {
56  if ( lastHandle->hinstLib )
57  FreeLibrary( lastHandle->hinstLib );
58  prev = lastHandle->previousHandle;
59  free( lastHandle );
60  lastHandle = prev;
61  }
62 }
63 
64 
73 lt_dlhandle lt_dlopenext( char* dllname )
74 {
75  lt_dlhandle dlhandle = malloc( sizeof ( struct __dlhandle ) );
76  memset( dlhandle, '\0', sizeof ( struct __dlhandle ) );
77 
78  dlhandle->hinstLib = LoadLibrary( dllname );
79  if ( !dlhandle->hinstLib )
80  {
81  free( dlhandle );
82  return NULL;
83  }
84 
85  dlhandle->previousHandle = lastHandle;
86  lastHandle = dlhandle;
87 
88  return dlhandle;
89 }
90 
91 
96 const char* lt_dlerror()
97 {
98  strncpy( errortext, "No error information", 512 );
99 
100  return errortext;
101 }
102 
103 
111 void* lt_dlsym( lt_dlhandle dlhandle, const char* symbol )
112 {
113  if ( dlhandle->hinstLib )
114  {
115 #ifdef __BORLANDC__
116  unsigned int bufferLength = strlen( symbol ) + 2;
117  char * buffer = (char *) malloc( bufferLength );
118  void * retPointer;
119 
120  buffer[0] = '_';
121  strncpy( &buffer[1], symbol, bufferLength - 2 );
122  buffer[bufferLength - 1] = '\0';
123  retPointer = GetProcAddress( dlhandle->hinstLib, buffer );
124  free( buffer );
125  return retPointer;
126 #else
127  return GetProcAddress( dlhandle->hinstLib, symbol );
128 #endif
129  }
130  else
131  return NULL;
132 }
133 
141 {
142  return 0;
143 }