kodi
DynamicDll.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "DllPaths.h"
12 #include "cores/DllLoader/LibraryLoader.h"
13 
14 #include <string>
15 
17 //
18 // DECLARE_DLL_WRAPPER
19 //
20 // Declares the constructor of the wrapper class.
21 // This must be followed by one or more
22 // DEFINE_METHODX/DEFINE_METHOD_LINKAGEX and
23 // one BEGIN_METHOD_RESOLVE/END_METHOD_RESOLVE block.
24 //
25 // classname: name of the wrapper class to construct
26 // dllname: file including path of the dll to wrap
27 
28 #define DECLARE_DLL_WRAPPER(classname, dllname) \
29 XDECLARE_DLL_WRAPPER(classname,dllname)
30 
31 #define XDECLARE_DLL_WRAPPER(classname, dllname) \
32 public: \
33  classname () : DllDynamic( dllname ) {}
34 
36 //
37 // DECLARE_DLL_WRAPPER_TEMPLATE_BEGIN
38 //
39 // Declares the constructor of the wrapper class.
40 // The method SetFile(strDllName) can be used to set the
41 // dll of this wrapper.
42 // This must be followed by one or more
43 // DEFINE_METHODX/DEFINE_METHOD_LINKAGEX and
44 // one BEGIN_METHOD_RESOLVE/END_METHOD_RESOLVE block.
45 //
46 // classname: name of the wrapper class to construct
47 //
48 #define DECLARE_DLL_WRAPPER_TEMPLATE(classname) \
49 public: \
50  classname () {} \
51 
52 
54 //
55 // LOAD_SYMBOLS
56 //
57 // Tells the dllloader to load Debug symbols when possible
58 #define LOAD_SYMBOLS() \
59  protected: \
60  virtual bool LoadSymbols() { return true; }
61 
63 //
64 // DEFINE_GLOBAL
65 //
66 // Defines a global for export from the dll as well as
67 // a function for accessing it (Get_name).
68 //
69 // type: The variables type.
70 // name: Name of the variable.
71 //
72 
73 #define DEFINE_GLOBAL_PTR(type, name) \
74  protected: \
75  union { \
76  type* m_##name; \
77  void* m_##name##_ptr; \
78  }; \
79  public: \
80  virtual type* Get_##name (void) \
81  { \
82  return m_##name; \
83  }
84 
85 #define DEFINE_GLOBAL(type, name) \
86  protected: \
87  union { \
88  type* m_##name; \
89  void* m_##name##_ptr; \
90  }; \
91  public: \
92  virtual type Get_##name (void) \
93  { \
94  return *m_##name; \
95  }
96 
98 //
99 // DEFINE_METHOD_LINKAGE
100 //
101 // Defines a function for an export from a dll, if the
102 // calling convention is not __cdecl.
103 // Use DEFINE_METHOD_LINKAGE for each function to be resolved.
104 //
105 // result: Result of the function
106 // linkage: Calling convention of the function
107 // name: Name of the function
108 // args: Arguments of the function, enclosed in parentheses
109 //
110 #define DEFINE_METHOD_LINKAGE_FP(result, linkage, name, args) \
111  protected: \
112  typedef result (linkage * name##_METHOD) args; \
113  public: \
114  union { \
115  name##_METHOD m_##name; \
116  void* m_##name##_ptr; \
117  };
118 
119 #define DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, args2) \
120  protected: \
121  typedef result (linkage * name##_METHOD) args; \
122  union { \
123  name##_METHOD m_##name; \
124  void* m_##name##_ptr; \
125  }; \
126  public: \
127  virtual result name args override \
128  { \
129  return m_##name ? m_##name args2 : (result) 0; \
130  }
131 
132 #define DEFINE_METHOD_LINKAGE0(result, linkage, name) \
133  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, () , ())
134 
135 #define DEFINE_METHOD_LINKAGE1(result, linkage, name, args) \
136  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1))
137 
138 #define DEFINE_METHOD_LINKAGE2(result, linkage, name, args) \
139  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2))
140 
141 #define DEFINE_METHOD_LINKAGE3(result, linkage, name, args) \
142  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3))
143 
144 #define DEFINE_METHOD_LINKAGE4(result, linkage, name, args) \
145  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4))
146 
147 #define DEFINE_METHOD_LINKAGE5(result, linkage, name, args) \
148  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5))
149 
150 #define DEFINE_METHOD_LINKAGE6(result, linkage, name, args) \
151  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5, p6))
152 
153 #define DEFINE_METHOD_LINKAGE7(result, linkage, name, args) \
154  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5, p6, p7))
155 
156 #define DEFINE_METHOD_LINKAGE8(result, linkage, name, args) \
157  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5, p6, p7, p8))
158 
159 #define DEFINE_METHOD_LINKAGE9(result, linkage, name, args) \
160  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5, p6, p7, p8, p9))
161 
162 #define DEFINE_METHOD_LINKAGE10(result, linkage, name, args) \
163  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10))
164 
165 #define DEFINE_METHOD_LINKAGE11(result, linkage, name, args) \
166  DEFINE_METHOD_LINKAGE_BASE(result, linkage, name, args, (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11))
167 
169 //
170 // DEFINE_METHOD_FP
171 //
172 // Defines a function for an export from a dll as a function pointer.
173 // Use DEFINE_METHOD_FP for each function to be resolved. Functions
174 // defined like this are not listed by IntelliSence.
175 //
176 // result: Result of the function
177 // name: Name of the function
178 // args: Arguments of the function, enclosed in parentheses
179 // The parameter names can be anything
180 //
181 #define DEFINE_METHOD_FP(result, name, args) DEFINE_METHOD_LINKAGE_FP(result, __cdecl, name, args)
182 
184 //
185 // DEFINE_METHODX
186 //
187 // Defines a function for an export from a dll.
188 // Use DEFINE_METHODX for each function to be resolved.
189 // where X is the number of parameter the function has.
190 //
191 // result: Result of the function
192 // name: Name of the function
193 // args: Arguments of the function, enclosed in parentheses
194 // The parameter names have to be renamed to px, where
195 // x is the number of the parameter
196 //
197 #define DEFINE_METHOD0(result, name) DEFINE_METHOD_LINKAGE0(result, __cdecl, name)
198 #define DEFINE_METHOD1(result, name, args) DEFINE_METHOD_LINKAGE1(result, __cdecl, name, args)
199 #define DEFINE_METHOD2(result, name, args) DEFINE_METHOD_LINKAGE2(result, __cdecl, name, args)
200 #define DEFINE_METHOD3(result, name, args) DEFINE_METHOD_LINKAGE3(result, __cdecl, name, args)
201 #define DEFINE_METHOD4(result, name, args) DEFINE_METHOD_LINKAGE4(result, __cdecl, name, args)
202 #define DEFINE_METHOD5(result, name, args) DEFINE_METHOD_LINKAGE5(result, __cdecl, name, args)
203 #define DEFINE_METHOD6(result, name, args) DEFINE_METHOD_LINKAGE6(result, __cdecl, name, args)
204 #define DEFINE_METHOD7(result, name, args) DEFINE_METHOD_LINKAGE7(result, __cdecl, name, args)
205 #define DEFINE_METHOD8(result, name, args) DEFINE_METHOD_LINKAGE8(result, __cdecl, name, args)
206 #define DEFINE_METHOD9(result, name, args) DEFINE_METHOD_LINKAGE9(result, __cdecl, name, args)
207 #define DEFINE_METHOD10(result, name, args) DEFINE_METHOD_LINKAGE10(result, __cdecl, name, args)
208 #define DEFINE_METHOD11(result, name, args) DEFINE_METHOD_LINKAGE11(result, __cdecl, name, args)
209 
210 #ifdef TARGET_WINDOWS
211 //
213 // DEFINE_FUNC_ALIGNED 0-X
214 //
215 // Defines a function for an export from a dll, which
216 // requires an aligned stack on function call
217 // Use DEFINE_FUNC_ALIGNED for each function to be resolved.
218 //
219 // result: Result of the function
220 // linkage: Calling convention of the function
221 // name: Name of the function
222 // args: Argument types of the function
223 //
224 // Actual function call will expand to something like this
225 // this will align the stack (esp) at the point of function
226 // entry as required by gcc compiled dlls, it is a bit obfuscated
227 // to allow for different sized variables
228 //
229 // int64_t test(int64_t p1, char p2, char p3)
230 // {
231 // int o,s = ((sizeof(p1)+3)&~3)+((sizeof(p2)+3)&~3)+((sizeof(p3)+3)&~3);
232 // __asm mov [o],esp;
233 // __asm sub esp, [s];
234 // __asm and esp, ~15;
235 // __asm add esp, [s]
236 // m_test(p1, p2, p3); //return value will still be correct as long as we don't mess with it
237 // __asm mov esp,[o];
238 // };
239 
240 #define ALS(a) ((sizeof(a)+3)&~3)
241 #define DEFINE_FUNC_PART1(result, linkage, name, args) \
242  private: \
243  typedef result (linkage * name##_type)##args; \
244  union { \
245  name##_type m_##name; \
246  void* m_##name##_ptr; \
247  }; \
248  public: \
249  virtual result name##args
250 
251 #define DEFINE_FUNC_PART2(size) \
252  { \
253  int o,s = size; \
254  __asm { \
255  __asm mov [o], esp \
256  __asm sub esp, [s] \
257  __asm and esp, ~15 \
258  __asm add esp, [s] \
259  }
260 
261 #define DEFINE_FUNC_PART3(name,args) \
262  m_##name##args; \
263  __asm { \
264  __asm mov esp,[o] \
265  } \
266  }
267 
268 #define DEFINE_FUNC_ALIGNED0(result, linkage, name) \
269  DEFINE_FUNC_PART1(result, linkage, name, ()) \
270  DEFINE_FUNC_PART2(0) \
271  DEFINE_FUNC_PART3(name,())
272 
273 #define DEFINE_FUNC_ALIGNED1(result, linkage, name, t1) \
274  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1)) \
275  DEFINE_FUNC_PART2(ALS(p1)) \
276  DEFINE_FUNC_PART3(name,(p1))
277 
278 #define DEFINE_FUNC_ALIGNED2(result, linkage, name, t1, t2) \
279  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2)) \
280  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)) \
281  DEFINE_FUNC_PART3(name,(p1, p2))
282 
283 #define DEFINE_FUNC_ALIGNED3(result, linkage, name, t1, t2, t3) \
284  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3)) \
285  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)) \
286  DEFINE_FUNC_PART3(name,(p1, p2, p3))
287 
288 #define DEFINE_FUNC_ALIGNED4(result, linkage, name, t1, t2, t3, t4) \
289  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4)) \
290  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)+ALS(p4)) \
291  DEFINE_FUNC_PART3(name,(p1, p2, p3, p4))
292 
293 #define DEFINE_FUNC_ALIGNED5(result, linkage, name, t1, t2, t3, t4, t5) \
294  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5)) \
295  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)+ALS(p4)+ALS(p5)) \
296  DEFINE_FUNC_PART3(name,(p1, p2, p3, p4, p5))
297 
298 #define DEFINE_FUNC_ALIGNED6(result, linkage, name, t1, t2, t3, t4, t5, t6) \
299  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6)) \
300  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)+ALS(p4)+ALS(p5)+ALS(p6)) \
301  DEFINE_FUNC_PART3(name,(p1, p2, p3, p4, p5, p6))
302 
303 #define DEFINE_FUNC_ALIGNED7(result, linkage, name, t1, t2, t3, t4, t5, t6, t7) \
304  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7)) \
305  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)+ALS(p4)+ALS(p5)+ALS(p6)+ALS(p7)) \
306  DEFINE_FUNC_PART3(name,(p1, p2, p3, p4, p5, p6, p7))
307 
308 #define DEFINE_FUNC_ALIGNED8(result, linkage, name, t1, t2, t3, t4, t5, t6, t7, t8) \
309  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8)) \
310  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)+ALS(p4)+ALS(p5)+ALS(p6)+ALS(p7)+ALS(p8)) \
311  DEFINE_FUNC_PART3(name,(p1, p2, p3, p4, p5, p6, p7, p8))
312 
313 #define DEFINE_FUNC_ALIGNED9(result, linkage, name, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
314  DEFINE_FUNC_PART1(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9)) \
315  DEFINE_FUNC_PART2(ALS(p1)+ALS(p2)+ALS(p3)+ALS(p4)+ALS(p5)+ALS(p6)+ALS(p7)+ALS(p8)+ALS(p9)) \
316  DEFINE_FUNC_PART3(name,(p1, p2, p3, p4, p5, p6, p7, p8, p9))
317 
318 #else
319 
320 #define DEFINE_FUNC_ALIGNED0(result, linkage, name) DEFINE_METHOD_LINKAGE0 (result, linkage, name)
321 #define DEFINE_FUNC_ALIGNED1(result, linkage, name, t1) DEFINE_METHOD_LINKAGE1 (result, linkage, name, (t1 p1) )
322 #define DEFINE_FUNC_ALIGNED2(result, linkage, name, t1, t2) DEFINE_METHOD_LINKAGE2 (result, linkage, name, (t1 p1, t2 p2) )
323 #define DEFINE_FUNC_ALIGNED3(result, linkage, name, t1, t2, t3) DEFINE_METHOD_LINKAGE3 (result, linkage, name, (t1 p1, t2 p2, t3 p3) )
324 #define DEFINE_FUNC_ALIGNED4(result, linkage, name, t1, t2, t3, t4) DEFINE_METHOD_LINKAGE4 (result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4) )
325 #define DEFINE_FUNC_ALIGNED5(result, linkage, name, t1, t2, t3, t4, t5) DEFINE_METHOD_LINKAGE5 (result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5) )
326 #define DEFINE_FUNC_ALIGNED6(result, linkage, name, t1, t2, t3, t4, t5, t6) DEFINE_METHOD_LINKAGE6 (result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6) )
327 #define DEFINE_FUNC_ALIGNED7(result, linkage, name, t1, t2, t3, t4, t5, t6, t7) DEFINE_METHOD_LINKAGE7 (result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7) )
328 #define DEFINE_FUNC_ALIGNED8(result, linkage, name, t1, t2, t3, t4, t5, t6, t7, t8) DEFINE_METHOD_LINKAGE8 (result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8) )
329 #define DEFINE_FUNC_ALIGNED9(result, linkage, name, t1, t2, t3, t4, t5, t6, t7, t8, t9) DEFINE_METHOD_LINKAGE9 (result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9) )
330 #define DEFINE_FUNC_ALIGNED10(result, linkage, name, t1, t2, t3, t4, t5, t6, t7, t8, t10) DEFINE_METHOD_LINKAGE10(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10) )
331 #define DEFINE_FUNC_ALIGNED11(result, linkage, name, t1, t2, t3, t4, t5, t6, t7, t8, t10, t11) DEFINE_METHOD_LINKAGE11(result, linkage, name, (t1 p1, t2 p2, t3 p3, t4 p4, t5 p5, t6 p6, t7 p7, t8 p8, t9 p9, t10 p10, t11 p11) )
332 
333 #endif
334 
336 //
337 // BEGIN_METHOD_RESOLVE/END_METHOD_RESOLVE
338 //
339 // Defines a method that resolves the exported functions
340 // defined with DEFINE_METHOD or DEFINE_METHOD_LINKAGE.
341 // There must be a RESOLVE_METHOD or RESOLVE_METHOD_RENAME
342 // for each DEFINE_METHOD or DEFINE_METHOD_LINKAGE within this
343 // block. This block must be followed by an END_METHOD_RESOLVE.
344 //
345 #define BEGIN_METHOD_RESOLVE() \
346  protected: \
347  virtual bool ResolveExports() override \
348  {
349 
350 #define END_METHOD_RESOLVE() \
351  return true; \
352  }
353 
355 //
356 // RESOLVE_METHOD
357 //
358 // Resolves a method from a dll
359 //
360 // method: Name of the method defined with DEFINE_METHOD
361 // or DEFINE_METHOD_LINKAGE
362 //
363 #define RESOLVE_METHOD(method) \
364  if (!m_dll->ResolveExport( #method , & m_##method##_ptr )) \
365  return false;
366 
367 #define RESOLVE_METHOD_FP(method) \
368  if (!m_dll->ResolveExport( #method , & m_##method##_ptr )) \
369  return false;
370 
371 
373 //
374 // RESOLVE_METHOD_OPTIONAL
375 //
376 // Resolves a method from a dll. does not abort if the
377 // method is missing
378 //
379 // method: Name of the method defined with DEFINE_METHOD
380 // or DEFINE_METHOD_LINKAGE
381 //
382 
383 #define RESOLVE_METHOD_OPTIONAL(method) \
384  m_##method##_ptr = nullptr; \
385  m_dll->ResolveExport( #method , & m_##method##_ptr, false );
386 
387 #define RESOLVE_METHOD_OPTIONAL_FP(method) \
388  m_##method##_ptr = NULL; \
389  m_dll->ResolveExport( #method , & m_##method##_ptr, false );
390 
391 
392 
394 //
395 // RESOLVE_METHOD_RENAME
396 //
397 // Resolves a method from a dll
398 //
399 // dllmethod: Name of the function exported from the dll
400 // method: Name of the method defined with DEFINE_METHOD
401 // or DEFINE_METHOD_LINKAGE
402 //
403 #define RESOLVE_METHOD_RENAME(dllmethod, method) \
404  if (!m_dll->ResolveExport( #dllmethod , & m_##method##_ptr )) \
405  return false;
406 
407 #define RESOLVE_METHOD_RENAME_OPTIONAL(dllmethod, method) \
408  m_##method##_ptr = nullptr; \
409  m_dll->ResolveExport( #dllmethod , & m_##method##_ptr, false );
410 
411 #define RESOLVE_METHOD_RENAME_FP(dllmethod, method) \
412  if (!m_dll->ResolveExport( #dllmethod , & method##_ptr )) \
413  return false;
414 
415 
417 //
418 // Example declaration of a dll wrapper class
419 //
420 // 1. Define a class with pure virtual functions with all functions
421 // exported from the dll. This is needed to use the IntelliSence
422 // feature of the Visual Studio Editor.
423 //
424 // class DllExampleInterface
425 // {
426 // public:
427 // virtual void foo (unsigned int type, char* szTest)=0;
428 // virtual void bar (char* szTest, unsigned int type)=0;
429 // };
430 //
431 // 2. Define a class, derived from DllDynamic and the previously defined
432 // interface class. Define the constructor of the class using the
433 // DECLARE_DLL_WRAPPER macro. Use the DEFINE_METHODX/DEFINE_METHOD_LINKAGEX
434 // macros to define the functions from the interface above, where X is number of
435 // parameters the function has. The function parameters
436 // have to be enclosed in parentheses. The parameter names have to be changed to px
437 // where x is the number on which position the parameter appears.
438 // Use the RESOLVE_METHOD/RESOLVE_METHOD_RENAME to do the actually resolve the functions
439 // from the dll when it's loaded. The RESOLVE_METHOD/RESOLVE_METHOD_RENAME have to
440 // be between the BEGIN_METHOD_RESOLVE/END_METHOD_RESOLVE block.
441 //
442 // class DllExample : public DllDynamic, DllExampleInterface
443 // {
444 // DECLARE_DLL_WRAPPER(DllExample, special://xbmcbin/system/Example.dll)
445 // LOAD_SYMBOLS() // add this if you want to load debug symbols for the dll
446 // DEFINE_METHOD2(void, foo, (int p1, char* p2))
447 // DEFINE_METHOD_LINKAGE2(void, __stdcall, bar, (char* p1, int p2))
448 // DEFINE_METHOD_FP(void, foobar, (int type, char* szTest)) // No need to define this function in the
449 // // interface class, as it's a function pointer.
450 // // But its not recognised by IntelliSence
451 // BEGIN_METHOD_RESOLVE()
452 // RESOLVE_METHOD(foo)
453 // RESOLVE_METHOD_RENAME("_bar@8", bar)
454 // RESOLVE_METHOD_FP(foobar)
455 // END_METHOD_RESOLVE()
456 // };
457 //
458 // The above macros will expand to a class that will look like this
459 //
460 // class DllExample : public DllDynamic, DllExampleInterface
461 // {
462 // public:
463 // DllExample() : DllDynamic( "special://xbmcbin/system/Example.dll" ) {}
464 // protected:
465 // virtual bool LoadSymbols() { return true; }
466 // protected:
467 // typedef void (* foo_METHOD) ( int p1, char* p2 );
468 // foo_METHOD m_foo;
469 // public:
470 // virtual void foo( int p1, char* p2 )
471 // {
472 // return m_foo(p1, p2);
473 // }
474 // protected:
475 // typedef void (__stdcall * bar_METHOD) ( char* p1, int p2 );
476 // bar_METHOD m_bar;
477 // public:
478 // virtual void bar( char* p1, int p2 )
479 // {
480 // return m_bar(p1, p2);
481 // }
482 // protected:
483 // typedef void (* foobar_METHOD) (int type, char* szTest);
484 // public:
485 // foobar_METHOD foobar;
486 // protected:
487 // virtual bool ResolveExports()
488 // {
489 // return (
490 // m_dll->ResolveExport( "foo", (void**)& m_foo ) &&
491 // m_dll->ResolveExport( "_bar@8", (void**)& m_bar ) &&
492 // m_dll->ResolveExport( "foobar" , (void**)& foobar ) &&
493 // 1
494 // );
495 // }
496 // };
497 //
498 // Usage of the class
499 //
500 // DllExample dll;
501 // dll.Load();
502 // if (dll.IsLoaded())
503 // {
504 // dll.foo(1, "bar");
505 // dll.Unload();
506 // }
507 //
508 
510 //
511 // Baseclass for a Dynamically loaded dll
512 // use the above macros to create a dll wrapper
513 //
515 {
516 public:
517  DllDynamic();
518  explicit DllDynamic(const std::string& strDllName);
519  virtual ~DllDynamic();
520  virtual bool Load();
521  virtual void Unload();
522  virtual bool IsLoaded() const { return m_dll!=NULL; }
523  bool CanLoad();
524  bool EnableDelayedUnload(bool bOnOff);
525  bool SetFile(const std::string& strDllName);
526  const std::string &GetFile() const { return m_strDllName; }
527 
528 protected:
529  virtual bool ResolveExports()=0;
530  virtual bool LoadSymbols() { return false; }
531  bool m_DelayUnload;
532  LibraryLoader* m_dll;
533  std::string m_strDllName;
534 };
Definition: LibraryLoader.h:17
Definition: DynamicDll.h:514