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.

201 lines
5.2 KiB

  1. /*++
  2. Copyright (C) 1995-2001 Microsoft Corporation
  3. Module Name:
  4. STDPROV.CPP
  5. Abstract:
  6. Contains DLL entry points. Also has code that controls
  7. when the DLL can be unloaded by tracking the number of
  8. object. Also holds various utility classes and
  9. functions.
  10. History:
  11. a-davj 9-27-95 Created.
  12. --*/
  13. #include "precomp.h"
  14. #include <wbemidl.h>
  15. #include <genutils.h>
  16. #include "cvariant.h"
  17. #include "cfdyn.h"
  18. #include "provreg.h"
  19. #include "provperf.h"
  20. #include <regeprov.h>
  21. // Count number of objects and number of locks so DLL can know when to unload
  22. long lObj = 0;
  23. long lLock = 0;
  24. HINSTANCE ghModule = NULL;
  25. //***************************************************************************
  26. //
  27. // BOOL WINAPI DllMain
  28. //
  29. // DESCRIPTION:
  30. //
  31. // Entry point for DLL. Good place for initialization.
  32. //
  33. // PARAMETERS:
  34. //
  35. // hInstance instance handle
  36. // ulReason why we are being called
  37. // pvReserved reserved
  38. //
  39. // RETURN VALUE:
  40. //
  41. // TRUE if OK.
  42. //
  43. //***************************************************************************
  44. BOOL WINAPI DllMain(
  45. IN HINSTANCE hInstance,
  46. IN ULONG ulReason,
  47. LPVOID pvReserved)
  48. {
  49. if(ghModule == NULL)
  50. {
  51. ghModule = hInstance;
  52. }
  53. if (DLL_PROCESS_DETACH==ulReason)
  54. {
  55. return TRUE;
  56. }
  57. else if (DLL_PROCESS_ATTACH==ulReason)
  58. {
  59. return TRUE;
  60. }
  61. return TRUE;
  62. }
  63. //***************************************************************************
  64. //
  65. // STDAPI DllGetClassObject
  66. //
  67. // DESCRIPTION:
  68. //
  69. // Called when Ole wants a class factory. Return one only if it is the sort
  70. // of class this DLL supports.
  71. //
  72. // PARAMETERS:
  73. //
  74. // rclsid CLSID of the object that is desired.
  75. // riid ID of the desired interface.
  76. // ppv Set to the class factory.
  77. //
  78. // RETURN VALUE:
  79. //
  80. // S_OK all is well
  81. // E_FAILED not something we support
  82. // E_OUTOFMEMORY out of memory
  83. //
  84. //***************************************************************************
  85. STDAPI DllGetClassObject(
  86. IN REFCLSID rclsid,
  87. IN REFIID riid,
  88. OUT PPVOID ppv)
  89. {
  90. HRESULT hr;
  91. // CCFDyn *pObj;
  92. IClassFactory *pObj;
  93. // **** FOR EACH PROVIDER ***
  94. if (CLSID_RegProvider ==rclsid)
  95. pObj=new CCFReg();
  96. else if (CLSID_RegPropProv ==rclsid)
  97. pObj=new CCFRegProp();
  98. else if (CLSID_PerfProvider ==rclsid)
  99. pObj=new CCFPerf();
  100. else if (CLSID_PerfPropProv ==rclsid)
  101. pObj=new CCFPerfProp();
  102. else if (CLSID_RegistryEventProvider ==rclsid)
  103. pObj=new CRegEventProviderFactory;
  104. else
  105. return ResultFromScode(E_FAIL);
  106. // **** FOR EACH PROVIDER ***
  107. if (NULL==pObj)
  108. return ResultFromScode(E_OUTOFMEMORY);
  109. hr=pObj->QueryInterface(riid, ppv);
  110. if (FAILED(hr))
  111. delete pObj;
  112. return hr;
  113. }
  114. //***************************************************************************
  115. //
  116. // STDAPI DllCanUnloadNow
  117. //
  118. // DESCRIPTION:
  119. //
  120. // Answers if the DLL can be freed, that is, if there are no
  121. // references to anything this DLL provides.
  122. //
  123. // RETURN VALUE:
  124. //
  125. // S_OK if it is OK to unload
  126. // S_FALSE if still in use
  127. //
  128. //***************************************************************************
  129. STDAPI DllCanUnloadNow(void)
  130. {
  131. if(lLock == 0 && lObj == 0)
  132. return S_OK;
  133. else
  134. return S_FALSE;
  135. }
  136. //***************************************************************************
  137. //
  138. // DllRegisterServer
  139. //
  140. // Purpose: Called during setup or by regsvr32.
  141. //
  142. // Return: NOERROR if registration successful, error otherwise.
  143. //***************************************************************************
  144. STDAPI DllRegisterServer(void)
  145. {
  146. RegisterDLL(ghModule, CLSID_RegProvider, __TEXT("WBEM Registry Instance Provider"), __TEXT("Both"), NULL);
  147. RegisterDLL(ghModule, CLSID_RegPropProv, __TEXT("WBEM Registry Property Provider"), __TEXT("Both"), NULL);
  148. if(IsNT())
  149. {
  150. RegisterDLL(ghModule, CLSID_PerfProvider, __TEXT("WBEM PerfMon Instance Provider"), __TEXT("Both"), NULL);
  151. RegisterDLL(ghModule, CLSID_PerfPropProv, __TEXT("WBEM PerfMon Property Provider"), __TEXT("Both"), NULL);
  152. }
  153. RegisterDLL(ghModule, CLSID_RegistryEventProvider,
  154. __TEXT("WBEM Registry Event Provider"), __TEXT("Both"), NULL);
  155. return S_OK;
  156. }
  157. //***************************************************************************
  158. //
  159. // DllUnregisterServer
  160. //
  161. // Purpose: Called when it is time to remove the registry entries.
  162. //
  163. // Return: NOERROR if registration successful, error otherwise.
  164. //***************************************************************************
  165. STDAPI DllUnregisterServer(void)
  166. {
  167. UnRegisterDLL(CLSID_RegProvider, NULL);
  168. UnRegisterDLL(CLSID_RegPropProv, NULL);
  169. UnRegisterDLL(CLSID_PerfProvider, NULL);
  170. UnRegisterDLL(CLSID_PerfPropProv, NULL);
  171. UnRegisterDLL(CLSID_RegistryEventProvider, NULL);
  172. return NOERROR;
  173. }