1 // Windows/DLL.h
2 
3 #ifndef __WINDOWS_DLL_H
4 #define __WINDOWS_DLL_H
5 
6 #include "../Common/MyString.h"
7 
8 namespace NWindows {
9 namespace NDLL {
10 
11 #ifdef UNDER_CE
12 #define My_GetProcAddress(module, proceName) GetProcAddressA(module, proceName)
13 #else
14 #define My_GetProcAddress(module, proceName) ::GetProcAddress(module, proceName)
15 #endif
16 
17 class CLibrary
18 {
19   bool LoadOperations(HMODULE newModule);
20 protected:
21   HMODULE _module;
22 public:
CLibrary()23   CLibrary(): _module(NULL) {};
~CLibrary()24   ~CLibrary() { Free(); }
25 
HMODULE()26   operator HMODULE() const { return _module; }
27   HMODULE* operator&() { return &_module; }
IsLoaded()28   bool IsLoaded() const { return (_module != NULL); };
29 
Attach(HMODULE m)30   void Attach(HMODULE m)
31   {
32     Free();
33     _module = m;
34   }
Detach()35   HMODULE Detach()
36   {
37     HMODULE m = _module;
38     _module = NULL;
39     return m;
40   }
41 
42   bool Free();
43   bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);
44   bool Load(LPCTSTR fileName);
45   #ifndef _UNICODE
46   bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);
47   bool Load(LPCWSTR fileName);
48   #endif
GetProc(LPCSTR procName)49   FARPROC GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
50 };
51 
52 bool MyGetModuleFileName(HMODULE hModule, CSysString &result);
53 #ifndef _UNICODE
54 bool MyGetModuleFileName(HMODULE hModule, UString &result);
55 #endif
56 
57 }}
58 
59 #endif
60