The Gaudi Framework  v38r1p1 (ae26267b)
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 #include "GaudiKernel/Kernel.h"
29 #include "GaudiKernel/System.h"
30 
31 #if !defined( __APPLE__ )
32 class GaudiDll {
33  GaudiDll() {}
34 
35 public:
36  static void initialize( void* hinstDLL );
37  static void finalize( void* hinstDLL );
38 };
39 #endif
40 
41 #if defined( _WIN32 ) && defined( _DLL )
42 namespace win {
43 // Avoid conflicts between Windows' headers and MSG.
44 # ifndef NOMSG
45 # define NOMSG
46 # ifndef NOGDI
47 # define NOGDI
48 # endif
49 # endif
50 # include <windows.h>
51 } // namespace win
52 
53 win::BOOL APIENTRY DllMain( win::HINSTANCE hinstDLL, // handle to DLL module
54  win::DWORD fdwReason, // reason for calling function
55  win::LPVOID lpvReserved // reserved
56 ) {
57  System::setModuleHandle( hinstDLL );
58  switch ( fdwReason ) {
59  case DLL_PROCESS_ATTACH: {
60  GaudiDll::initialize( hinstDLL );
61  } break;
62  case DLL_THREAD_ATTACH:
63  break;
64  case DLL_THREAD_DETACH:
65  break;
66  case DLL_PROCESS_DETACH: {
67  GaudiDll::finalize( hinstDLL );
68  // Since the System class is shared now, we may no longer close the
69  // Process handle! M.F.
70  // win::CloseHandle(System::processHandle());
71  } break;
72  }
73  return TRUE;
74 }
75 #elif __linux
76 static void _init() __attribute__( ( constructor ) );
77 static void _fini() __attribute__( ( destructor ) );
78 
79 static void _init() { GaudiDll::initialize( 0 ); }
80 static void _fini() { GaudiDll::finalize( 0 ); }
81 #elif defined( __APPLE__ )
82 static void _init() __attribute__( ( constructor ) );
83 static void _fini() __attribute__( ( destructor ) );
84 
85 static void _init() {
86  // FIXME GaudiDll::initialize(0);
87 }
88 static void _fini() {
89  // FIXME GaudiDll::finalize(0);
90 }
91 
92 #endif // WIN32
93 
94 #endif // SYSTEM_DLLMAIN_ICPP
System.h
GaudiDll::GaudiDll
GaudiDll()
Definition: DllMain.icpp:33
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:29
GaudiDll
Definition: DllMain.icpp:32
Kernel.h
GaudiKernel.Constants.TRUE
TRUE
Definition: Constants.py:37
GaudiDll::finalize
static void finalize(void *hinstDLL)
Definition: LoadFactoryEntries.h:30