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.

281 lines
5.6 KiB

  1. // PlugIn.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "driver.h"
  5. #include "PlugIn.h"
  6. #include "VSEdit.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPlugIn property page
  14. IMPLEMENT_DYNCREATE(CPlugIn, CPropertyPage)
  15. CPlugIn::CPlugIn() : CPropertyPage(CPlugIn::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CPlugIn)
  18. m_ProgID = _T("");
  19. //}}AFX_DATA_INIT
  20. m_pPlugIn = NULL;
  21. }
  22. CPlugIn::~CPlugIn()
  23. {
  24. if ( m_pPlugIn )
  25. m_pPlugIn->Release();
  26. }
  27. void CPlugIn::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CPropertyPage::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CPlugIn)
  31. DDX_Text(pDX, IDC_PROG_ID, m_ProgID);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CPlugIn, CPropertyPage)
  35. //{{AFX_MSG_MAP(CPlugIn)
  36. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  37. ON_BN_CLICKED(IDC_CREATE_INSTANCE, OnCreateInstance)
  38. ON_BN_CLICKED(IDC_EDIT_VARSET, OnEditVarset)
  39. ON_BN_CLICKED(IDC_GET_DESC, OnGetDesc)
  40. ON_BN_CLICKED(IDC_GET_NAME, OnGetName)
  41. ON_BN_CLICKED(IDC_POST_TASK, OnPostTask)
  42. ON_BN_CLICKED(IDC_PRE_TASK, OnPreTask)
  43. ON_BN_CLICKED(IDC_REGISTERABLE_FILES, OnRegisterableFiles)
  44. ON_BN_CLICKED(IDC_REQUIRED_FILES, OnRequiredFiles)
  45. ON_BN_CLICKED(IDC_STORE_RESULT, OnStoreResult)
  46. ON_BN_CLICKED(IDC_VIEW_RESULT, OnViewResult)
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CPlugIn message handlers
  51. void CPlugIn::OnConfigure()
  52. {
  53. HRESULT hr;
  54. CString msg;
  55. if ( m_pPlugIn )
  56. {
  57. hr = m_pPlugIn->ConfigureSettings(m_pVarSet);
  58. if ( SUCCEEDED(hr) )
  59. {
  60. msg = L"ConfigureSettings succeeded";
  61. }
  62. else
  63. {
  64. msg.Format(L"ConfigureSettings failed, hr=%lx",hr);
  65. }
  66. MessageBox(msg);
  67. }
  68. }
  69. void CPlugIn::OnCreateInstance()
  70. {
  71. UpdateData(TRUE);
  72. HRESULT hr = S_OK;
  73. CLSID clsid;
  74. WCHAR progid[200];
  75. CString msg;
  76. if ( m_pPlugIn )
  77. {
  78. m_pPlugIn->Release();
  79. m_pPlugIn = NULL;
  80. }
  81. wcscpy(progid,m_ProgID);
  82. hr = CLSIDFromProgID(progid,&clsid);
  83. if ( SUCCEEDED(hr) )
  84. {
  85. hr = CoCreateInstance(clsid,NULL,CLSCTX_ALL,IID_IMcsDomPlugIn,(void**)&m_pPlugIn);
  86. if ( SUCCEEDED(hr) )
  87. {
  88. msg = L"CreateInstance succeeded!";
  89. }
  90. else
  91. {
  92. msg.Format(L"CreateInstance failed, hr=%lx",hr);
  93. }
  94. }
  95. else
  96. {
  97. msg.Format(L"CLSIDFromProgID failed, hr=%lx",hr);
  98. }
  99. MessageBox(msg);
  100. }
  101. void CPlugIn::OnEditVarset()
  102. {
  103. CVarSetEditDlg vedit;
  104. vedit.SetVarSet(m_pVarSet);
  105. vedit.DoModal();
  106. m_pVarSet = vedit.GetVarSet();
  107. }
  108. void CPlugIn::OnGetDesc()
  109. {
  110. HRESULT hr;
  111. CString msg;
  112. BSTR val = NULL;
  113. if ( m_pPlugIn )
  114. {
  115. hr = m_pPlugIn->GetDescription(&val);
  116. if ( SUCCEEDED(hr) )
  117. {
  118. msg = val;
  119. }
  120. else
  121. {
  122. msg.Format(L"GetDescription failed, hr=%lx",hr);
  123. }
  124. MessageBox(msg);
  125. }
  126. }
  127. void CPlugIn::OnGetName()
  128. {
  129. HRESULT hr;
  130. CString msg;
  131. BSTR val = NULL;
  132. if ( m_pPlugIn )
  133. {
  134. hr = m_pPlugIn->GetName(&val);
  135. if ( SUCCEEDED(hr) )
  136. {
  137. msg = val;
  138. }
  139. else
  140. {
  141. msg.Format(L"GetDescription failed, hr=%lx",hr);
  142. }
  143. MessageBox(msg);
  144. }
  145. }
  146. void CPlugIn::OnPostTask()
  147. {
  148. HRESULT hr;
  149. CString msg;
  150. if ( m_pPlugIn )
  151. {
  152. hr = m_pPlugIn->PostMigrationTask(m_pVarSet);
  153. if ( SUCCEEDED(hr) )
  154. {
  155. msg = L"Postmigration task succeeded";
  156. }
  157. else
  158. {
  159. msg.Format(L"Postmigration task failed, hr=%lx",hr);
  160. }
  161. MessageBox(msg);
  162. }
  163. }
  164. void CPlugIn::OnPreTask()
  165. {
  166. HRESULT hr;
  167. CString msg;
  168. if ( m_pPlugIn )
  169. {
  170. hr = m_pPlugIn->PreMigrationTask(m_pVarSet);
  171. if ( SUCCEEDED(hr) )
  172. {
  173. msg = L"Premigration task succeeded";
  174. }
  175. else
  176. {
  177. msg.Format(L"Premigration task failed, hr=%lx",hr);
  178. }
  179. MessageBox(msg);
  180. }
  181. }
  182. void CPlugIn::OnRegisterableFiles()
  183. {
  184. // TODO: Add your control notification handler code here
  185. }
  186. void CPlugIn::OnRequiredFiles()
  187. {
  188. // TODO: Add your control notification handler code here
  189. }
  190. void CPlugIn::OnStoreResult()
  191. {
  192. HRESULT hr;
  193. CString msg;
  194. if ( m_pPlugIn )
  195. {
  196. hr = m_pPlugIn->StoreResults(m_pVarSet);
  197. if ( SUCCEEDED(hr) )
  198. {
  199. msg = L"StoreResult succeeded";
  200. }
  201. else
  202. {
  203. msg.Format(L"StoreResult failed, hr=%lx",hr);
  204. }
  205. MessageBox(msg);
  206. }
  207. }
  208. void CPlugIn::OnViewResult()
  209. {
  210. HRESULT hr;
  211. CString msg;
  212. BSTR text = NULL;
  213. if ( m_pPlugIn )
  214. {
  215. hr = m_pPlugIn->GetResultString(m_pVarSet,&text);
  216. if ( SUCCEEDED(hr) )
  217. {
  218. msg = text;
  219. }
  220. else
  221. {
  222. msg.Format(L"GetResultString failed, hr=%lx",hr);
  223. }
  224. MessageBox(msg);
  225. }
  226. }
  227. BOOL CPlugIn::OnInitDialog()
  228. {
  229. CPropertyPage::OnInitDialog();
  230. HRESULT hr = m_pVarSet.CreateInstance(CLSID_VarSet);
  231. if ( FAILED(hr) )
  232. {
  233. CString msg;
  234. msg.Format(L"Failed to create VarSet, CoCreateInstance returned %lx",hr);
  235. MessageBox(msg);
  236. }
  237. return TRUE; // return TRUE unless you set the focus to a control
  238. // EXCEPTION: OCX Property Pages should return FALSE
  239. }