| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkDynamicLoader.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:35 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkDynamicLoader_h |
| 18 |
|
#define __itkDynamicLoader_h |
| 19 |
|
|
| 20 |
|
#include "itkMacro.h" |
| 21 |
|
|
| 22 |
|
// Ugly stuff for library handles. |
| 23 |
|
// They are different on several different OS's |
| 24 |
|
#if defined(__hpux) |
| 25 |
|
# include <dl.h> |
| 26 |
|
namespace itk |
| 27 |
|
{ |
| 28 |
|
typedef shl_t LibHandle; |
| 29 |
|
} // end namespace itk |
| 30 |
|
#elif defined(_WIN32) |
| 31 |
|
#include "itkWindows.h" |
| 32 |
|
|
| 33 |
|
namespace itk |
| 34 |
|
{ |
| 35 |
|
typedef HMODULE LibHandle; |
| 36 |
|
} // end namespace itk |
| 37 |
|
#else |
| 38 |
|
namespace itk |
| 39 |
|
{ |
| 40 |
|
typedef void* LibHandle; |
| 41 |
|
} // end namespace itk |
| 42 |
|
#endif |
| 43 |
|
|
| 44 |
|
#include "itkObject.h" |
| 45 |
|
#include "itkObjectFactory.h" |
| 46 |
|
|
| 47 |
|
namespace itk |
| 48 |
|
{ |
| 49 |
|
|
| 50 |
|
/** \class DynamicLoader |
| 51 |
|
* \brief Portable loading of dynamic libraries or dll's. |
| 52 |
|
* |
| 53 |
|
* DynamicLoader provides a portable interface to loading dynamic |
| 54 |
|
* libraries or dll's into a process. |
| 55 |
|
* |
| 56 |
|
* \ingroup OSSystemObjects |
| 57 |
|
*/ |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
class ITKCommon_EXPORT DynamicLoader : public Object |
| 61 |
|
{ |
| 62 |
|
public: |
| 63 |
|
/** Standard class typedefs. */ |
| 64 |
|
typedef DynamicLoader Self; |
| 65 |
TDA |
typedef Object Superclass; |
| 66 |
|
typedef SmartPointer<Self> Pointer; |
| 67 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 68 |
|
|
| 69 |
|
/** Method for creation through the object factory. */ |
| 70 |
|
itkNewMacro(Self); |
| 71 |
|
|
| 72 |
|
/** Run-time type information (and related methods). */ |
| 73 |
|
itkTypeMacro(DynamicLoader,Object); |
| 74 |
|
|
| 75 |
|
/** Load a dynamic library into the current process. |
| 76 |
|
* The returned LibHandle can be used to access the symbols in the |
| 77 |
|
* library. */ |
| 78 |
|
static LibHandle OpenLibrary(const char*); |
| 79 |
|
|
| 80 |
|
/** Attempt to detach a dynamic library from the |
| 81 |
|
* process. A value of true is returned if it is sucessful. */ |
| 82 |
|
static int CloseLibrary(LibHandle); |
| 83 |
|
|
| 84 |
|
/** Find the address of the symbol in the given library. */ |
| 85 |
|
static void* GetSymbolAddress(LibHandle, const char*); |
| 86 |
|
|
| 87 |
|
/** Return the library prefix for the given architecture */ |
| 88 |
|
static const char* LibPrefix(); |
| 89 |
|
|
| 90 |
|
/** Return the library extension for the given architecture. */ |
| 91 |
|
static const char* LibExtension(); |
| 92 |
|
|
| 93 |
|
/** Return the last error produced from a calls made on this class. */ |
| 94 |
|
static const char* LastError(); |
| 95 |
|
|
| 96 |
|
protected: |
| 97 |
|
DynamicLoader(); |
| 98 |
|
~DynamicLoader(); |
| 99 |
|
|
| 100 |
|
private: |
| 101 |
|
DynamicLoader(const Self&); //purposely not implemented |
| 102 |
|
void operator=(const Self&); //purposely not implemented |
| 103 |
|
|
| 104 |
|
}; |
| 105 |
|
|
| 106 |
|
} // end namespace itk |
| 107 |
|
|
| 108 |
|
#endif |
| 109 |
|
|