| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# DllMain.icpp

Go to the documentation of this file.

    00001 //====================================================================
    00002 //      DllMain.cpp
    00003 //--------------------------------------------------------------------
    00004 //
    00005 //      Package    : Gaudi/System
    00006 //
    00007 //  Description: The DLL initialisation must be done seperately for
    00008 //               each DLL.
    00009 //
    00010 //      Author     : M.Frank
    00011 //  Created    : 13/1/99
    00012 //      Changes    :
    00013 //
    00014 //====================================================================
    00015 #ifndef SYSTEM_DLLMAIN_ICPP
    00016 #define SYSTEM_DLLMAIN_ICPP 1
    00017
    00018 #include "GaudiKernel/System.h"
    00019
    00020 #if !defined(__APPLE__)
    00021 class GaudiDll   {
    00022   GaudiDll()  {}
    00023 public:
    00024   static void initialize(void* hinstDLL);
    00025   static void finalize(void* hinstDLL);
    00026 };
    00027 #endif
    00028
    00029 #if defined _WIN32
    00030 #  define FACTORYTABLE_API __declspec(dllexport)
    00031 #else
    00032 #  define FACTORYTABLE_API
    00033 #endif
    00034
    00035 #if defined(_WIN32) && defined(_DLL)
    00036 namespace win {
    00037 #ifndef NOMSG
    00038 # define NOMSG
    00039 # ifndef NOGDI
    00040 #  define NOGDI
    00041 #  include <windows.h>
    00042 #  undef NOGDI
    00043 # else
    00044 #  include <windows.h>
    00045 # endif
    00046 # undef NOMSG
    00047 #else
    00048 # include <windows.h>
    00049 #endif
    00050 }
    00051
    00052 win::BOOL APIENTRY DllMain(
    00053         win::HINSTANCE hinstDLL,  // handle to DLL module
    00054         win::DWORD fdwReason,     // reason for calling function
    00055         win::LPVOID lpvReserved   // reserved
    00056 )
    00057 {
    00058     System::setModuleHandle(hinstDLL);
    00059     switch( fdwReason ) {
    00060     case DLL_PROCESS_ATTACH:    {
    00061       GaudiDll::initialize(hinstDLL);
    00062     }
    00063     break;
    00064     case DLL_THREAD_ATTACH:
    00065     break;
    00066     case DLL_THREAD_DETACH:
    00067     break;
    00068     case DLL_PROCESS_DETACH:    {
    00069       GaudiDll::finalize(hinstDLL);
    00070       // Since the System class is shared now, we may no longer close the
    00071       // Process handle!  M.F.
    00072       //win::CloseHandle(System::processHandle());
    00073     }
    00074     break;
    00075     }
    00076     return TRUE;
    00077
    00078 }
    00079 #elif linux
    00080 static void _init() __attribute__((constructor));
    00081 static void _fini() __attribute__((destructor));
    00082
    00083 static void _init()   {
    00084       GaudiDll::initialize(0);
    00085 }
    00086 static void _fini()   {
    00087       GaudiDll::finalize(0);
    00088 }
    00089 #elif defined(__APPLE__)
    00090 static void _init() __attribute__((constructor));
    00091 static void _fini() __attribute__((destructor));
    00092
    00093 static void _init()   {
    00094       //FIXME GaudiDll::initialize(0);
    00095 }
    00096 static void _fini()   {
    00097       //FIXME GaudiDll::finalize(0);
    00098 }
    00099
    00100 #endif // WIN32
    00101
    00102 #endif // SYSTEM_DLLMAIN_ICPP