Source code of Windows XP (NT5)
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.

143 lines
4.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: cryptnet.cpp
  7. //
  8. // Contents: DllMain for CRYPTNET.DLL
  9. //
  10. // History: 24-Jul-97 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "windows.h"
  14. #include "crtem.h"
  15. #include "unicode.h"
  16. //
  17. // DllMain stuff
  18. //
  19. #if DBG
  20. extern BOOL WINAPI DebugDllMain(HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  21. #endif
  22. extern BOOL WINAPI RPORDllMain (HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  23. extern BOOL WINAPI DpsDllMain (HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  24. extern BOOL WINAPI DemandLoadDllMain (HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  25. extern BOOL WINAPI NSRevokeDllMain (HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  26. typedef BOOL (WINAPI *PFN_DLL_MAIN_FUNC) (
  27. HMODULE hInstDLL,
  28. DWORD fdwReason,
  29. LPVOID lpvReserved
  30. );
  31. HMODULE g_hModule;
  32. // For process/thread attach, called in the following order. For process/thread
  33. // detach, called in reverse order.
  34. static const PFN_DLL_MAIN_FUNC rgpfnDllMain[] = {
  35. #if DBG
  36. DebugDllMain,
  37. #endif
  38. DemandLoadDllMain,
  39. RPORDllMain,
  40. NSRevokeDllMain
  41. };
  42. #define DLL_MAIN_FUNC_COUNT (sizeof(rgpfnDllMain) / sizeof(rgpfnDllMain[0]))
  43. //
  44. // DllRegisterServer and DllUnregisterServer stuff
  45. //
  46. extern HRESULT WINAPI DpsDllRegUnregServer (HMODULE hInstDLL, BOOL fRegUnreg);
  47. extern HRESULT WINAPI RPORDllRegUnregServer (HMODULE hInstDLL, BOOL fRegUnreg);
  48. typedef HRESULT (WINAPI *PFN_DLL_REGUNREGSERVER_FUNC) (
  49. HMODULE hInstDLL,
  50. BOOL fRegUnreg
  51. );
  52. static const PFN_DLL_REGUNREGSERVER_FUNC rgpfnDllRegUnregServer[] = {
  53. RPORDllRegUnregServer
  54. };
  55. #define DLL_REGUNREGSERVER_FUNC_COUNT (sizeof(rgpfnDllRegUnregServer) / \
  56. sizeof(rgpfnDllRegUnregServer[0]))
  57. //+-------------------------------------------------------------------------
  58. // Dll initialization
  59. //--------------------------------------------------------------------------
  60. BOOL WINAPI DllMain(
  61. HMODULE hInstDLL,
  62. DWORD fdwReason,
  63. LPVOID lpvReserved
  64. )
  65. {
  66. BOOL fReturn = TRUE;
  67. int i;
  68. #if DBG
  69. // NB- Due to an apparent bug in the Win95 loader, the CRT gets unloaded
  70. // too early in some circumstances. In particular, it can get unloaded
  71. // before this routine executes at process detach time. This can cause
  72. // faults when executing this routine, and also when executing the rest
  73. // of CRYPT32:CRT_INIT, after this initroutine returns. Ergo, we do an
  74. // extra load of the CRT, to be sure it stays around long enough.
  75. if ((fdwReason == DLL_PROCESS_ATTACH) && (!FIsWinNT()))
  76. LoadLibrary( "MSVCRTD.DLL");
  77. #endif
  78. switch (fdwReason) {
  79. case DLL_PROCESS_DETACH:
  80. case DLL_THREAD_DETACH:
  81. for (i = DLL_MAIN_FUNC_COUNT - 1; i >= 0; i--)
  82. fReturn &= rgpfnDllMain[i](hInstDLL, fdwReason, lpvReserved);
  83. break;
  84. case DLL_PROCESS_ATTACH:
  85. g_hModule = hInstDLL;
  86. case DLL_THREAD_ATTACH:
  87. default:
  88. for (i = 0; i < DLL_MAIN_FUNC_COUNT; i++)
  89. fReturn &= rgpfnDllMain[i](hInstDLL, fdwReason, lpvReserved);
  90. break;
  91. }
  92. return(fReturn);
  93. }
  94. STDAPI DllRegisterServer ()
  95. {
  96. HRESULT hr = 0;
  97. ULONG cCount;
  98. for ( cCount = 0; cCount < DLL_REGUNREGSERVER_FUNC_COUNT; cCount++ )
  99. {
  100. hr = rgpfnDllRegUnregServer[cCount]( g_hModule, TRUE );
  101. if ( hr != S_OK )
  102. {
  103. break;
  104. }
  105. }
  106. return( hr );
  107. }
  108. STDAPI DllUnregisterServer ()
  109. {
  110. HRESULT hr = 0;
  111. ULONG cCount;
  112. for ( cCount = 0; cCount < DLL_REGUNREGSERVER_FUNC_COUNT; cCount++ )
  113. {
  114. hr = rgpfnDllRegUnregServer[cCount]( g_hModule, FALSE );
  115. if ( hr != S_OK )
  116. {
  117. break;
  118. }
  119. }
  120. return( hr );
  121. }