home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / src / mingw-runtime-19991107 / mingw / dllcrt1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-03  |  2.3 KB  |  90 lines

  1. /*
  2.  * dllcrt1.c
  3.  *
  4.  * Initialization code for DLLs.
  5.  *
  6.  * This file is part of the Mingw32 package.
  7.  *
  8.  * Contributors:
  9.  *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
  10.  *  DLL support adapted from Gunther Ebert <gunther.ebert@ixos-leipzig.de>
  11.  *  Maintained by Mumit Khan <khan@xraylith.wisc.EDU>
  12.  *
  13.  *  THIS SOFTWARE IS NOT COPYRIGHTED
  14.  *
  15.  *  This source code is offered for use in the public domain. You may
  16.  *  use, modify or distribute it freely.
  17.  *
  18.  *  This code is distributed in the hope that it will be useful but
  19.  *  WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
  20.  *  DISCLAMED. This includes but is not limited to warrenties of
  21.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22.  *
  23.  * $Revision: 1.5 $
  24.  * $Author: khan $
  25.  * $Date: 1998/09/03 16:31:17 $
  26.  * 
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <io.h>
  31. #include <process.h>
  32. #include <windows.h>
  33.  
  34. /* Unlike normal crt1, I don't initialize the FPU, because the process
  35.  * should have done that already. I also don't set the file handle modes,
  36.  * because that would be rude. */
  37.  
  38. #ifdef    __GNUC__
  39. extern void __main ();
  40. extern void __do_global_dtors ();
  41. #endif
  42.  
  43. extern BOOL WINAPI DllMain (HANDLE, DWORD, LPVOID);
  44.  
  45. BOOL WINAPI
  46. DllMainCRTStartup (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  47. {
  48.   BOOL bRet;
  49.  
  50.   if (dwReason == DLL_PROCESS_ATTACH)
  51.     {
  52. #ifdef    __GNUC__
  53.       /* From libgcc.a, calls global class constructors. */
  54.       __main ();
  55. #endif
  56.     }
  57.  
  58.   /*
  59.    * Call the user-supplied DllMain subroutine
  60.    * NOTE: DllMain is optional, so libmingw32.a includes a stub
  61.    *       which will be used if the user does not supply one.
  62.    */
  63.   bRet = DllMain (hDll, dwReason, lpReserved);
  64.  
  65. #ifdef    __GNUC__
  66.   if (dwReason == DLL_PROCESS_DETACH)
  67.     {
  68.       /* From libgcc.a, calls global class destructors. */
  69.       __do_global_dtors ();
  70.     }
  71. #endif
  72.  
  73.   return bRet;
  74. }
  75.  
  76. /*
  77.  * For the moment a dummy atexit. Atexit causes problems in DLLs, especially
  78.  * if they are dynamically loaded. For now atexit inside a DLL does nothing.
  79.  * NOTE: We need this even if the DLL author never calls atexit because
  80.  *       the global constructor function __do_global_ctors called from __main
  81.  *       will attempt to register __do_global_dtors using atexit.
  82.  *       Thanks to Andrey A. Smirnov for pointing this one out.
  83.  */
  84. int
  85. atexit (void (*pfn) ())
  86. {
  87.   return 0;
  88. }
  89.  
  90.