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