1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 */ |
|
16 |
|
17 #ifndef _DST_DLL_MODULE_ |
|
18 #define _DST_DLL_MODULE_ |
|
19 |
|
20 class CDLLModule |
|
21 { |
|
22 public: |
|
23 CDLLModule() : m_hDLL(NULL) |
|
24 { |
|
25 } |
|
26 virtual ~CDLLModule() //destructor, free the library |
|
27 { |
|
28 if (m_hDLL) |
|
29 ::FreeLibrary(m_hDLL); |
|
30 } |
|
31 ////////////////////////////////////////////////////////////////// |
|
32 // See if dll been loaded, returning true dose not mean that all |
|
33 // functions of the dll is valid. |
|
34 bool IsLoaded(void) |
|
35 { |
|
36 return m_hDLL != NULL; |
|
37 } |
|
38 |
|
39 ///////////////////////////////////////////////////////// |
|
40 // pure virtual, must implemented in derived class |
|
41 // used macros to generate the implementation |
|
42 virtual bool Init(LPCTSTR szDll)=0; |
|
43 |
|
44 protected: |
|
45 HMODULE m_hDLL; |
|
46 }; |
|
47 |
|
48 ////////////////////////////////////////////////////////////////////// |
|
49 // macros to implement the Init function |
|
50 #define DECLARE_DLL_FUNCTION(ret, cc, func, params) \ |
|
51 ret (cc* func)params; |
|
52 |
|
53 #define BEGIN_DLL_INIT() \ |
|
54 bool Init(LPCTSTR szDll) \ |
|
55 { \ |
|
56 if (m_hDLL) \ |
|
57 ::FreeLibrary(m_hDLL); \ |
|
58 m_hDLL = ::LoadLibrary(szDll); \ |
|
59 bool bOk = true; |
|
60 |
|
61 #define INIT_DLL_FUNCTION(ret, cc, func, params, origin) \ |
|
62 if (m_hDLL) \ |
|
63 { \ |
|
64 func = (ret (cc* )params)GetProcAddress(m_hDLL, origin); \ |
|
65 } \ |
|
66 else \ |
|
67 func = NULL; \ |
|
68 if (!func) \ |
|
69 bOk = false; |
|
70 |
|
71 #define END_DLL_INIT() \ |
|
72 return bOk; \ |
|
73 } |
|
74 |
|
75 #endif |
|