PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dynalink.h
Go to the documentation of this file.
1 /*
2  * dynalink.h
3  *
4  * Dynamic Link Library abstraction class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 30333 $
30  * $Author: rjongbloed $
31  * $Date: 2013-08-17 14:15:45 +1000 (Sat, 17 Aug 2013) $
32  */
33 
34 #ifndef PTLIB_DYNALINK_H
35 #define PTLIB_DYNALINK_H
36 
37 #if !defined(P_RTEMS)
38 
39 #ifdef P_USE_PRAGMA
40 #pragma interface
41 #endif
42 
51 class PDynaLink : public PObject
52 {
53  PCLASSINFO(PDynaLink, PObject);
54 
55  public:
61  PDynaLink();
65  PDynaLink(
66  const PString & name
67  );
68 
71  ~PDynaLink();
73 
76  /* Open a new dyna-link, loading the specified module.
77  The \p names string is a '\n' separated list of DLL names to attempt
78  to load. The first one found is used.
79 
80  @return
81  true if the library was loaded.
82  */
83  virtual PBoolean Open(
84  const PString & names
85  );
86 
89  virtual void Close();
90 
93  virtual PBoolean IsLoaded() const;
94 
104  virtual PString GetName(
105  PBoolean full = false
106  ) const;
107 
113  static PString GetExtension();
115 
118 
119  typedef void (*Function)();
120 
121 
128  PINDEX index,
129  Function & func,
130  bool compulsory = false
131  );
132 
139  const PString & name,
140  Function & func,
141  bool compulsory = false
142  );
143 
145  const PString & GetLastError() const { return m_lastError; }
147 
153  template <typename FuncPtr>
154  class EntryPoint {
155  protected:
156  FuncPtr m_function;
157  public :
159  PDynaLink & dll,
160  const char * name,
161  bool compulsory = true
162  ) {
163  dll.GetFunction(name, (Function &)m_function, compulsory);
164  }
165 
166  bool IsPresent() const { return m_function != NULL; }
167  operator FuncPtr() const { return PAssertNULL(m_function); }
168  };
170  #define P_DYNALINK_ENTRY_POINT(name) P_DISABLE_MSVC_WARNINGS(4355, name(*this, #name))
171 
172  #define P_DYNALINK_OPTIONAL_ENTRY_POINT(name) P_DISABLE_MSVC_WARNINGS(4355, name(*this, #name, false))
173 
174  protected:
176 
177 // Include platform dependent part of class
178 #ifdef _WIN32
179 #include "msos/ptlib/dynalink.h"
180 #else
181 #include "unix/ptlib/dynalink.h"
182 #endif
183 };
184 
185 #endif // !defined(P_RTEMS)
186 
187 
188 #endif //PTLIB_DYNALINK_H
189 
190 
191 // End Of File ///////////////////////////////////////////////////////////////