Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dllmain.c
  6. * Content: Main entry point for the DLL.
  7. * History:
  8. *@@BEGIN_MSINTERNAL
  9. * Date By Reason
  10. * ==== == ======
  11. * 4/10/96 kipo created it
  12. * 4/15/96 kipo added msinternal
  13. * 6/18/96 kipo changed ghInstance to be an HINSTANCE
  14. * 12/22/00 aarono #190380 - use process heap for memory allocation
  15. *@@END_MSINTERNAL
  16. ***************************************************************************/
  17. #include <windows.h>
  18. #include "dpf.h"
  19. #include "macros.h"
  20. DWORD gdwRefCount = 0; // no. of attached processes
  21. HINSTANCE ghInstance = NULL; // instance of our DLL
  22. /*
  23. * DllMain
  24. *
  25. * Main entry point for DLL.
  26. */
  27. #undef DPF_MODNAME
  28. #define DPF_MODNAME "DllMain"
  29. BOOL WINAPI DllMain(HINSTANCE hmod, DWORD dwReason, LPVOID lpvReserved)
  30. {
  31. switch( dwReason )
  32. {
  33. case DLL_PROCESS_ATTACH:
  34. DisableThreadLibraryCalls( hmod );
  35. DPFINIT(); // bugbug : dpfinit for every proc?
  36. DPF( 0, "====> ENTER: DLLMAIN(%08lx): Process Attach: %08lx, tid=%08lx", DllMain,
  37. GetCurrentProcessId(), GetCurrentThreadId() );
  38. // initialize memory
  39. if( gdwRefCount == 0 )
  40. {
  41. DPF(0,"dllmain - starting up!");
  42. // do one-time initializations
  43. INIT_DPSP_CSECT();
  44. if( !MemInit() )
  45. {
  46. DPF( 0, "LEAVING, COULD NOT MemInit" );
  47. return FALSE;
  48. }
  49. // save the instance
  50. ghInstance = hmod;
  51. }
  52. gdwRefCount++;
  53. break;
  54. case DLL_PROCESS_DETACH:
  55. DPF( 2, "====> ENTER: DLLMAIN(%08lx): Process Detach %08lx, tid=%08lx",
  56. DllMain, GetCurrentProcessId(), GetCurrentThreadId() );
  57. gdwRefCount--;
  58. if (gdwRefCount == 0)
  59. {
  60. DPF(0,"DPMODEMX - dllmain - going away!");
  61. #ifdef DEBUG
  62. MemState();
  63. #endif // debug
  64. MemFini();
  65. FINI_DPSP_CSECT();
  66. }
  67. break;
  68. default:
  69. break;
  70. }
  71. return TRUE;
  72. } // DllMain