• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, procName) ::GetProcAddressA(module, procName)
13 #else
14 #define My_GetProcAddress(module, procName) ::GetProcAddress(module, procName)
15 #endif
16 
17 /* Win32: Don't call CLibrary::Free() and FreeLibrary() from another
18     FreeLibrary() code: detaching code in DLL entry-point or in
19     destructors of global objects in DLL module. */
20 
21 class CLibrary
22 {
23   HMODULE _module;
24 
25   // CLASS_NO_COPY(CLibrary);
26 public:
CLibrary()27   CLibrary(): _module(NULL) {};
~CLibrary()28   ~CLibrary() { Free(); }
29 
HMODULE()30   operator HMODULE() const { return _module; }
31   HMODULE* operator&() { return &_module; }
IsLoaded()32   bool IsLoaded() const { return (_module != NULL); }
33 
Attach(HMODULE m)34   void Attach(HMODULE m)
35   {
36     Free();
37     _module = m;
38   }
Detach()39   HMODULE Detach()
40   {
41     HMODULE m = _module;
42     _module = NULL;
43     return m;
44   }
45 
46   bool Free() throw();
47   bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE) throw();
48   bool Load(CFSTR path) throw();
GetProc(LPCSTR procName)49   FARPROC GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
50 };
51 
52 bool MyGetModuleFileName(FString &path);
53 
54 FString GetModuleDirPrefix();
55 
56 }}
57 
58 #endif
59