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.

242 lines
5.8 KiB

  1. //***************************************************************************
  2. //
  3. // MAINDLL.CPP
  4. //
  5. // Module: WMI Framework Instance provider
  6. //
  7. // Purpose: Contains DLL entry points. Also has code that controls
  8. // when the DLL can be unloaded by tracking the number of
  9. // objects and locks as well as routines that support
  10. // self registration.
  11. //
  12. // Copyright (c) 2000-2001 Microsoft Corporation, All Rights Reserved
  13. //
  14. //***************************************************************************
  15. #include "precomp.h"
  16. #include <dllunreg.h>
  17. #include <DllCommon.h>
  18. #include <CIpRouteEvent.h>
  19. #include <brodcast.h>
  20. HMODULE ghModule ;
  21. // {23b77e99-5c2d-482d-a795-62ca3ae5b673}
  22. DEFINE_GUID(CLSID_CIPROUTETABLE,
  23. 0x23b77e99, 0x5c2d, 0x482d, 0xa7, 0x95, 0x62, 0xca, 0x3a, 0xe5, 0xb6, 0x73);
  24. // {6D7A4B0E-66D5-4ac3-A7ED-0189E8CF5E77}
  25. DEFINE_GUID(CLSID_CIPROUTETABLEEVENT,
  26. 0x6d7a4b0e, 0x66d5, 0x4ac3, 0xa7, 0xed, 0x1, 0x89, 0xe8, 0xcf, 0x5e, 0x77);
  27. #define PROVIDER_NAME L"CIPROUTETABLE"
  28. //Count number of objects and number of locks.
  29. long g_cLock = 0 ;
  30. //***************************************************************************
  31. //
  32. // DllGetClassObject
  33. //
  34. // Purpose: Called by Ole when some client wants a class factory. Return
  35. // one only if it is the sort of class this DLL supports.
  36. //
  37. //***************************************************************************
  38. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, PPVOID ppv)
  39. {
  40. HRESULT hr = S_OK;
  41. try
  42. {
  43. if ( CLSID_CIPROUTETABLE == rclsid )
  44. {
  45. hr = CommonGetClassObject(riid, ppv, PROVIDER_NAME, g_cLock);
  46. }
  47. else if( CLSID_CIPROUTETABLEEVENT == rclsid )
  48. {
  49. CIPRouteEventProviderClassFactory *lpunk = new CIPRouteEventProviderClassFactory ;
  50. if ( lpunk == NULL )
  51. {
  52. hr = E_OUTOFMEMORY ;
  53. }
  54. else
  55. {
  56. hr = lpunk->QueryInterface ( riid , ppv ) ;
  57. if ( FAILED ( hr ) )
  58. {
  59. delete lpunk ;
  60. }
  61. }
  62. }
  63. else
  64. {
  65. hr = E_FAIL;
  66. }
  67. }
  68. catch ( ... )
  69. {
  70. hr = E_OUTOFMEMORY;
  71. }
  72. return hr;
  73. }
  74. //***************************************************************************
  75. //
  76. // DllCanUnloadNow
  77. //
  78. // Purpose: Called periodically by Ole in order to determine if the
  79. // DLL can be freed.
  80. //
  81. // Return: S_OK if there are no objects in use and the class factory
  82. // isn't locked.
  83. //
  84. //***************************************************************************
  85. STDAPI DllCanUnloadNow ()
  86. {
  87. SCODE sc = S_FALSE;
  88. try
  89. {
  90. if (CIPRouteEventProviderClassFactory::DllCanUnloadNow())
  91. {
  92. sc = CommonCanUnloadNow(PROVIDER_NAME, g_cLock);
  93. }
  94. }
  95. catch ( ... )
  96. {
  97. // sc should already be set correctly
  98. }
  99. return sc;
  100. }
  101. //***************************************************************************
  102. //
  103. // DllRegisterServer
  104. //
  105. // Purpose: Called during setup or by regsvr32.
  106. //
  107. // Return: NOERROR if registration successful, error otherwise.
  108. //***************************************************************************
  109. STDAPI DllRegisterServer(void)
  110. {
  111. HRESULT t_status = S_OK;
  112. try
  113. {
  114. t_status = RegisterServer( _T("WBEM IP Route Provider"), CLSID_CIPROUTETABLE ) ;
  115. if( NOERROR == t_status )
  116. {
  117. t_status = RegisterServer( _T("WBEM IP Route Event Provider"), CLSID_CIPROUTETABLEEVENT ) ;
  118. }
  119. }
  120. catch ( ... )
  121. {
  122. t_status = E_OUTOFMEMORY;
  123. }
  124. return t_status;
  125. }
  126. //***************************************************************************
  127. //
  128. // DllUnregisterServer
  129. //
  130. // Purpose: Called when it is time to remove the registry entries.
  131. //
  132. // Return: NOERROR if registration successful, error otherwise.
  133. //***************************************************************************
  134. STDAPI DllUnregisterServer(void)
  135. {
  136. HRESULT t_status = S_OK;
  137. try
  138. {
  139. t_status = UnregisterServer( CLSID_CIPROUTETABLE ) ;
  140. if( NOERROR == t_status )
  141. {
  142. t_status = UnregisterServer( CLSID_CIPROUTETABLEEVENT ) ;
  143. }
  144. }
  145. catch ( ... )
  146. {
  147. t_status = E_OUTOFMEMORY;
  148. }
  149. return t_status ;
  150. }
  151. //***************************************************************************
  152. //
  153. // DllMain
  154. //
  155. // Purpose: Called by the operating system when processes and threads are
  156. // initialized and terminated, or upon calls to the LoadLibrary
  157. // and FreeLibrary functions
  158. //
  159. // Return: TRUE if load was successful, else FALSE
  160. //***************************************************************************
  161. BOOL APIENTRY DllMain( HINSTANCE hInstDLL, // handle to DLL module
  162. DWORD fdwReason, // reason for calling function
  163. LPVOID lpReserved ) // reserved
  164. {
  165. BOOL bRet = TRUE;
  166. try
  167. {
  168. LogMessage2( L"%s -> DllMain", PROVIDER_NAME);
  169. // Perform actions based on the reason for calling.
  170. switch( fdwReason )
  171. {
  172. case DLL_PROCESS_ATTACH:
  173. {
  174. bRet = CommonProcessAttach(PROVIDER_NAME, g_cLock, hInstDLL);
  175. }
  176. break;
  177. case DLL_THREAD_ATTACH:
  178. {
  179. // Do thread-specific initialization.
  180. }
  181. break;
  182. case DLL_THREAD_DETACH:
  183. {
  184. // Do thread-specific cleanup.
  185. }
  186. break;
  187. case DLL_PROCESS_DETACH:
  188. {
  189. // Perform any necessary cleanup.
  190. LogMessage( L"DLL_PROCESS_DETACH" );
  191. }
  192. break;
  193. }
  194. }
  195. catch ( ... )
  196. {
  197. bRet = FALSE;
  198. }
  199. return bRet ; // Status of DLL_PROCESS_ATTACH.
  200. }