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.

222 lines
6.3 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #include "stdenum.h"
  4. #include <mshtmdid.h>
  5. #include "shdispid.h"
  6. /////////////////////////////////////////////
  7. // Migration Wizard OOBE Automation Object //
  8. /////////////////////////////////////////////
  9. // This object handles automation calls from
  10. // OOBE (Out Of Box Experience) and contains
  11. // the Migration Wizard Engine located in migoobe.dll.
  12. //
  13. // Someday, this code will live inside of migoobe.dll,
  14. // but we didn't have time to generate an entirely new
  15. // typelib for migoobe.dll so we piggybacked on shell32's
  16. // to make the development of the automation quicker to
  17. // satisfy time constraints.
  18. /////////////////////////////////////////////
  19. // {E7562536-2D53-4f63-A749-84F7D4FC93E8}
  20. extern "C" const CLSID CLSID_MigWizEngine =
  21. { 0xe7562536, 0x2d53, 0x4f63, { 0xa7, 0x49, 0x84, 0xf7, 0xd4, 0xfc, 0x93, 0xe8 } };
  22. class ATL_NO_VTABLE CMigrationWizardAuto
  23. : public CComObjectRootEx<CComSingleThreadModel>
  24. , public CComCoClass<CMigrationWizardAuto, &CLSID_MigrationWizardAuto>
  25. , public IObjectWithSiteImpl<CMigrationWizardAuto>
  26. , public IDispatchImpl<IMigrationWizardAuto, &IID_IMigrationWizardAuto, &LIBID_Shell32>
  27. , public IConnectionPointContainerImpl<CMigrationWizardAuto>
  28. , public IConnectionPointImpl<CMigrationWizardAuto, &DIID_DMigrationWizardAutoEvents>
  29. , public IProvideClassInfo2Impl<&CLSID_MigrationWizardAuto, &DIID_DMigrationWizardAutoEvents, &LIBID_Shell32>
  30. // maybe , public IObjectWithSite
  31. {
  32. public:
  33. CMigrationWizardAuto();
  34. ~CMigrationWizardAuto();
  35. DECLARE_REGISTRY_RESOURCEID(IDR_MIGWIZAUTO)
  36. DECLARE_NOT_AGGREGATABLE(CMigrationWizardAuto)
  37. BEGIN_COM_MAP(CMigrationWizardAuto)
  38. // ATL Uses these in IUnknown::QueryInterface()
  39. COM_INTERFACE_ENTRY(IMigrationWizardAuto)
  40. COM_INTERFACE_ENTRY(IDispatch)
  41. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  42. COM_INTERFACE_ENTRY_IMPL(IObjectWithSite) // maybe nuke _IMPL
  43. COM_INTERFACE_ENTRY(IProvideClassInfo)
  44. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  45. END_COM_MAP()
  46. BEGIN_CONNECTION_POINT_MAP(CMigrationWizardAuto)
  47. CONNECTION_POINT_ENTRY(DIID_DMigrationWizardAutoEvents)
  48. END_CONNECTION_POINT_MAP()
  49. // IObjectWithSite
  50. STDMETHODIMP SetSite(IUnknown * punk);
  51. // IDispatch
  52. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr);
  53. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  54. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid);
  55. // IMigrationWizardAuto
  56. STDMETHODIMP CreateToolDisk(BSTR pszDrivePath, BSTR pszFilesPath, BSTR pszManifest);
  57. STDMETHODIMP ApplySettings(BSTR pszStore);
  58. STDMETHODIMP Cancel();
  59. protected:
  60. HRESULT _InitInner(void);
  61. // HRESULT _FireDebug();
  62. private:
  63. ITypeInfo* m_pTypeInfo;
  64. IMigrationWizardAuto * m_pInner;
  65. };
  66. LCID g_lcidLocaleUnicppMigWiz = MAKELCID(LANG_USER_DEFAULT, SORT_DEFAULT);
  67. STDAPI CMigrationWizardAuto_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppvOut)
  68. {
  69. return CComCreator< CComPolyObject< CMigrationWizardAuto > >::CreateInstance((void *) punkOuter, riid, ppvOut);
  70. }
  71. CMigrationWizardAuto::CMigrationWizardAuto() : m_pTypeInfo(NULL)
  72. {
  73. IID* pIID = (IID*)&IID_IMigrationWizardAuto;
  74. GUID* pLIBID = (GUID*)&LIBID_Shell32;
  75. WORD wMajor = 1;
  76. WORD wMinor = 0;
  77. ITypeLib* ptl = 0;
  78. HRESULT hr = LoadRegTypeLib(*pLIBID, wMajor, wMinor, 0, &ptl);
  79. m_pInner = NULL;
  80. if (SUCCEEDED(hr))
  81. {
  82. hr = ptl->GetTypeInfoOfGuid(*pIID, &m_pTypeInfo);
  83. ptl->Release();
  84. }
  85. DllAddRef();
  86. }
  87. CMigrationWizardAuto::~CMigrationWizardAuto()
  88. {
  89. ATOMICRELEASE(m_pInner);
  90. if (m_pTypeInfo)
  91. {
  92. m_pTypeInfo->Release();
  93. }
  94. DllRelease();
  95. }
  96. HRESULT CMigrationWizardAuto::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** ppITypeInfo)
  97. {
  98. if (itinfo != 0)
  99. {
  100. return (*ppITypeInfo = 0), DISP_E_BADINDEX;
  101. }
  102. else
  103. {
  104. return (*ppITypeInfo = m_pTypeInfo)->AddRef(), S_OK;
  105. }
  106. }
  107. HRESULT CMigrationWizardAuto::GetIDsOfNames(REFIID /*riid*/, LPOLESTR* rgszNames,
  108. UINT cNames, LCID lcid, DISPID* rgdispid)
  109. {
  110. return m_pTypeInfo->GetIDsOfNames(rgszNames, cNames, rgdispid);
  111. }
  112. HRESULT CMigrationWizardAuto::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams,
  113. VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
  114. {
  115. return m_pTypeInfo->Invoke(static_cast<IMigrationWizardAuto*>(this),
  116. dispidMember, wFlags, pdispparams, pvarResult,
  117. pexcepinfo, puArgErr);
  118. }
  119. ///////////////////////////////////////////////////////////////////////////////
  120. ///////////////////////////////////////////////////////////////////////////////
  121. ///////////////////////////////////////////////////////////////////////////////
  122. STDMETHODIMP CMigrationWizardAuto::SetSite(IUnknown * punk)
  123. {
  124. if (m_pInner && !punk)
  125. {
  126. // Break back pointer
  127. IUnknown_SetSite(m_pInner, NULL);
  128. }
  129. return IObjectWithSiteImpl<CMigrationWizardAuto>::SetSite(punk);
  130. }
  131. HRESULT CMigrationWizardAuto::_InitInner(void)
  132. {
  133. HRESULT hr = S_OK;
  134. if (!m_pInner)
  135. {
  136. hr = CoCreateInstance(CLSID_MigWizEngine, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IMigrationWizardAuto, &m_pInner));
  137. if (SUCCEEDED(hr))
  138. {
  139. IUnknown_SetSite(m_pInner, reinterpret_cast<IUnknown*>(this));
  140. }
  141. }
  142. return hr;
  143. }
  144. STDMETHODIMP CMigrationWizardAuto::CreateToolDisk(BSTR pszDrivePath, BSTR pszFilesPath, BSTR pszManifest)
  145. {
  146. HRESULT hr = _InitInner();
  147. if (SUCCEEDED(hr))
  148. {
  149. hr = m_pInner->CreateToolDisk(pszDrivePath, pszFilesPath, pszManifest);
  150. // Done by inner
  151. }
  152. return hr;
  153. }
  154. STDMETHODIMP CMigrationWizardAuto::ApplySettings(BSTR pszStore)
  155. {
  156. HRESULT hr = _InitInner();
  157. if (SUCCEEDED(hr))
  158. {
  159. hr = m_pInner->ApplySettings(pszStore);
  160. // Done by inner
  161. }
  162. return hr;
  163. }
  164. STDMETHODIMP CMigrationWizardAuto::Cancel()
  165. {
  166. HRESULT hr = _InitInner();
  167. if (SUCCEEDED(hr))
  168. {
  169. hr = m_pInner->Cancel();
  170. // Done by inner
  171. }
  172. return hr;
  173. }