Source code of Windows XP (NT5)
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.

258 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000
  6. //
  7. // File: aucpl.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "pch.h"
  11. #pragma hdrstop
  12. HINSTANCE g_hInstance = NULL;
  13. LONG g_cRefDll = 0;
  14. // {5F327514-6C5E-4d60-8F16-D07FA08A78ED}
  15. //DEFINE_GUID(CLSID_AutoUpdatePropSheet,
  16. //0x5f327514, 0x6c5e, 0x4d60, 0x8f, 0x16, 0xd0, 0x7f, 0xa0, 0x8a, 0x78, 0xed);
  17. class __declspec(uuid("5f327514-6c5e-4d60-8f16-d07fa08a78ed")) CAutoUpdatePropSheet;
  18. //-----------------------------------------------------------------------------
  19. // COM server class factory.
  20. //-----------------------------------------------------------------------------
  21. class CAutoUpdateClassFactory : IClassFactory
  22. {
  23. public:
  24. ~CAutoUpdateClassFactory(void);
  25. //
  26. // IUnknown methods
  27. //
  28. STDMETHOD(QueryInterface)(REFIID riid, void **ppvOut);
  29. STDMETHOD_(ULONG, AddRef)(void);
  30. STDMETHOD_(ULONG, Release)(void);
  31. //
  32. // IClassFactory methods
  33. //
  34. STDMETHOD(CreateInstance)(LPUNKNOWN pUnkOuter, REFIID riid, void **ppvOut);
  35. STDMETHOD(LockServer)(BOOL);
  36. //
  37. // Instance generator.
  38. //
  39. static HRESULT CreateInstance(REFIID riid, void **ppvOut);
  40. private:
  41. LONG m_cRef;
  42. //
  43. // Force use of instance generator.
  44. //
  45. CAutoUpdateClassFactory(void);
  46. //
  47. // Prevent copy.
  48. //
  49. CAutoUpdateClassFactory(const CAutoUpdateClassFactory& rhs); // not implemented.
  50. CAutoUpdateClassFactory& operator = (const CAutoUpdateClassFactory& rhs); // not implemented.
  51. };
  52. //
  53. // Instance generator.
  54. //
  55. HRESULT
  56. CAutoUpdateClassFactory::CreateInstance( // [static]
  57. REFIID riid,
  58. void **ppvOut
  59. )
  60. {
  61. HRESULT hr = E_OUTOFMEMORY;
  62. CAutoUpdateClassFactory *pFactory = new CAutoUpdateClassFactory();
  63. if (NULL != pFactory)
  64. {
  65. hr = pFactory->QueryInterface(riid, ppvOut);
  66. pFactory->Release();
  67. }
  68. return hr;
  69. }
  70. CAutoUpdateClassFactory::CAutoUpdateClassFactory(void)
  71. : m_cRef(1)
  72. {
  73. DllAddRef();
  74. }
  75. CAutoUpdateClassFactory::~CAutoUpdateClassFactory(void)
  76. {
  77. DllRelease();
  78. }
  79. STDMETHODIMP
  80. CAutoUpdateClassFactory::QueryInterface(
  81. REFIID riid,
  82. void **ppvOut
  83. )
  84. {
  85. HRESULT hr = E_NOINTERFACE;
  86. if (NULL == ppvOut)
  87. return E_INVALIDARG;
  88. *ppvOut = NULL;
  89. if (IID_IClassFactory == riid || IID_IUnknown == riid)
  90. {
  91. *ppvOut = static_cast<IClassFactory *>(this);
  92. }
  93. if (NULL != *ppvOut)
  94. {
  95. ((LPUNKNOWN)*ppvOut)->AddRef();
  96. hr = NOERROR;
  97. }
  98. return hr;
  99. }
  100. STDMETHODIMP_(ULONG) CAutoUpdateClassFactory::AddRef(void)
  101. {
  102. return InterlockedIncrement(&m_cRef);
  103. }
  104. STDMETHODIMP_(ULONG) CAutoUpdateClassFactory::Release(void)
  105. {
  106. if (InterlockedDecrement(&m_cRef))
  107. return m_cRef;
  108. delete this;
  109. return 0;
  110. }
  111. STDMETHODIMP
  112. CAutoUpdateClassFactory::CreateInstance(
  113. IUnknown *pUnkOuter,
  114. REFIID riid,
  115. void **ppvOut
  116. )
  117. {
  118. HRESULT hr = CLASS_E_NOAGGREGATION;
  119. if (NULL == ppvOut)
  120. {
  121. return E_INVALIDARG;
  122. }
  123. *ppvOut = NULL;
  124. if (NULL == pUnkOuter)
  125. {
  126. if (IID_IShellExtInit == riid ||
  127. IID_IShellPropSheetExt == riid ||
  128. IID_IUnknown == riid)
  129. {
  130. hr = CAutoUpdatePropSheet_CreateInstance(g_hInstance, riid, ppvOut);
  131. }
  132. else
  133. {
  134. hr = E_NOINTERFACE;
  135. }
  136. }
  137. return hr;
  138. }
  139. STDMETHODIMP
  140. CAutoUpdateClassFactory::LockServer(
  141. BOOL fLock
  142. )
  143. {
  144. if (fLock)
  145. DllAddRef();
  146. else
  147. DllRelease();
  148. return S_OK;
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Standard COM server exports.
  152. //-----------------------------------------------------------------------------
  153. STDAPI
  154. DllGetClassObject(
  155. REFCLSID rclsid,
  156. REFIID riid,
  157. void **ppvOut
  158. )
  159. {
  160. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  161. if (NULL == ppvOut)
  162. {
  163. return E_INVALIDARG;
  164. }
  165. *ppvOut = NULL;
  166. if (__uuidof(CAutoUpdatePropSheet) == rclsid)
  167. {
  168. hr = CAutoUpdateClassFactory::CreateInstance(riid, ppvOut);
  169. }
  170. return hr;
  171. }
  172. STDAPI DllCanUnloadNow(void)
  173. {
  174. HRESULT hr = (0 == g_cRefDll ? S_OK : S_FALSE);
  175. return hr;
  176. }
  177. STDAPI_(void) DllAddRef(void)
  178. {
  179. InterlockedIncrement(&g_cRefDll);
  180. }
  181. STDAPI_(void) DllRelease(void)
  182. {
  183. InterlockedDecrement(&g_cRefDll);
  184. }
  185. BOOL APIENTRY
  186. DllMain(
  187. HANDLE hModule,
  188. DWORD dwReason,
  189. LPVOID /*lpReserved*/
  190. )
  191. {
  192. switch (dwReason)
  193. {
  194. case DLL_PROCESS_ATTACH:
  195. g_hInstance = (HINSTANCE)hModule;
  196. DisableThreadLibraryCalls(g_hInstance);
  197. break;
  198. case DLL_THREAD_ATTACH:
  199. case DLL_THREAD_DETACH:
  200. case DLL_PROCESS_DETACH:
  201. break;
  202. }
  203. return TRUE;
  204. }