The Gaudi Framework  v29r0 (ff2e7097)
DllMain.icpp
Go to the documentation of this file.
1 //====================================================================
2 // DllMain.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : Gaudi/System
6 //
7 // Description: The DLL initialisation must be done seperately for
8 // each DLL.
9 //
10 // Author : M.Frank
11 // Created : 13/1/99
12 // Changes :
13 //
14 //====================================================================
15 #ifndef SYSTEM_DLLMAIN_ICPP
16 #define SYSTEM_DLLMAIN_ICPP 1
17 
18 #include "GaudiKernel/Kernel.h"
19 #include "GaudiKernel/System.h"
20 
21 #if !defined( __APPLE__ )
22 class GaudiDll
23 {
24  GaudiDll() {}
25 
26 public:
27  static void initialize( void* hinstDLL );
28  static void finalize( void* hinstDLL );
29 };
30 #endif
31 
32 #if defined( _WIN32 ) && defined( _DLL )
33 namespace win
34 {
35 // Avoid conflicts between Windows' headers and MSG.
36 #ifndef NOMSG
37 #define NOMSG
38 #ifndef NOGDI
39 #define NOGDI
40 #endif
41 #endif
42 #include <windows.h>
43 }
44 
45 win::BOOL APIENTRY DllMain( win::HINSTANCE hinstDLL, // handle to DLL module
46  win::DWORD fdwReason, // reason for calling function
47  win::LPVOID lpvReserved // reserved
48  )
49 {
50  System::setModuleHandle( hinstDLL );
51  switch ( fdwReason ) {
52  case DLL_PROCESS_ATTACH: {
53  GaudiDll::initialize( hinstDLL );
54  } break;
55  case DLL_THREAD_ATTACH:
56  break;
57  case DLL_THREAD_DETACH:
58  break;
59  case DLL_PROCESS_DETACH: {
60  GaudiDll::finalize( hinstDLL );
61  // Since the System class is shared now, we may no longer close the
62  // Process handle! M.F.
63  // win::CloseHandle(System::processHandle());
64  } break;
65  }
66  return TRUE;
67 }
68 #elif __linux
69 static void _init() __attribute__( ( constructor ) );
70 static void _fini() __attribute__( ( destructor ) );
71 
72 static void _init() { GaudiDll::initialize( 0 ); }
73 static void _fini() { GaudiDll::finalize( 0 ); }
74 #elif defined( __APPLE__ )
75 static void _init() __attribute__( ( constructor ) );
76 static void _fini() __attribute__( ( destructor ) );
77 
78 static void _init()
79 {
80  // FIXME GaudiDll::initialize(0);
81 }
82 static void _fini()
83 {
84  // FIXME GaudiDll::finalize(0);
85 }
86 
87 #endif // WIN32
88 
89 #endif // SYSTEM_DLLMAIN_ICPP
#define __attribute__(x)
Definition: System.cpp:79
static void initialize(void *hinstDLL)
GAUDI_API void setModuleHandle(ImageHandle handle)
Attach module handle.
Definition: ModuleInfo.cpp:139
static void finalize(void *hinstDLL)
GaudiDll()
Definition: DllMain.icpp:24