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.

238 lines
6.0 KiB

  1. #include "precomp.h"
  2. #include "advpub.h" // For REGINSTALL
  3. #pragma hdrstop
  4. #define DECL_CRTFREE
  5. #include <crtfree.h>
  6. // Fix the debug builds
  7. #define SZ_DEBUGINI "ccshell.ini"
  8. #define SZ_DEBUGSECTION "resize"
  9. #define SZ_MODULE "resize"
  10. #define DECLARE_DEBUG
  11. #include "debug.h"
  12. // interface stuff
  13. // CLSID_ResizePhotos {1530f7ee-5128-43bd-9977-84a4b0fad7df}
  14. const CLSID CLSID_ResizePhotos = {0x1530f7ee,0x5128,0x43bd,{0x99, 0x77, 0x84, 0xa4, 0xb0, 0xfa, 0xd7, 0xdf}};
  15. // CLSID_SlideshowExtension {efb97cb8-a4a4-4357-a261-002ffaed0267}
  16. const CLSID CLSID_SlideshowExtension = {0xefb97cb8,0xa4a4,0x4357,{0xa2, 0x61, 0x00, 0x2f, 0xfa, 0xed, 0x02, 0x67}};
  17. STDAPI CResizePhotos_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi);
  18. STDAPI CSlideshowExtension_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi);
  19. // shell/lib files look for this instance variable
  20. EXTERN_C HINSTANCE g_hinst = 0;
  21. LONG g_cLocks = 0;
  22. BOOL g_bMirroredOS = FALSE;
  23. // DLL lifetime stuff
  24. STDAPI_(BOOL) DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
  25. {
  26. if (dwReason == DLL_PROCESS_ATTACH)
  27. {
  28. g_hinst = hinstDLL; // For shell/lib files who extern him
  29. g_bMirroredOS = IS_MIRRORING_ENABLED();
  30. SHFusionInitializeFromModule(hinstDLL);
  31. }
  32. else if (dwReason == DLL_PROCESS_DETACH)
  33. {
  34. SHFusionUninitialize();
  35. }
  36. return TRUE; // Successful DLL_PROCESS_ATTACH.
  37. }
  38. STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine)
  39. {
  40. return S_OK;
  41. }
  42. STDAPI DllCanUnloadNow()
  43. {
  44. return (g_cLocks == 0) ? S_OK:S_FALSE;
  45. }
  46. STDAPI_(void) DllAddRef(void)
  47. {
  48. InterlockedIncrement(&g_cLocks);
  49. }
  50. STDAPI_(void) DllRelease(void)
  51. {
  52. InterlockedDecrement(&g_cLocks);
  53. }
  54. // helper to handle the SELFREG.INF parsing
  55. HRESULT _CallRegInstall(LPCSTR szSection, BOOL bUninstall)
  56. {
  57. HRESULT hr = E_FAIL;
  58. HINSTANCE hinstAdvPack = LoadLibrary(TEXT("ADVPACK.DLL"));
  59. if (hinstAdvPack)
  60. {
  61. REGINSTALL pfnri = (REGINSTALL)GetProcAddress(hinstAdvPack, "RegInstall");
  62. if (pfnri)
  63. {
  64. STRENTRY seReg[] = {
  65. { "25", "%SystemRoot%" },
  66. { "11", "%SystemRoot%\\system32" },
  67. };
  68. STRTABLE stReg = { ARRAYSIZE(seReg), seReg };
  69. hr = pfnri(g_hinst, szSection, &stReg);
  70. if (bUninstall)
  71. {
  72. // ADVPACK will return E_UNEXPECTED if you try to uninstall
  73. // (which does a registry restore) on an INF section that was
  74. // never installed. We uninstall sections that may never have
  75. // been installed, so ignore this error
  76. hr = ((E_UNEXPECTED == hr) ? S_OK : hr);
  77. }
  78. }
  79. FreeLibrary(hinstAdvPack);
  80. }
  81. return hr;
  82. }
  83. STDAPI DllRegisterServer()
  84. {
  85. return _CallRegInstall("RegDll", FALSE);
  86. }
  87. STDAPI DllUnregisterServer()
  88. {
  89. return S_OK;
  90. }
  91. //
  92. // This array holds information needed for ClassFacory.
  93. // OLEMISC_ flags are used by shembed and shocx.
  94. //
  95. // PERF: this table should be ordered in most-to-least used order
  96. //
  97. #define OIF_ALLOWAGGREGATION 0x0001
  98. CF_TABLE_BEGIN(g_ObjectInfo)
  99. CF_TABLE_ENTRY( &CLSID_ResizePhotos, CResizePhotos_CreateInstance, COCREATEONLY),
  100. CF_TABLE_ENTRY( &CLSID_SlideshowExtension, CSlideshowExtension_CreateInstance, COCREATEONLY),
  101. CF_TABLE_END(g_ObjectInfo)
  102. // constructor for CObjectInfo.
  103. CObjectInfo::CObjectInfo(CLSID const* pclsidin, LPFNCREATEOBJINSTANCE pfnCreatein, IID const* piidIn,
  104. IID const* piidEventsIn, long lVersionIn, DWORD dwOleMiscFlagsIn,
  105. DWORD dwClassFactFlagsIn)
  106. {
  107. pclsid = pclsidin;
  108. pfnCreateInstance = pfnCreatein;
  109. piid = piidIn;
  110. piidEvents = piidEventsIn;
  111. lVersion = lVersionIn;
  112. dwOleMiscFlags = dwOleMiscFlagsIn;
  113. dwClassFactFlags = dwClassFactFlagsIn;
  114. }
  115. // static class factory (no allocs!)
  116. STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void **ppvObj)
  117. {
  118. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  119. {
  120. *ppvObj = (void *)GET_ICLASSFACTORY(this);
  121. DllAddRef();
  122. return NOERROR;
  123. }
  124. *ppvObj = NULL;
  125. return E_NOINTERFACE;
  126. }
  127. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  128. {
  129. DllAddRef();
  130. return 2;
  131. }
  132. STDMETHODIMP_(ULONG) CClassFactory::Release()
  133. {
  134. DllRelease();
  135. return 1;
  136. }
  137. STDMETHODIMP CClassFactory::CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  138. {
  139. *ppv = NULL;
  140. if (punkOuter && !IsEqualIID(riid, IID_IUnknown))
  141. {
  142. // It is technically illegal to aggregate an object and request
  143. // any interface other than IUnknown. Enforce this.
  144. //
  145. return CLASS_E_NOAGGREGATION;
  146. }
  147. else
  148. {
  149. LPOBJECTINFO pthisobj = (LPOBJECTINFO)this;
  150. if (punkOuter && !(pthisobj->dwClassFactFlags & OIF_ALLOWAGGREGATION))
  151. return CLASS_E_NOAGGREGATION;
  152. IUnknown *punk;
  153. HRESULT hres = pthisobj->pfnCreateInstance(punkOuter, &punk, pthisobj);
  154. if (SUCCEEDED(hres))
  155. {
  156. hres = punk->QueryInterface(riid, ppv);
  157. punk->Release();
  158. }
  159. _ASSERT(FAILED(hres) ? *ppv == NULL : TRUE);
  160. return hres;
  161. }
  162. }
  163. STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
  164. {
  165. if (fLock)
  166. DllAddRef();
  167. else
  168. DllRelease();
  169. return S_OK;
  170. }
  171. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
  172. {
  173. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  174. *ppv = NULL;
  175. if (IsEqualIID(riid, IID_IClassFactory) || IsEqualIID(riid, IID_IUnknown))
  176. {
  177. for (LPCOBJECTINFO pcls = g_ObjectInfo; pcls->pclsid; pcls++)
  178. {
  179. if (IsEqualGUID(rclsid, *(pcls->pclsid)))
  180. {
  181. *ppv = (void*)pcls;
  182. DllAddRef(); // class factory holds DLL ref count
  183. hr = S_OK;
  184. }
  185. }
  186. }
  187. return hr;
  188. }