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.

220 lines
5.1 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 <brodcast.h>
  19. #include "FactoryRouter.h"
  20. #include "ResourceManager.h"
  21. #include "timerqueue.h"
  22. HMODULE ghModule ;
  23. // {4AF3F4A4-06C8-4b79-A523-633CC65CE297}
  24. DEFINE_GUID(CLSID_DISKQUOTAVOLUME,
  25. 0x4af3f4a4, 0x6c8, 0x4b79, 0xa5, 0x23, 0x63, 0x3c, 0xc6, 0x5c, 0xe2, 0x97);
  26. #define PROVIDER_NAME L"WMIPDSKQ"
  27. // Globals from using ciwin32 library
  28. CFactoryRouterData g_FactoryRouterData;
  29. CTimerQueue CTimerQueue :: s_TimerQueue ;
  30. CResourceManager CResourceManager::sm_TheResourceManager ;
  31. //Count number of objects and number of locks.
  32. long g_cLock = 0 ;
  33. //***************************************************************************
  34. //
  35. // DllGetClassObject
  36. //
  37. // Purpose: Called by Ole when some client wants a class factory. Return
  38. // one only if it is the sort of class this DLL supports.
  39. //
  40. //***************************************************************************
  41. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, PPVOID ppv)
  42. {
  43. HRESULT hr = S_OK;
  44. try
  45. {
  46. if ( CLSID_DISKQUOTAVOLUME == rclsid )
  47. {
  48. hr = CommonGetClassObject(riid, ppv, PROVIDER_NAME, g_cLock);
  49. }
  50. else
  51. {
  52. hr = E_FAIL;
  53. }
  54. }
  55. catch ( ... )
  56. {
  57. hr = E_OUTOFMEMORY;
  58. }
  59. return hr ;
  60. }
  61. //***************************************************************************
  62. //
  63. // DllCanUnloadNow
  64. //
  65. // Purpose: Called periodically by Ole in order to determine if the
  66. // DLL can be freed.
  67. //
  68. // Return: S_OK if there are no objects in use and the class factory
  69. // isn't locked.
  70. //
  71. //***************************************************************************
  72. STDAPI DllCanUnloadNow ()
  73. {
  74. SCODE sc = S_FALSE;
  75. try
  76. {
  77. sc = CommonCanUnloadNow(PROVIDER_NAME, g_cLock);
  78. }
  79. catch ( ... )
  80. {
  81. // sc should already be set correctly
  82. }
  83. return sc;
  84. }
  85. //***************************************************************************
  86. //
  87. // DllRegisterServer
  88. //
  89. // Purpose: Called during setup or by regsvr32.
  90. //
  91. // Return: NOERROR if registration successful, error otherwise.
  92. //***************************************************************************
  93. STDAPI DllRegisterServer(void)
  94. {
  95. HRESULT t_status = S_OK;
  96. try
  97. {
  98. t_status = RegisterServer( _T("WBEM Disk Quota Volume Provider"), CLSID_DISKQUOTAVOLUME ) ;
  99. }
  100. catch ( ... )
  101. {
  102. t_status = E_OUTOFMEMORY;
  103. }
  104. return t_status ;
  105. }
  106. //***************************************************************************
  107. //
  108. // DllUnregisterServer
  109. //
  110. // Purpose: Called when it is time to remove the registry entries.
  111. //
  112. // Return: NOERROR if registration successful, error otherwise.
  113. //***************************************************************************
  114. STDAPI DllUnregisterServer(void)
  115. {
  116. HRESULT t_status = S_OK;
  117. try
  118. {
  119. t_status = UnregisterServer( CLSID_DISKQUOTAVOLUME ) ;
  120. }
  121. catch ( ... )
  122. {
  123. t_status = E_OUTOFMEMORY;
  124. }
  125. return t_status;
  126. }
  127. //***************************************************************************
  128. //
  129. // DllMain
  130. //
  131. // Purpose: Called by the operating system when processes and threads are
  132. // initialized and terminated, or upon calls to the LoadLibrary
  133. // and FreeLibrary functions
  134. //
  135. // Return: TRUE if load was successful, else FALSE
  136. //***************************************************************************
  137. BOOL APIENTRY DllMain( HINSTANCE hInstDLL, // handle to DLL module
  138. DWORD fdwReason, // reason for calling function
  139. LPVOID lpReserved ) // reserved
  140. {
  141. BOOL bRet = TRUE;
  142. try
  143. {
  144. LogMessage2( L"%s -> DllMain", PROVIDER_NAME);
  145. // Perform actions based on the reason for calling.
  146. switch( fdwReason )
  147. {
  148. case DLL_PROCESS_ATTACH:
  149. {
  150. bRet = CommonProcessAttach(PROVIDER_NAME, g_cLock, hInstDLL);
  151. }
  152. break;
  153. case DLL_THREAD_ATTACH:
  154. {
  155. // Do thread-specific initialization.
  156. }
  157. break;
  158. case DLL_THREAD_DETACH:
  159. {
  160. // Do thread-specific cleanup.
  161. }
  162. break;
  163. case DLL_PROCESS_DETACH:
  164. {
  165. // Perform any necessary cleanup.
  166. LogMessage( L"DLL_PROCESS_DETACH" );
  167. }
  168. break;
  169. }
  170. }
  171. catch ( ... )
  172. {
  173. bRet = FALSE;
  174. }
  175. return bRet ; // Status of DLL_PROCESS_ATTACH.
  176. }