PTLib  Version 2.18.8
 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 
30 #ifndef PTLIB_DYNALINK_H
31 #define PTLIB_DYNALINK_H
32 
33 #if !defined(P_RTEMS)
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
47 class PDynaLink : public PObject
48 {
49  PCLASSINFO(PDynaLink, PObject);
50 
51  public:
57  PDynaLink();
61  PDynaLink(
62  const PString & name
63  );
64 
67  ~PDynaLink();
69 
72  /* Open a new dyna-link, loading the specified module.
73  The \p names string is a '\n' separated list of DLL names to attempt
74  to load. The first one found is used.
75 
76  @return
77  true if the library was loaded.
78  */
79  virtual PBoolean Open(
80  const PString & names
81  );
82 
85  virtual void Close();
86 
89  virtual PBoolean IsLoaded() const;
90 
100  virtual PString GetName(
101  PBoolean full = false
102  ) const;
103 
109  static PString GetExtension();
111 
114  typedef void (*Function)();
116 
117 
124  PINDEX index,
125  Function & func,
126  bool compulsory = false
127  );
128 
135  const PString & name,
136  Function & func,
137  bool compulsory = false
138  );
139 
141  const PString & GetLastError() const { return m_lastError; }
143 
149  template <typename FuncPtr>
150  class EntryPoint {
151  protected:
152  FuncPtr m_function;
153  public :
155  PDynaLink & dll,
156  const char * name,
157  bool compulsory = true
158  ) {
159  Function fn;
160  if (dll.GetFunction(name, fn, compulsory))
161  m_function = reinterpret_cast<FuncPtr>(fn);
162  else
163  m_function = NULL;
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  #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 ///////////////////////////////////////////////////////////////
#define PAssertNULL(ptr)
This macro is used to assert that a pointer must be non-null.
Definition: object.h:428
bool PBoolean
Definition: object.h:174
The character string class.
Definition: pstring.h:108
Ultimate parent class for all objects in the class library.
Definition: object.h:2204