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.

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