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.

214 lines
5.6 KiB

  1. //****************************************************************************
  2. //
  3. // Module: ULS.DLL
  4. // File: init.cpp
  5. // Content: This file contains the module initialization.
  6. // History:
  7. // Tue 08-Oct-1996 08:51:15 -by- Viroon Touranachun [viroont]
  8. //
  9. // Copyright (c) Microsoft Corporation 1996-1997
  10. //
  11. //****************************************************************************
  12. #include "ulsp.h"
  13. #include "regunreg.h"
  14. #include <ilsguid.h>
  15. #include "classfac.h"
  16. //****************************************************************************
  17. // Constants
  18. //****************************************************************************
  19. //****************************************************************************
  20. // Global Parameters
  21. //****************************************************************************
  22. HINSTANCE g_hInstance = NULL;
  23. LONG g_cDllRef = 0;
  24. #ifdef _DEBUG
  25. LONG g_cCritSec = 0;
  26. #endif
  27. CRITICAL_SECTION g_ULSSem;
  28. #ifdef DEBUG
  29. HDBGZONE ghZoneUls = NULL; // ULS zones
  30. static PTCHAR _rgZonesUls[] = {
  31. TEXT("ILS"),
  32. TEXT("Error"),
  33. TEXT("Warning"),
  34. TEXT("Trace"),
  35. TEXT("RefCount"),
  36. TEXT("KA"),
  37. TEXT("Filter"),
  38. TEXT("Request"),
  39. TEXT("Response"),
  40. TEXT("Connection"),
  41. };
  42. #endif
  43. //****************************************************************************
  44. // BOOL _Processattach (HINSTANCE)
  45. //
  46. // This function is called when a process is attached to the DLL
  47. //
  48. // History:
  49. // Tue 08-Oct-1996 08:53:03 -by- Viroon Touranachun [viroont]
  50. // Ported from Shell.
  51. //****************************************************************************
  52. BOOL _ProcessAttach(HINSTANCE hDll)
  53. {
  54. // Tracking critical section leaks
  55. //
  56. #ifdef _DEBUG
  57. g_cCritSec = 0;
  58. g_cDllRef = 0;
  59. #endif
  60. g_hInstance = hDll;
  61. MyInitializeCriticalSection (&g_ULSSem);
  62. return TRUE;
  63. }
  64. //****************************************************************************
  65. // BOOL _ProcessDetach (HINSTANCE)
  66. //
  67. // This function is called when a process is detached from the DLL
  68. //
  69. // History:
  70. // Tue 08-Oct-1996 08:53:11 -by- Viroon Touranachun [viroont]
  71. // Ported from Shell.
  72. //****************************************************************************
  73. BOOL _ProcessDetach(HINSTANCE hDll)
  74. {
  75. MyDeleteCriticalSection (&g_ULSSem);
  76. #ifdef _DEBUG
  77. DBG_REF("ULS g_cCritSec=%d", g_cCritSec);
  78. DBG_REF("ULS RefCount=%d", g_cDllRef);
  79. #endif
  80. return TRUE;
  81. }
  82. //****************************************************************************
  83. // BOOL APIENTRY DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
  84. //
  85. // This function is called when the DLL is loaded
  86. //
  87. // History:
  88. // Tue 08-Oct-1996 08:53:22 -by- Viroon Touranachun [viroont]
  89. // Ported from Shell.
  90. //****************************************************************************
  91. BOOL APIENTRY DllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved)
  92. {
  93. switch(dwReason)
  94. {
  95. case DLL_PROCESS_ATTACH:
  96. DBGINIT(&ghZoneUls, _rgZonesUls);
  97. DisableThreadLibraryCalls(hDll);
  98. DBG_INIT_MEMORY_TRACKING(hDll);
  99. _ProcessAttach(hDll);
  100. break;
  101. case DLL_PROCESS_DETACH:
  102. _ProcessDetach(hDll);
  103. DBG_CHECK_MEMORY_TRACKING(hDll);
  104. DBGDEINIT(&ghZoneUls);
  105. break;
  106. default:
  107. break;
  108. } // end switch()
  109. return TRUE;
  110. }
  111. //****************************************************************************
  112. // STDAPI DllCanUnLoadNow()
  113. //
  114. // This function is called to check whether it can be unloaded.
  115. //
  116. // History:
  117. // Tue 08-Oct-1996 08:53:35 -by- Viroon Touranachun [viroont]
  118. // Created.
  119. //****************************************************************************
  120. STDAPI DllCanUnloadNow(void)
  121. {
  122. if (g_cDllRef)
  123. return S_FALSE;
  124. return S_OK;
  125. }
  126. //****************************************************************************
  127. // STDAPI DllRegisterServer(void)
  128. //
  129. // This function is called to check whether it can be unloaded.
  130. //
  131. // History:
  132. // Tue 08-Oct-1996 08:53:35 -by- Viroon Touranachun [viroont]
  133. // Created.
  134. //****************************************************************************
  135. STDAPI DllRegisterServer(void)
  136. {
  137. if (RegisterUnknownObject(TEXT("Internet Location Services"),
  138. CLSID_InternetLocationServices))
  139. return S_OK;
  140. else
  141. return ILS_E_FAIL;
  142. }
  143. //****************************************************************************
  144. // STDAPI DllUnregisterServer(void)
  145. //
  146. // This function is called to check whether it can be unloaded.
  147. //
  148. // History:
  149. // Tue 08-Oct-1996 08:53:35 -by- Viroon Touranachun [viroont]
  150. // Created.
  151. //****************************************************************************
  152. STDAPI DllUnregisterServer(void)
  153. {
  154. if (UnregisterUnknownObject(CLSID_InternetLocationServices))
  155. return S_OK;
  156. else
  157. return ILS_E_FAIL;
  158. }
  159. //****************************************************************************
  160. // void DllLock()
  161. //
  162. // This function is called to prevent the DLL from being unloaded.
  163. //
  164. // History:
  165. // Tue 08-Oct-1996 08:53:45 -by- Viroon Touranachun [viroont]
  166. // Created.
  167. //****************************************************************************
  168. void DllLock(void)
  169. {
  170. InterlockedIncrement(&g_cDllRef);
  171. }
  172. //****************************************************************************
  173. // void DllRelease()
  174. //
  175. // This function is called to allow the DLL to be unloaded.
  176. //
  177. // History:
  178. // Tue 08-Oct-1996 08:53:52 -by- Viroon Touranachun [viroont]
  179. // Created.
  180. //****************************************************************************
  181. void DllRelease(void)
  182. {
  183. InterlockedDecrement(&g_cDllRef);
  184. }