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.

202 lines
5.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. MAINDLL.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. objects and locks.
  9. History:
  10. a-davj 15-Aug-96 Created.
  11. --*/
  12. #include "precomp.h"
  13. #include <wbemidl.h>
  14. #include <wbemutil.h>
  15. #include <genutils.h>
  16. #include <cominit.h>
  17. #include <reg.h>
  18. #include "wbemprox.h"
  19. #include <initguid.h>
  20. #include <wbemint.h>
  21. #include <strsafe.h>
  22. //Count number of objects and number of locks.
  23. long g_cObj=0;
  24. ULONG g_cLock=0;
  25. HMODULE ghModule;
  26. //***************************************************************************
  27. //
  28. // BOOL WINAPI DllMain
  29. //
  30. // DESCRIPTION:
  31. //
  32. // Entry point for DLL. Good place for initialization.
  33. //
  34. // PARAMETERS:
  35. //
  36. // hInstance instance handle
  37. // ulReason why we are being called
  38. // pvReserved reserved
  39. //
  40. // RETURN VALUE:
  41. //
  42. // TRUE if OK.
  43. //
  44. //***************************************************************************
  45. BOOL WINAPI DllMain(
  46. IN HINSTANCE hInstance,
  47. IN ULONG ulReason,
  48. LPVOID pvReserved)
  49. {
  50. if(ghModule == NULL)
  51. {
  52. ghModule = hInstance;
  53. DisableThreadLibraryCalls ( hInstance ) ;
  54. }
  55. if (DLL_PROCESS_DETACH==ulReason)
  56. {
  57. return TRUE;
  58. }
  59. else
  60. {
  61. if (DLL_PROCESS_ATTACH!=ulReason)
  62. {
  63. }
  64. }
  65. return TRUE;
  66. }
  67. //***************************************************************************
  68. //
  69. // STDAPI DllGetClassObject
  70. //
  71. // DESCRIPTION:
  72. //
  73. // Called when Ole wants a class factory. Return one only if it is the sort
  74. // of class this DLL supports.
  75. //
  76. // PARAMETERS:
  77. //
  78. // rclsid CLSID of the object that is desired.
  79. // riid ID of the desired interface.
  80. // ppv Set to the class factory.
  81. //
  82. // RETURN VALUE:
  83. //
  84. // S_OK all is well
  85. // E_FAILED not something we support
  86. //
  87. //***************************************************************************
  88. STDAPI DllGetClassObject(
  89. IN REFCLSID rclsid,
  90. IN REFIID riid,
  91. OUT PPVOID ppv)
  92. {
  93. HRESULT hr;
  94. CLocatorFactory *pObj = NULL;
  95. if (CLSID_WbemLocator == rclsid)
  96. pObj=new CLocatorFactory(LOCATOR);
  97. else if(CLSID_WbemAdministrativeLocator == rclsid)
  98. pObj=new CLocatorFactory(ADMINLOC);
  99. else if(CLSID_WbemAuthenticatedLocator == rclsid)
  100. pObj=new CLocatorFactory(AUTHLOC);
  101. else if(CLSID_WbemUnauthenticatedLocator == rclsid)
  102. pObj=new CLocatorFactory(UNAUTHLOC);
  103. if(pObj == NULL)
  104. return E_FAIL;
  105. if (NULL==pObj)
  106. return ResultFromScode(E_OUTOFMEMORY);
  107. hr=pObj->QueryInterface(riid, ppv);
  108. if (FAILED(hr))
  109. delete pObj;
  110. return hr;
  111. }
  112. //***************************************************************************
  113. //
  114. // STDAPI DllCanUnloadNow
  115. //
  116. // DESCRIPTION:
  117. //
  118. // Answers if the DLL can be freed, that is, if there are no
  119. // references to anything this DLL provides.
  120. //
  121. // RETURN VALUE:
  122. //
  123. // S_OK if it is OK to unload
  124. // S_FALSE if still in use
  125. //
  126. //***************************************************************************
  127. STDAPI DllCanUnloadNow(void)
  128. {
  129. SCODE sc;
  130. //It is OK to unload if there are no objects or locks on the
  131. // class factory.
  132. sc=(0L==g_cObj && 0L==g_cLock) ? S_OK : S_FALSE;
  133. return ResultFromScode(sc);
  134. }
  135. //***************************************************************************
  136. //
  137. // DllRegisterServer
  138. //
  139. // Purpose: Called during setup or by regsvr32.
  140. //
  141. // Return: NOERROR if registration successful, error otherwise.
  142. //***************************************************************************
  143. #define LocatorPROGID __TEXT("WBEMComLocator")
  144. #define ConnectionPROGID __TEXT("WBEMComConnection")
  145. STDAPI DllRegisterServer(void)
  146. {
  147. RegisterDLL(ghModule, CLSID_WbemLocator, __TEXT("WBEM Locator"), __TEXT("Both"), LocatorPROGID);
  148. RegisterDLL(ghModule, CLSID_WbemAdministrativeLocator, __TEXT(""), __TEXT("Both"), NULL);
  149. RegisterDLL(ghModule, CLSID_WbemAuthenticatedLocator, __TEXT(""), __TEXT("Both"), NULL);
  150. RegisterDLL(ghModule, CLSID_WbemUnauthenticatedLocator, __TEXT(""), __TEXT("Both"), NULL);
  151. return S_OK;
  152. }
  153. //***************************************************************************
  154. //
  155. // DllUnregisterServer
  156. //
  157. // Purpose: Called when it is time to remove the registry entries.
  158. //
  159. // Return: NOERROR if registration successful, error otherwise.
  160. //***************************************************************************
  161. STDAPI DllUnregisterServer(void)
  162. {
  163. UnRegisterDLL(CLSID_WbemLocator,LocatorPROGID);
  164. UnRegisterDLL(CLSID_WbemAdministrativeLocator, NULL);
  165. UnRegisterDLL(CLSID_WbemAuthenticatedLocator, NULL);
  166. UnRegisterDLL(CLSID_WbemUnauthenticatedLocator, NULL);
  167. return NOERROR;
  168. }