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.

431 lines
9.2 KiB

  1. /*
  2. * w i z o m. c p p
  3. *
  4. * Purpose:
  5. *
  6. * History
  7. *
  8. * Copyright (C) Microsoft Corp. 1995, 1996.
  9. */
  10. #include <pch.hxx>
  11. #include "dllmain.h"
  12. #include <mshtml.h>
  13. #include <mshtmhst.h>
  14. #include <mimeole.h>
  15. #include "icwacct.h"
  16. #include "hotwiz.h"
  17. #include "hotwizom.h"
  18. #include "hotwizui.h"
  19. #define HASH_GROW_SIZE 32
  20. COEHotWizOm::COEHotWizOm()
  21. {
  22. m_pTypeInfo = NULL;
  23. m_cRef = 1;
  24. m_hwndDlg = NULL;
  25. m_pHash = NULL;
  26. m_pWizHost = NULL;
  27. DllAddRef();
  28. }
  29. COEHotWizOm::~COEHotWizOm()
  30. {
  31. clearProps();
  32. ReleaseObj(m_pTypeInfo);
  33. ReleaseObj(m_pWizHost);
  34. AssertSz(m_pHash == NULL, "clearPops catches this");
  35. DllRelease();
  36. }
  37. HRESULT COEHotWizOm::QueryInterface(REFIID riid, LPVOID *lplpObj)
  38. {
  39. if(!lplpObj)
  40. return E_INVALIDARG;
  41. *lplpObj = NULL;
  42. if (IsEqualIID(riid, IID_IUnknown))
  43. *lplpObj = (LPVOID)(IOEHotWizardOM *)this;
  44. else if (IsEqualIID(riid, IID_IDispatch))
  45. *lplpObj = (LPVOID)(IDispatch *)this;
  46. else if (IsEqualIID(riid, IID_IOEHotWizardOM))
  47. *lplpObj = (LPVOID)(IOEHotWizardOM *)this;
  48. else if (IsEqualIID(riid, IID_IElementBehavior))
  49. *lplpObj = (LPVOID)(IElementBehavior *)this;
  50. else
  51. return E_NOINTERFACE;
  52. AddRef();
  53. return NOERROR;
  54. }
  55. ULONG COEHotWizOm::AddRef()
  56. {
  57. return ++m_cRef;
  58. }
  59. ULONG COEHotWizOm::Release()
  60. {
  61. if (0 == --m_cRef)
  62. {
  63. delete this;
  64. return 0;
  65. }
  66. else
  67. return m_cRef;
  68. }
  69. HRESULT COEHotWizOm::Init(HWND hwndDlg, IHotWizardHost *pWizHost)
  70. {
  71. TCHAR szDll[MAX_PATH];
  72. LPWSTR pszW=NULL;
  73. HRESULT hr = E_FAIL;
  74. ITypeLib *pTypeLib=NULL;
  75. ReplaceInterface(m_pWizHost, pWizHost);
  76. // see who we are
  77. if (!GetModuleFileName(g_hInst, szDll, ARRAYSIZE(szDll)))
  78. {
  79. hr = TraceResult(E_FAIL);
  80. goto error;
  81. }
  82. pszW = PszToUnicode(CP_ACP, szDll);
  83. if (!pszW)
  84. {
  85. hr = TraceResult (E_OUTOFMEMORY);
  86. goto error;
  87. }
  88. // load the MSOE.DLL typelibrary
  89. hr = LoadTypeLib(pszW, &pTypeLib);
  90. if (FAILED(hr))
  91. {
  92. TraceResult(hr);
  93. goto error;
  94. }
  95. // load our type-info data
  96. hr = pTypeLib->GetTypeInfoOfGuid(IID_IOEHotWizardOM, &m_pTypeInfo);
  97. if (FAILED(hr))
  98. {
  99. TraceResult(hr);
  100. goto error;
  101. }
  102. m_hwndDlg = hwndDlg;
  103. error:
  104. SafeMemFree(pszW);
  105. ReleaseObj(pTypeLib);
  106. return hr;
  107. }
  108. // *** IDispatch ***
  109. HRESULT COEHotWizOm::GetTypeInfoCount(UINT *pctinfo)
  110. {
  111. *pctinfo = 1;
  112. return S_OK;
  113. }
  114. HRESULT COEHotWizOm::GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  115. {
  116. if (!m_pTypeInfo)
  117. return E_FAIL;
  118. if (!pptinfo)
  119. return E_INVALIDARG;
  120. if (itinfo)
  121. return DISP_E_BADINDEX;
  122. m_pTypeInfo->AddRef();
  123. *pptinfo = m_pTypeInfo;
  124. return S_OK;
  125. }
  126. HRESULT COEHotWizOm::GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
  127. {
  128. if (!m_pTypeInfo)
  129. return E_FAIL;
  130. return DispGetIDsOfNames(m_pTypeInfo, rgszNames, cNames, rgdispid);
  131. }
  132. HRESULT COEHotWizOm::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr)
  133. {
  134. if (!m_pTypeInfo)
  135. return E_FAIL;
  136. return DispInvoke(this, m_pTypeInfo, dispidMember, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr);
  137. }
  138. HRESULT COEHotWizOm::setPropSz(BSTR bstrProp, BSTR bstrVal)
  139. {
  140. LPSTR pszPropA=NULL;
  141. BSTR bstr=NULL;
  142. HRESULT hr=S_OK;
  143. // make sure we have a valid property
  144. if (bstrProp == NULL || *bstrProp == NULL)
  145. return E_INVALIDARG;
  146. // make sure we have a hash
  147. if (!m_pHash)
  148. {
  149. hr = CoCreateInstance(CLSID_IHashTable, NULL, CLSCTX_INPROC_SERVER, IID_IHashTable, (LPVOID*)&m_pHash);
  150. if (FAILED(hr))
  151. {
  152. TraceResult(hr);
  153. goto error;
  154. }
  155. hr = m_pHash->Init(HASH_GROW_SIZE, TRUE);
  156. if (FAILED(hr))
  157. {
  158. SafeRelease(m_pHash);
  159. TraceResult(hr);
  160. goto error;
  161. }
  162. }
  163. // convert property to ANSI to work with our hashtable
  164. pszPropA = PszToANSI(CP_ACP, bstrProp);
  165. if (!pszPropA)
  166. {
  167. hr = TraceResult(E_OUTOFMEMORY);
  168. goto error;
  169. }
  170. // see if this property already exists, if so we're going to replace it
  171. if (m_pHash->Find(pszPropA, TRUE, (LPVOID *)&bstr)==S_OK)
  172. {
  173. SysFreeString(bstr);
  174. bstr = NULL;
  175. }
  176. // bstrVal might be NULL if they just want to remove the prop
  177. if (bstrVal)
  178. {
  179. // dupe our own BSTR to hold onto
  180. bstr = SysAllocString(bstrVal);
  181. if (!bstr)
  182. {
  183. hr = TraceResult(E_OUTOFMEMORY);
  184. goto error;
  185. }
  186. // insert the new property
  187. hr = m_pHash->Insert(pszPropA, (LPVOID)bstr, NOFLAGS);
  188. if (FAILED(hr))
  189. {
  190. TraceResult(hr);
  191. goto error;
  192. }
  193. bstr = NULL; // release when destroying the hash
  194. }
  195. error:
  196. SafeMemFree(pszPropA);
  197. SysFreeString(bstr);
  198. return hr;
  199. }
  200. HRESULT COEHotWizOm::getPropSz(BSTR bstrProp, BSTR *pbstrVal)
  201. {
  202. LPSTR pszPropA=NULL;
  203. BSTR bstr;
  204. // make sure we have a valid property
  205. if (bstrProp == NULL || *bstrProp == NULL)
  206. return E_INVALIDARG;
  207. *pbstrVal = NULL;
  208. // if we have no hash then there are no props
  209. if (m_pHash)
  210. {
  211. // convert property to ANSI to work with our hashtable
  212. pszPropA = PszToANSI(CP_ACP, bstrProp);
  213. if (!pszPropA)
  214. return TraceResult(E_OUTOFMEMORY);
  215. // see if this property exists
  216. if (m_pHash->Find(pszPropA, FALSE, (LPVOID *)&bstr)==S_OK)
  217. *pbstrVal = SysAllocString(bstr);
  218. }
  219. // if we failed to find, try and return a NULL string, so that the script
  220. // engine doesn't barf with errors
  221. if (*pbstrVal == NULL)
  222. *pbstrVal = SysAllocString(L"");
  223. SafeMemFree(pszPropA);
  224. return *pbstrVal ? S_OK : E_OUTOFMEMORY;
  225. }
  226. HRESULT COEHotWizOm::clearProps()
  227. {
  228. ULONG cFound;
  229. BSTR bstr;
  230. LPVOID *rgpv;
  231. if (m_pHash)
  232. {
  233. m_pHash->Reset();
  234. // free all the strings
  235. while (SUCCEEDED(m_pHash->Next(HASH_GROW_SIZE, &rgpv, &cFound)))
  236. {
  237. while (cFound--)
  238. SysFreeString((BSTR)rgpv[cFound]);
  239. MemFree(rgpv);
  240. }
  241. m_pHash->Release();
  242. m_pHash = NULL;
  243. }
  244. return S_OK;
  245. }
  246. HRESULT COEHotWizOm::createAccount(BSTR bstrINS)
  247. {
  248. HRESULT hr;
  249. LPSTR pszInsA=NULL;
  250. LPSTR pszPathA=NULL;
  251. HANDLE hFile=NULL;
  252. ULONG cbWritten=0;
  253. TraceCall("COEHotWizOm::createAccount");
  254. // if we have a wizard host (possibly outlook in the future), delegate...
  255. if (m_pWizHost)
  256. return m_pWizHost->CreateAccountFromINS(bstrINS);
  257. // convert to ANSI
  258. pszInsA = PszToANSI(CP_ACP, bstrINS);
  259. if (!pszInsA)
  260. {
  261. hr = TraceResult(E_OUTOFMEMORY);
  262. goto error;
  263. }
  264. // create temp INS file for account manager
  265. hr = CreateTempFile("oeacct", ".ins", &pszPathA, &hFile);
  266. if (FAILED(hr))
  267. {
  268. TraceResult(hr);
  269. goto error;
  270. }
  271. // write the data to the file
  272. if (!WriteFile(hFile, pszInsA, lstrlen(pszInsA), &cbWritten, NULL))
  273. {
  274. hr = TraceResult(E_FAIL);
  275. goto error;
  276. }
  277. CloseHandle(hFile);
  278. hFile = NULL;
  279. // create the account from the temp file
  280. hr = CreateAccountsFromFile(pszPathA, 6);
  281. if (FAILED(hr))
  282. {
  283. TraceResult(hr);
  284. goto error;
  285. }
  286. error:
  287. if (hFile)
  288. CloseHandle(hFile);
  289. if (pszPathA)
  290. {
  291. DeleteFile(pszPathA);
  292. MemFree(pszPathA);
  293. }
  294. SafeMemFree(pszInsA);
  295. return hr;
  296. }
  297. HRESULT COEHotWizOm::close(VARIANT_BOOL fPrompt)
  298. {
  299. // send message to set the prompt flag
  300. SendMessage(m_hwndDlg, HWM_SETDIRTY, (fPrompt == VARIANT_TRUE), 0);
  301. // do the close
  302. SendMessage(m_hwndDlg, WM_CLOSE, 0, 0);
  303. return S_OK;
  304. }
  305. HRESULT COEHotWizOm::get_width(LONG *pl)
  306. {
  307. RECT rc;
  308. GetWindowRect(m_hwndDlg, &rc);
  309. *pl = rc.right - rc.left;
  310. return S_OK;
  311. }
  312. HRESULT COEHotWizOm::put_width(LONG l)
  313. {
  314. LONG lHeight=NULL;
  315. get_height(&lHeight);
  316. SetWindowPos(m_hwndDlg, 0, 0, 0, l, lHeight, SWP_NOMOVE|SWP_NOZORDER);
  317. return S_OK;
  318. }
  319. HRESULT COEHotWizOm::get_height(LONG *pl)
  320. {
  321. RECT rc;
  322. GetWindowRect(m_hwndDlg, &rc);
  323. *pl = rc.bottom - rc.top;
  324. return S_OK;
  325. }
  326. HRESULT COEHotWizOm::put_height(LONG l)
  327. {
  328. LONG lWidth=NULL;
  329. get_width(&lWidth);
  330. SetWindowPos(m_hwndDlg, 0, 0, 0, lWidth, l, SWP_NOMOVE|SWP_NOZORDER);
  331. return S_OK;
  332. }
  333. HRESULT COEHotWizOm::Init(IElementBehaviorSite *pBehaviorSite)
  334. {
  335. return S_OK;
  336. }
  337. HRESULT COEHotWizOm::Notify(LONG lEvent, VARIANT *pVar)
  338. {
  339. return S_OK;
  340. }
  341. HRESULT COEHotWizOm::Detach()
  342. {
  343. return E_NOTIMPL;
  344. }