Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cOSModImpl.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cOSModImpl_H
7 #define _INC_cOSModImpl_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cOSModule.h"
13 #include "cAtom.h"
14 #include "cArraySort.h"
15 #include "cSingleton.h"
16 
17 #ifdef _MFC_VER
18 #include "SysRes.h"
19 #include <afxwin.h> // MFC extensions AFX_EXTENSION_MODULE. includes <afxdll_.h>
20 #endif
21 
22 namespace Gray
23 {
25  {
34 
35  public:
36  const char* m_pszModuleName;
37  HMODULE m_hModule;
38 
39 #ifdef _MFC_VER
40  AFX_EXTENSION_MODULE m_AFXExt; // I might be a MFC extension module.
41 #endif
42 
43  private:
44  bool OnProcessAttach2();
45 
46  public:
47  cOSModImpl(const char* pszModuleName) noexcept;
48  virtual ~cOSModImpl();
49 
50  bool IsLoaded() const noexcept
51  {
52  return m_pszModuleName != nullptr && m_hModule != HMODULE_NULL;
53  }
54 
55  virtual bool OnProcessAttach();
56  virtual void OnProcessDetach(); // DLL_PROCESS_DETACH
57 
58 #ifdef _WIN32
59  virtual bool DllMain(HINSTANCE hInstDll, DWORD dwReason);
60 #elif defined(__linux__)
61  void SOConstructor();
62  void SODestructor()
63  {
64  OnProcessDetach();
65  }
66 #endif
67  };
68 
69 #ifdef GRAY_DLL // _WINDLL
70  // ASSUME g_Module is defined for DLL/SO. (and is outside namespace)
71  // Declare/expose DllMain()
72 #ifdef _WIN32 // _WINDLL
73 #define COSMODULE_IMPL(N) __DECL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hInstDll, DWORD dwReason, LPVOID) { return N::g_Module.DllMain(hInstDll,dwReason); }
74 #elif defined(__linux__)
75 #define COSMODULE_IMPL(N) CATTR_CONSTRUCTOR void _cdecl SOConstructor() { N::g_Module.SOConstructor(); } \
76  CATTR_DESTRUCTOR void _cdecl SODestructor() { g_Module.SODestructor(); }
77 #endif
78 #endif //GRAY_DLL
79 
80 }
81 
82 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define HMODULE_NULL
Definition: cOSModule.h:31
Definition: cOSModImpl.h:25
HMODULE m_hModule
My HMODULE assigned to me when loaded. should be same as GetModuleHandleForAddr(&g_Module)
Definition: cOSModImpl.h:37
const char * m_pszModuleName
Just derive this from the file name ?
Definition: cOSModImpl.h:36
bool IsLoaded() const noexcept
Definition: cOSModImpl.h:50
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14