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