The Gaudi Framework  master (37c0b60a)
DllMain.icpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //====================================================================
12 // DllMain.cpp
13 //--------------------------------------------------------------------
14 //
15 // Package : Gaudi/System
16 //
17 // Description: The DLL initialisation must be done seperately for
18 // each DLL.
19 //
20 // Author : M.Frank
21 // Created : 13/1/99
22 // Changes :
23 //
24 //====================================================================
25 #ifndef SYSTEM_DLLMAIN_ICPP
26 #define SYSTEM_DLLMAIN_ICPP 1
27 
28 // this header is only used by the deprecated GaudiKernel/LoadFactoryEntries.h
29 // but we want to make sure nobody else is using it
30 #if !defined( GAUDIKERNEL_LOADFACTORYENTRIES_H )
31 # warning "deprecated header file, not to be used"
32 #endif
33 
34 #include "GaudiKernel/Kernel.h"
35 #include "GaudiKernel/System.h"
36 
37 #if !defined( __APPLE__ )
38 class GaudiDll {
39  GaudiDll() {}
40 
41 public:
42  static void initialize( void* hinstDLL );
43  static void finalize( void* hinstDLL );
44 };
45 #endif
46 
47 #if defined( _WIN32 ) && defined( _DLL )
48 namespace win {
49 // Avoid conflicts between Windows' headers and MSG.
50 # ifndef NOMSG
51 # define NOMSG
52 # ifndef NOGDI
53 # define NOGDI
54 # endif
55 # endif
56 # include <windows.h>
57 } // namespace win
58 
59 win::BOOL APIENTRY DllMain( win::HINSTANCE hinstDLL, // handle to DLL module
60  win::DWORD fdwReason, // reason for calling function
61  win::LPVOID lpvReserved // reserved
62 ) {
63  System::setModuleHandle( hinstDLL );
64  switch ( fdwReason ) {
65  case DLL_PROCESS_ATTACH: {
66  GaudiDll::initialize( hinstDLL );
67  } break;
68  case DLL_THREAD_ATTACH:
69  break;
70  case DLL_THREAD_DETACH:
71  break;
72  case DLL_PROCESS_DETACH: {
73  GaudiDll::finalize( hinstDLL );
74  // Since the System class is shared now, we may no longer close the
75  // Process handle! M.F.
76  // win::CloseHandle(System::processHandle());
77  } break;
78  }
79  return TRUE;
80 }
81 #elif __linux
82 static void _init() __attribute__( ( constructor ) );
83 static void _fini() __attribute__( ( destructor ) );
84 
85 static void _init() { GaudiDll::initialize( 0 ); }
86 static void _fini() { GaudiDll::finalize( 0 ); }
87 #elif defined( __APPLE__ )
88 static void _init() __attribute__( ( constructor ) );
89 static void _fini() __attribute__( ( destructor ) );
90 
91 static void _init() {
92  // FIXME GaudiDll::initialize(0);
93 }
94 static void _fini() {
95  // FIXME GaudiDll::finalize(0);
96 }
97 
98 #endif // WIN32
99 
100 #endif // SYSTEM_DLLMAIN_ICPP
System.h
GaudiDll::GaudiDll
GaudiDll()
Definition: DllMain.icpp:39
System::setModuleHandle
GAUDI_API void setModuleHandle(ImageHandle handle)
Attach module handle.
Definition: ModuleInfo.cpp:145
GaudiDll::initialize
static void initialize(void *hinstDLL)
Definition: LoadFactoryEntries.h:33
GaudiDll
Definition: DllMain.icpp:38
Kernel.h
GaudiKernel.Constants.TRUE
TRUE
Definition: Constants.py:37
GaudiDll::finalize
static void finalize(void *hinstDLL)
Definition: LoadFactoryEntries.h:34