Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

cplgetsymbol.cpp

00001 /******************************************************************************
00002  * $Id: cplgetsymbol_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $
00003  *
00004  * Project:  Common Portability Library
00005  * Purpose:  Fetch a function pointer from a shared library / DLL.
00006  * Author:   Frank Warmerdam, warmerda@home.com
00007  *
00008  ******************************************************************************
00009  * Copyright (c) 1999, Frank Warmerdam
00010  *
00011  * Permission is hereby granted, free of charge, to any person obtaining a
00012  * copy of this software and associated documentation files (the "Software"),
00013  * to deal in the Software without restriction, including without limitation
00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00015  * and/or sell copies of the Software, and to permit persons to whom the
00016  * Software is furnished to do so, subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be included
00019  * in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00027  * DEALINGS IN THE SOFTWARE.
00028  ******************************************************************************
00029  *
00030  * $Log: cplgetsymbol_cpp-source.html,v $
00030  * Revision 1.10  2002/04/16 13:11:48  warmerda
00030  * updated
00030  *
00031  * Revision 1.11  2001/07/18 04:00:49  warmerda
00032  * added CPL_CVSID
00033  *
00034  * Revision 1.10  2001/01/19 21:16:41  warmerda
00035  * expanded tabs
00036  *
00037  * Revision 1.9  2000/09/25 19:59:03  warmerda
00038  * look for WIN32 not _WIN32
00039  *
00040  * Revision 1.8  1999/05/20 02:54:38  warmerda
00041  * Added API documentation
00042  *
00043  * Revision 1.7  1999/04/23 13:56:36  warmerda
00044  * added stub implementation.  Don't check for __unix__
00045  *
00046  * Revision 1.6  1999/04/21 20:06:05  warmerda
00047  * Removed incorrect comment.
00048  *
00049  * Revision 1.5  1999/03/02 21:20:00  warmerda
00050  * test for dlfcn.h, not -ldl
00051  *
00052  * Revision 1.4  1999/03/02 21:08:11  warmerda
00053  * autoconf switch
00054  *
00055  * Revision 1.3  1999/01/28 18:35:44  warmerda
00056  * minor windows cleanup.
00057  *
00058  * Revision 1.2  1999/01/27 20:16:03  warmerda
00059  * Added windows implementation.
00060  *
00061  * Revision 1.1  1999/01/11 15:34:57  warmerda
00062  * New
00063  *
00064  */
00065 
00066 #include "cpl_conv.h"
00067 
00068 CPL_CVSID("$Id: cplgetsymbol_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $");
00069 
00070 /* ==================================================================== */
00071 /*                  Unix Implementation                                 */
00072 /* ==================================================================== */
00073 #if defined(HAVE_DLFCN_H)
00074 
00075 #define GOT_GETSYMBOL
00076 
00077 #include <dlfcn.h>
00078 
00079 /************************************************************************/
00080 /*                            CPLGetSymbol()                            */
00081 /************************************************************************/
00082 
00116 void *CPLGetSymbol( const char * pszLibrary, const char * pszSymbolName )
00117 
00118 {
00119     void        *pLibrary;
00120     void        *pSymbol;
00121 
00122     pLibrary = dlopen(pszLibrary, RTLD_LAZY);
00123     if( pLibrary == NULL )
00124     {
00125         CPLError( CE_Failure, CPLE_AppDefined,
00126                   "%s", dlerror() );
00127         return NULL;
00128     }
00129 
00130     pSymbol = dlsym( pLibrary, pszSymbolName );
00131 
00132     if( pSymbol == NULL )
00133     {
00134         CPLError( CE_Failure, CPLE_AppDefined,
00135                   "%s", dlerror() );
00136         return NULL;
00137     }
00138     
00139     return( pSymbol );
00140 }
00141 
00142 #endif /* def __unix__ && defined(HAVE_DLFCN_H) */
00143 
00144 /* ==================================================================== */
00145 /*                 Windows Implementation                               */
00146 /* ==================================================================== */
00147 #ifdef WIN32
00148 
00149 #define GOT_GETSYMBOL
00150 
00151 #include <windows.h>
00152 
00153 /************************************************************************/
00154 /*                            CPLGetSymbol()                            */
00155 /************************************************************************/
00156 
00157 void *CPLGetSymbol( const char * pszLibrary, const char * pszSymbolName )
00158 
00159 {
00160     void        *pLibrary;
00161     void        *pSymbol;
00162 
00163     pLibrary = LoadLibrary(pszLibrary);
00164     if( pLibrary == NULL )
00165     {
00166         CPLError( CE_Failure, CPLE_AppDefined,
00167                   "Can't load requested DLL: %s", pszLibrary );
00168         return NULL;
00169     }
00170 
00171     pSymbol = GetProcAddress( (HINSTANCE) pLibrary, pszSymbolName );
00172 
00173     if( pSymbol == NULL )
00174     {
00175         CPLError( CE_Failure, CPLE_AppDefined,
00176                   "Can't find requested entry point: %s\n", pszSymbolName );
00177         return NULL;
00178     }
00179     
00180     return( pSymbol );
00181 }
00182 
00183 #endif /* def _WIN32 */
00184 
00185 /* ==================================================================== */
00186 /*      Dummy implementation.                                           */
00187 /* ==================================================================== */
00188 
00189 #ifndef GOT_GETSYMBOL
00190 
00191 /************************************************************************/
00192 /*                            CPLGetSymbol()                            */
00193 /*                                                                      */
00194 /*      Dummy implementation.                                           */
00195 /************************************************************************/
00196 
00197 void *CPLGetSymbol(const char *, const char *)
00198 
00199 {
00200     return NULL;
00201 }
00202 #endif

Generated at Thu Mar 28 09:47:28 2002 for GDAL by doxygen1.2.3-20001105 written by Dimitri van Heesch, © 1997-2000