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.

2382 lines
73 KiB

  1. // --------------------------------------------------------------------------------
  2. // INSTANCE.CPP
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #include "instance.h"
  7. #include "acctutil.h"
  8. #include "inetcfg.h"
  9. #include <storfldr.h>
  10. #include "zmouse.h"
  11. #include "migrate.h"
  12. #include <notify.h>
  13. #include "conman.h"
  14. #include "browser.h"
  15. #include "note.h"
  16. #include "reutil.h"
  17. #include "spengine.h"
  18. #include "addrobj.h"
  19. #include "statnery.h"
  20. #include "thumb.h"
  21. #include "imagelst.h"
  22. #include "url.h"
  23. #include "secutil.h"
  24. #include "shlwapip.h"
  25. #include "ruleutil.h"
  26. #include "newfldr.h"
  27. #include "envfact.h"
  28. #include "storutil.h"
  29. #include "multiusr.h"
  30. #include "newsstor.h"
  31. #include "storutil.h"
  32. #include <storsync.h>
  33. #include "cleanup.h"
  34. #include <grplist2.h>
  35. #include <newsutil.h>
  36. #include <sync.h>
  37. #include "menures.h"
  38. #include "shared.h"
  39. #include "acctcach.h"
  40. #include <inetreg.h>
  41. #include <mapiutil.h>
  42. #include "useragnt.h"
  43. #include "demand.h"
  44. #include <ieguidp.h>
  45. static DWORD g_dwAcctAdvise = 0xffffffff;
  46. DWORD g_dwHideMessenger = BL_DEFAULT;
  47. extern BOOL g_fMigrationDone;
  48. extern UINT GetCurColorRes(void);
  49. // --------------------------------------------------------------------------------
  50. // Forward Decls
  51. // --------------------------------------------------------------------------------
  52. void SimpleMAPICleanup(void); // smapi.cpp
  53. BOOL DemandLoadMSOEACCT(void);
  54. BOOL DemandLoadMSOERT2(void);
  55. BOOL DemandLoadINETCOMM(void);
  56. // --------------------------------------------------------------------------------
  57. // Init Common Control Flags
  58. // --------------------------------------------------------------------------------
  59. #define ICC_FLAGS (ICC_WIN95_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|ICC_COOL_CLASSES|ICC_NATIVEFNTCTL_CLASS)
  60. #ifdef DEBUG
  61. // --------------------------------------------------------------------------------
  62. // INITSOURCEINFO
  63. // --------------------------------------------------------------------------------
  64. typedef struct tagINITSOURCEINFO *LPINITSOURCEINFO;
  65. typedef struct tagINITSOURCEINFO {
  66. LPSTR pszSource;
  67. DWORD cRefs;
  68. LPINITSOURCEINFO pNext;
  69. } INITSOURCEINFO;
  70. static LPINITSOURCEINFO g_InitSourceHead=NULL;
  71. #endif // DEBUG
  72. // --------------------------------------------------------------------------------
  73. // MAKEERROR
  74. // --------------------------------------------------------------------------------
  75. #define MAKEERROR(_pInfo, _nPrefixIds, _nErrorIds, _nReasonIds, _pszExtra1) \
  76. { \
  77. (_pInfo)->nTitleIds = idsAthena; \
  78. (_pInfo)->nPrefixIds = _nPrefixIds; \
  79. (_pInfo)->nErrorIds = _nErrorIds; \
  80. (_pInfo)->nReasonIds = _nReasonIds; \
  81. (_pInfo)->nHelpIds = IDS_ERROR_START_HELP; \
  82. (_pInfo)->pszExtra1 = _pszExtra1; \
  83. (_pInfo)->ulLastError = GetLastError(); \
  84. }
  85. // --------------------------------------------------------------------------------
  86. // CoStartOutlookExpress
  87. // --------------------------------------------------------------------------------
  88. MSOEAPI CoStartOutlookExpress(DWORD dwFlags, LPCWSTR pwszCmdLine, INT nCmdShow)
  89. {
  90. // Tracing
  91. TraceCall("CoStartOutlookExpress");
  92. // Verify that we have an outlook express object
  93. Assert(g_pInstance);
  94. // E_OUTOFMEMORY
  95. if (NULL == g_pInstance)
  96. {
  97. // We should show an error, but the liklyhood of this happening is almost zero
  98. return TraceResult(E_OUTOFMEMORY);
  99. }
  100. // Run...
  101. return g_pInstance->Start(dwFlags, pwszCmdLine, nCmdShow);
  102. }
  103. // --------------------------------------------------------------------------------
  104. // CoCreateOutlookExpress
  105. // --------------------------------------------------------------------------------
  106. MSOEAPI CoCreateOutlookExpress(IUnknown *pUnkOuter, IUnknown **ppUnknown)
  107. {
  108. // Locals
  109. HRESULT hr=S_OK;
  110. // Trace
  111. TraceCall("CoCreateOutlookExpress");
  112. // Invalid Arg
  113. Assert(NULL != ppUnknown && NULL == pUnkOuter);
  114. // No global object yet ?
  115. AssertSz(g_pInstance, "This gets created in dllmain.cpp DllProcessAttach.");
  116. // Lets not crash
  117. if (NULL == g_pInstance)
  118. {
  119. hr = TraceResult(E_OUTOFMEMORY);
  120. goto exit;
  121. }
  122. // AddRef that badboy
  123. g_pInstance->AddRef();
  124. // Return the Innter
  125. *ppUnknown = SAFECAST(g_pInstance, IOutlookExpress *);
  126. exit:
  127. // Done
  128. return hr;
  129. }
  130. // --------------------------------------------------------------------------------
  131. // COutlookExpress::COutlookExpress
  132. // --------------------------------------------------------------------------------
  133. COutlookExpress::COutlookExpress(void)
  134. {
  135. // Trace
  136. TraceCall("COutlookExpress::COutlookExpress");
  137. // Init Members
  138. m_cRef = 1;
  139. m_hInstMutex = NULL;
  140. m_fPumpingMsgs = FALSE;
  141. m_cDllRef = 0;
  142. m_cDllLock = 0;
  143. m_cDllInit = 0;
  144. m_dwThreadId = GetCurrentThreadId();
  145. m_fSwitchingUsers = FALSE;
  146. m_szSwitchToUsername = NULL;
  147. m_hwndSplash = NULL;
  148. m_pSplash = NULL;
  149. m_fIncremented = FALSE;
  150. m_hTrayIcon = 0;
  151. // Init Thread Safety
  152. InitializeCriticalSection(&m_cs);
  153. }
  154. // --------------------------------------------------------------------------------
  155. // COutlookExpress::~COutlookExpress
  156. // --------------------------------------------------------------------------------
  157. COutlookExpress::~COutlookExpress(void)
  158. {
  159. // Trace
  160. TraceCall("COutlookExpress::~COutlookExpress");
  161. // We should have been un-inited
  162. Assert(0 == m_cDllInit && 0 == m_cDllRef && 0 == m_cDllLock);
  163. // Free the mutex
  164. SafeCloseHandle(m_hInstMutex);
  165. // Kill CritSect
  166. DeleteCriticalSection(&m_cs);
  167. if(m_hTrayIcon)
  168. {
  169. DestroyIcon(m_hTrayIcon);
  170. }
  171. // Free the switch to if necessary
  172. if (m_szSwitchToUsername)
  173. MemFree(m_szSwitchToUsername);
  174. }
  175. // --------------------------------------------------------------------------------
  176. // COutlookExpress::QueryInterface
  177. // --------------------------------------------------------------------------------
  178. STDMETHODIMP COutlookExpress::QueryInterface(REFIID riid, LPVOID *ppv)
  179. {
  180. // Locals
  181. HRESULT hr=S_OK;
  182. // Stack
  183. TraceCall("COutlookExpress::QueryInterface");
  184. // check params
  185. if (ppv == NULL)
  186. return TrapError(E_INVALIDARG);
  187. // Find IID
  188. if (IID_IUnknown == riid)
  189. *ppv = (IUnknown *)this;
  190. else if (IID_IOutlookExpress == riid)
  191. *ppv = (IOutlookExpress *)this;
  192. else
  193. {
  194. *ppv = NULL;
  195. hr = TraceResult(E_NOINTERFACE);
  196. goto exit;
  197. }
  198. // AddRef It
  199. ((IUnknown *)*ppv)->AddRef();
  200. exit:
  201. // Done
  202. return hr;
  203. }
  204. // --------------------------------------------------------------------------------
  205. // COutlookExpress::AddRef
  206. // --------------------------------------------------------------------------------
  207. STDMETHODIMP_(ULONG) COutlookExpress::AddRef(void)
  208. {
  209. TraceCall("COutlookExpress::AddRef");
  210. return InterlockedIncrement(&m_cRef);
  211. }
  212. // --------------------------------------------------------------------------------
  213. // COutlookExpress::Release
  214. // --------------------------------------------------------------------------------
  215. STDMETHODIMP_(ULONG) COutlookExpress::Release(void)
  216. {
  217. TraceCall("COutlookExpress::Release");
  218. LONG cRef = InterlockedDecrement(&m_cRef);
  219. if (0 == cRef)
  220. delete this;
  221. return (ULONG)cRef;
  222. }
  223. // --------------------------------------------------------------------------------
  224. // COutlookExpress::LockServer
  225. // --------------------------------------------------------------------------------
  226. HRESULT COutlookExpress::LockServer(BOOL fLock)
  227. {
  228. // Locals
  229. HRESULT hr=S_OK;
  230. // Stack
  231. TraceCall("COutlookExpress::LockServer");
  232. if (TRUE == fLock)
  233. {
  234. InterlockedIncrement(&m_cDllLock);
  235. }
  236. else
  237. {
  238. InterlockedDecrement(&m_cDllLock);
  239. }
  240. // Trace
  241. //TraceInfo(_MSG("Lock: %d, CoIncrementInit Count = %d, Reference Count = %d, Lock Count = %d", fLock, m_cDllInit, m_cDllRef, m_cDllLock));
  242. // Done
  243. return S_OK;
  244. }
  245. // --------------------------------------------------------------------------------
  246. // COutlookExpress::DllAddRef
  247. // --------------------------------------------------------------------------------
  248. HRESULT COutlookExpress::DllAddRef(void)
  249. {
  250. // Locals
  251. HRESULT hr=S_OK;
  252. // Stack
  253. TraceCall("COutlookExpress::DllAddRef");
  254. // Thread Safety
  255. if (InterlockedIncrement(&m_cDllRef) <= 0)
  256. {
  257. // refcount already below zero
  258. hr = S_FALSE;
  259. }
  260. // Trace
  261. //TraceInfo(_MSG("CoIncrementInit Count = %d, Reference Count = %d, Lock Count = %d", m_cDllInit, m_cDllRef, m_cDllLock));
  262. // Done
  263. return hr;
  264. }
  265. // --------------------------------------------------------------------------------
  266. // COutlookExpress::DllRelease
  267. // --------------------------------------------------------------------------------
  268. HRESULT COutlookExpress::DllRelease(void)
  269. {
  270. // Locals
  271. HRESULT hr=S_OK;
  272. // Stack
  273. TraceCall("COutlookExpress::DllRelease");
  274. // Thread Safety
  275. if (InterlockedDecrement(&m_cDllRef) < 0)
  276. {
  277. // refcount already below zero
  278. hr = S_FALSE;
  279. }
  280. // Trace
  281. //TraceInfo(_MSG("CoIncrementInit Count = %d, Reference Count = %d, Lock Count = %d", m_cDllInit, m_cDllRef, m_cDllLock));
  282. // Done
  283. return hr;
  284. }
  285. // --------------------------------------------------------------------------------
  286. // _CheckForJunkMail
  287. // --------------------------------------------------------------------------------
  288. void _CheckForJunkMail()
  289. {
  290. HKEY hkey;
  291. DWORD dw=0, cb;
  292. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szRegRoot, 0, KEY_QUERY_VALUE, &hkey))
  293. {
  294. cb = sizeof(dw);
  295. RegQueryValueEx(hkey, c_szRegJunkMailOn, 0, NULL, (LPBYTE)&dw, &cb);
  296. if (dw)
  297. g_dwAthenaMode |= MODE_JUNKMAIL;
  298. RegCloseKey(hkey);
  299. }
  300. }
  301. // --------------------------------------------------------------------------------
  302. // COutlookExpress::Start
  303. // --------------------------------------------------------------------------------
  304. STDMETHODIMP COutlookExpress::Start(DWORD dwFlags, LPCWSTR pwszCmdLine, INT nCmdShow)
  305. {
  306. // Locals
  307. HRESULT hr=S_OK;
  308. MSG msg;
  309. HWND hwndTimeout;
  310. HINITREF hInitRef=NULL;
  311. BOOL fErrorDisplayed=FALSE;
  312. LPWSTR pwszFree=NULL;
  313. LPWSTR pwszCmdLineDup = NULL;
  314. // Stack
  315. TraceCall("COutlookExpress::Start");
  316. // Make sure OLE is initialized on the thread
  317. OleInitialize(NULL);
  318. // Duplicate It
  319. IF_NULLEXIT(pwszCmdLineDup = PszDupW(pwszCmdLine));
  320. // pwszCmdLineDup will change, remember the allocated block
  321. pwszFree = pwszCmdLineDup;
  322. //We want to process the switches set the mode flags before we call CoIncrementInit
  323. _ProcessCommandLineFlags(&pwszCmdLineDup, dwFlags);
  324. // AddRef the Dll..
  325. hr = CoIncrementInit("COutlookExpress", dwFlags, pwszCmdLine, &hInitRef);
  326. if (FAILED(hr))
  327. {
  328. fErrorDisplayed = TRUE;
  329. TraceResult(hr);
  330. goto exit;
  331. }
  332. // Process the Command Line..
  333. IF_FAILEXIT(hr = ProcessCommandLine(nCmdShow, pwszCmdLineDup, &fErrorDisplayed));
  334. // No splash screen
  335. CloseSplashScreen();
  336. // Do a CoDecrementInit
  337. IF_FAILEXIT(hr = CoDecrementInit("COutlookExpress", &hInitRef));
  338. // No need for a Message Pump ?
  339. if (S_OK == DllCanUnloadNow() || FALSE == ISFLAGSET(dwFlags, MSOEAPI_START_MESSAGEPUMP))
  340. goto exit;
  341. // Start the message Pump
  342. EnterCriticalSection(&m_cs);
  343. // Do we already have a pump running ?
  344. if (TRUE == m_fPumpingMsgs)
  345. {
  346. LeaveCriticalSection(&m_cs);
  347. goto exit;
  348. }
  349. // We are going to pump
  350. m_fPumpingMsgs = TRUE;
  351. // Thread Safety
  352. LeaveCriticalSection(&m_cs);
  353. SetSwitchingUsers(FALSE);
  354. // Message Loop
  355. while (GetMessageWrapW(&msg, NULL, 0, 0) && ((m_cDllInit > 0) || !SwitchingUsers()))
  356. {
  357. CNote *pNote = GetTlsGlobalActiveNote();
  358. // Ask it to translate an accelerator
  359. if (g_pBrowser && g_pBrowser->TranslateAccelerator(&msg) == S_OK)
  360. continue;
  361. // Hand message off to the active note, but ignore init window msgs and ignore per-task msgs where hwnd=0
  362. if (msg.hwnd != g_hwndInit && IsWindow(msg.hwnd))
  363. {
  364. pNote = GetTlsGlobalActiveNote();
  365. // Give it to the active note if a note has focus, call it's XLateAccelerator...
  366. if (pNote && pNote->TranslateAccelerator(&msg) == S_OK)
  367. continue;
  368. }
  369. // Get Timeout Window for this thread
  370. hwndTimeout = (HWND)TlsGetValue(g_dwTlsTimeout);
  371. // Check for Is modeless timeout dialog window message
  372. if (hwndTimeout && TRUE == IsDialogMessageWrapW(hwndTimeout, &msg))
  373. continue;
  374. // If Still not processed
  375. TranslateMessage(&msg);
  376. DispatchMessageWrapW(&msg);
  377. }
  378. // We are no longer pumping messages
  379. EnterCriticalSection(&m_cs);
  380. m_fPumpingMsgs = FALSE;
  381. LeaveCriticalSection(&m_cs);
  382. if(SwitchingUsers())
  383. {
  384. HrCloseWabWindow();
  385. while (PeekMessageWrapW(&msg, NULL, 0, 0, PM_REMOVE))
  386. {
  387. TranslateMessage(&msg);
  388. DispatchMessageWrapW(&msg);
  389. }
  390. MU_ResetRegRoot();
  391. }
  392. exit:
  393. // Free command line copy
  394. SafeMemFree(pwszFree);
  395. // Do a CoDecrementInit
  396. CoDecrementInit("COutlookExpress", &hInitRef);
  397. // No splash screen
  398. CloseSplashScreen();
  399. // Is there an error ?
  400. if (FALSE == fErrorDisplayed && FAILED(hr) &&
  401. hrUserCancel != hr &&
  402. MAPI_E_USER_CANCEL != hr)
  403. {
  404. REPORTERRORINFO rError={0};
  405. MAKEERROR(&rError, 0, IDS_ERROR_UNKNOWN, 0, NULL);
  406. _ReportError(g_hLocRes, hr, 0, &rError);
  407. }
  408. //Bug #101360 - (erici) OleInitialize created a window, this destroys it.
  409. OleUninitialize();
  410. // Done
  411. return (SwitchingUsers() ? S_RESTART_OE : hr);
  412. }
  413. // --------------------------------------------------------------------------------
  414. // COutlookExpress::_ReportError
  415. // --------------------------------------------------------------------------------
  416. BOOL COutlookExpress::_ReportError(
  417. HINSTANCE hInstance, // Dll Instance
  418. HRESULT hrResult, // HRESULT of the error
  419. LONG lResult, // LRESULT from like a registry function
  420. LPREPORTERRORINFO pInfo) // Report Error Information
  421. {
  422. // Locals
  423. TCHAR szRes[255],
  424. szMessage[1024],
  425. szTitle[128];
  426. // INit
  427. *szMessage = '\0';
  428. // Is there a prefix
  429. if (pInfo->nPrefixIds)
  430. {
  431. // Load the string
  432. LoadString(hInstance, pInfo->nPrefixIds, szMessage, ARRAYSIZE(szMessage));
  433. }
  434. // Error ?
  435. if (pInfo->nErrorIds)
  436. {
  437. // Are there extras in this error string
  438. if (NULL != pInfo->pszExtra1)
  439. {
  440. // Locals
  441. TCHAR szTemp[255];
  442. // Load and format
  443. LoadString(hInstance, pInfo->nErrorIds, szTemp, ARRAYSIZE(szTemp));
  444. // Format the string
  445. wnsprintf(szRes, ARRAYSIZE(szRes), szTemp, pInfo->pszExtra1);
  446. }
  447. // Load the string
  448. else
  449. {
  450. // Load the error string
  451. LoadString(hInstance, pInfo->nErrorIds, szRes, ARRAYSIZE(szRes));
  452. }
  453. // Add to szMessage
  454. StrCatBuff(szMessage, g_szSpace, ARRAYSIZE(szMessage));
  455. StrCatBuff(szMessage, szRes, ARRAYSIZE(szMessage));
  456. }
  457. // Reason ?
  458. if (pInfo->nReasonIds)
  459. {
  460. // Load the string
  461. LoadString(hInstance, pInfo->nReasonIds, szRes, ARRAYSIZE(szRes));
  462. // Add to szMessage
  463. StrCatBuff(szMessage, g_szSpace, ARRAYSIZE(szMessage));
  464. StrCatBuff(szMessage, szRes, ARRAYSIZE(szMessage));
  465. }
  466. // Load the string
  467. LoadString(hInstance, pInfo->nHelpIds, szRes, ARRAYSIZE(szRes));
  468. // Add to szMessage
  469. StrCatBuff(szMessage, g_szSpace, ARRAYSIZE(szMessage));
  470. StrCatBuff(szMessage, szRes, ARRAYSIZE(szMessage));
  471. // Append Error Results
  472. if (lResult != 0 && E_FAIL == hrResult && pInfo->ulLastError)
  473. wnsprintf(szRes, ARRAYSIZE(szRes), "(%d, %d)", lResult, pInfo->ulLastError);
  474. else if (lResult != 0 && E_FAIL == hrResult && 0 == pInfo->ulLastError)
  475. wnsprintf(szRes, ARRAYSIZE(szRes), "(%d)", lResult);
  476. else if (pInfo->ulLastError)
  477. wnsprintf(szRes, ARRAYSIZE(szRes), "(0x%08X, %d)", hrResult, pInfo->ulLastError);
  478. else
  479. wnsprintf(szRes, ARRAYSIZE(szRes), "(0x%08X)", hrResult);
  480. // Add to szMessage
  481. StrCatBuff(szMessage, g_szSpace, ARRAYSIZE(szMessage));
  482. StrCatBuff(szMessage, szRes, ARRAYSIZE(szMessage));
  483. // Get the title
  484. LoadString(hInstance, pInfo->nTitleIds, szTitle, ARRAYSIZE(szTitle));
  485. // Show the error message
  486. MessageBox(NULL, szMessage, szTitle, MB_OK | MB_SETFOREGROUND | MB_ICONEXCLAMATION);
  487. // Done
  488. return TRUE;
  489. }
  490. #ifdef DEAD
  491. // --------------------------------------------------------------------------------
  492. // COutlookExpress::_ValidateDll
  493. // --------------------------------------------------------------------------------
  494. HRESULT COutlookExpress::_ValidateDll(LPCSTR pszDll, BOOL fDemandResult, HMODULE hModule,
  495. HRESULT hrLoadError, HRESULT hrVersionError, LPREPORTERRORINFO pError)
  496. {
  497. // Locals
  498. HRESULT hr=S_OK;
  499. PFNGETDLLMAJORVERSION pfnGetVersion;
  500. // Tracing
  501. TraceCall("COutlookExpress::_ValidateDll");
  502. // We must load these here in order to show errors and not crash - Load MSOERT2.DLL
  503. if (FALSE == fDemandResult)
  504. {
  505. MAKEERROR(pError, IDS_ERROR_PREFIX1, IDS_ERROR_MISSING_DLL, IDS_ERROR_REASON2, pszDll);
  506. hr = TraceResult(hrLoadError);
  507. goto exit;
  508. }
  509. // Try to get the current verion
  510. else
  511. {
  512. // Get Version Proc Address
  513. pfnGetVersion = (PFNGETDLLMAJORVERSION)GetProcAddress(hModule, STR_GETDLLMAJORVERSION);
  514. // Not the Correct Version
  515. if (NULL == pfnGetVersion || OEDLL_VERSION_CURRENT != (*pfnGetVersion)())
  516. {
  517. MAKEERROR(pError, IDS_ERROR_PREFIX1, IDS_ERROR_BADVER_DLL, IDS_ERROR_REASON2, pszDll);
  518. hr = TraceResult(hrVersionError);
  519. goto exit;
  520. }
  521. }
  522. exit:
  523. // Done
  524. return hr;
  525. }
  526. #endif // DEAD
  527. // --------------------------------------------------------------------------------
  528. // COutlookExpress::CoIncrementInitDebug
  529. // --------------------------------------------------------------------------------
  530. #ifdef DEBUG
  531. HRESULT COutlookExpress::CoIncrementInitDebug(LPCSTR pszSource, DWORD dwFlags,
  532. LPCWSTR pwszCmdLine, LPHINITREF phInitRef)
  533. {
  534. // Locals
  535. BOOL fFound=FALSE;
  536. LPINITSOURCEINFO pCurrent;
  537. // Trace
  538. TraceCall("COutlookExpress::CoIncrementInitDebug");
  539. // Invalid Args
  540. Assert(pszSource);
  541. // Thread Safety
  542. EnterCriticalSection(&m_cs);
  543. // Find Source
  544. for (pCurrent = g_InitSourceHead; pCurrent != NULL; pCurrent = pCurrent->pNext)
  545. {
  546. // Is this It ?
  547. if (lstrcmpi(pszSource, pCurrent->pszSource) == 0)
  548. {
  549. // Increment Reference Count
  550. pCurrent->cRefs++;
  551. // Found
  552. fFound = TRUE;
  553. // Done
  554. break;
  555. }
  556. }
  557. // Not Found, lets add one
  558. if (FALSE == fFound)
  559. {
  560. // Set pCurrent
  561. pCurrent = (LPINITSOURCEINFO)ZeroAllocate(sizeof(INITSOURCEINFO));
  562. Assert(pCurrent);
  563. // Set pszSource
  564. pCurrent->pszSource = PszDupA(pszSource);
  565. Assert(pCurrent->pszSource);
  566. // Set cRefs
  567. pCurrent->cRefs = 1;
  568. // Set Next
  569. pCurrent->pNext = g_InitSourceHead;
  570. // Set Head
  571. g_InitSourceHead = pCurrent;
  572. }
  573. // Thread Safety
  574. LeaveCriticalSection(&m_cs);
  575. // Call the Actual CoIncrementInit
  576. return(CoIncrementInitImpl(dwFlags, pwszCmdLine, phInitRef));
  577. }
  578. #endif // DEBUG
  579. // --------------------------------------------------------------------------------
  580. // COutlookExpress::CoIncrementInitImpl
  581. // --------------------------------------------------------------------------------
  582. HRESULT COutlookExpress::CoIncrementInitImpl(DWORD dwFlags, LPCWSTR pwszCmdLine, LPHINITREF phInitRef)
  583. {
  584. // Locals
  585. HRESULT hr=S_OK;
  586. DWORD dw;
  587. RECT rc={0};
  588. HWND hwndDesk;
  589. DWORD dwSize;
  590. INITCOMMONCONTROLSEX icex = { sizeof(icex), ICC_FLAGS };
  591. CImnAdviseAccount *pImnAdviseAccount=NULL;
  592. WNDCLASSW wcW;
  593. WNDCLASS wc;
  594. DWORD dwType, dwVal, cb;
  595. REPORTERRORINFO rError={0};
  596. LONG lResult=0;
  597. LPCWSTR pwszInitWndClass;
  598. BOOL fReleaseMutex=FALSE;
  599. BOOL fResult;
  600. CHAR szFolder[MAX_PATH];
  601. IF_DEBUG(DWORD dwTickStart=GetTickCount());
  602. // Tracing
  603. TraceCall("COutlookExpress::CoIncrementInitImpl");
  604. // Make sure OLE is initialized on the thread
  605. OleInitialize(NULL);
  606. // Thread Safety
  607. EnterCriticalSection(&m_cs);
  608. if (!SwitchingUsers() && !m_fIncremented)
  609. {
  610. SetQueryNetSessionCount(SESSION_INCREMENT_NODEFAULTBROWSERCHECK);
  611. m_fIncremented = TRUE;
  612. }
  613. // Increment Reference Count
  614. m_cDllInit++;
  615. // Set phInitRef
  616. if (phInitRef)
  617. *phInitRef = (HINITREF)((ULONG_PTR)m_cDllInit);
  618. // First-Time Reference
  619. if (m_cDllInit > 1)
  620. {
  621. LeaveCriticalSection(&m_cs);
  622. return S_OK;
  623. }
  624. // Leave CS (This code always runs on the same primary thread
  625. LeaveCriticalSection(&m_cs);
  626. if (FAILED(hr = MU_Init(ISFLAGSET(dwFlags, MSOEAPI_START_DEFAULTIDENTITY))))
  627. goto exit;
  628. // Is there more than one identity?
  629. g_fPluralIDs = 1 < MU_CountUsers();
  630. if (!MU_Login(GetDesktopWindow(), FALSE, NULL))
  631. {
  632. hr = hrUserCancel;
  633. goto exit;
  634. }
  635. // Create the instance mutex
  636. if (NULL == m_hInstMutex)
  637. {
  638. m_hInstMutex = CreateMutex(NULL, FALSE, STR_MSOEAPI_INSTANCEMUTEX);
  639. if (NULL == m_hInstMutex)
  640. {
  641. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_CREATE_INSTMUTEX, IDS_ERROR_REASON1, NULL);
  642. hr = TraceResult(E_OUTOFMEMORY);
  643. goto exit;
  644. }
  645. }
  646. // Release m_hInstMutex if it is currently owned by this thread, allow new instances to start.
  647. if (FALSE == ISFLAGSET(dwFlags, MSOEAPI_START_INSTANCEMUTEX))
  648. {
  649. // Lets grab the mutex ourselves
  650. WaitForSingleObject(m_hInstMutex, INFINITE);
  651. }
  652. // Release the mutex
  653. fReleaseMutex = TRUE;
  654. // Must init thread on primary instnance thread
  655. // If the thread id is zero, then we have uninitialized everything.
  656. // Which means we need to re-initialize everything
  657. if (0 == m_dwThreadId)
  658. {
  659. m_dwThreadId = GetCurrentThreadId();
  660. }
  661. AssertSz(m_dwThreadId == GetCurrentThreadId(), "We are not doing first CoIncrementInit on the thread in which g_pInstance was created on.");
  662. // Set g_dwAthenaMode
  663. _CheckForJunkMail();
  664. // Get MimeOle IMalloc Interface
  665. if (NULL == g_pMoleAlloc)
  666. {
  667. hr = MimeOleGetAllocator(&g_pMoleAlloc);
  668. if (FAILED(hr))
  669. {
  670. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_MIMEOLE_ALLOCATOR, IDS_ERROR_REASON1, NULL);
  671. TraceResult(hr);
  672. goto exit;
  673. }
  674. }
  675. // Set OE5 mode for INetcomm.
  676. MimeOleSetCompatMode(MIMEOLE_COMPAT_MLANG2);
  677. // Create the Database Session Object
  678. if (NULL == g_pDBSession)
  679. {
  680. hr = CoCreateInstance(CLSID_DatabaseSession, NULL, CLSCTX_INPROC_SERVER, IID_IDatabaseSession, (LPVOID *)&g_pDBSession);
  681. if (FAILED(hr))
  682. {
  683. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_OPEN_STORE, IDS_ERROR_REASON1, NULL);
  684. goto exit;
  685. }
  686. }
  687. // all migration and upgrade happens in here now.
  688. hr = MigrateAndUpgrade();
  689. if (FAILED(hr))
  690. {
  691. TraceResult(hr);
  692. goto exit;
  693. }
  694. // Only if there is a command line...
  695. if (pwszCmdLine)
  696. {
  697. LPSTR pszCmdLine = NULL;
  698. // If this returns S_OK, we have launched the first-run ICW exe and we need to go away.
  699. // this is consistent with IE and forces the user to deal with the ICW before partying with us.
  700. IF_NULLEXIT(pszCmdLine = PszToANSI(CP_ACP, pwszCmdLine));
  701. hr = NeedToRunICW(pszCmdLine);
  702. MemFree(pszCmdLine);
  703. if (hr == S_OK)
  704. {
  705. hr = hrUserCancel;
  706. goto exit;
  707. }
  708. // If that failed, time to show an error message
  709. else if (FAILED(hr))
  710. {
  711. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_FIRST_TIME_ICW, IDS_ERROR_REASON2, NULL);
  712. hr = TraceResult(hr);
  713. goto exit;
  714. }
  715. }
  716. // Create WNDCLASS for Primary Outlook Express hidden window
  717. if (ISFLAGSET(dwFlags, MSOEAPI_START_APPWINDOW))
  718. pwszInitWndClass = STRW_MSOEAPI_INSTANCECLASS;
  719. else
  720. pwszInitWndClass = STRW_MSOEAPI_IPSERVERCLASS;
  721. // Register the init window
  722. if (FALSE == GetClassInfoWrapW(g_hInst, pwszInitWndClass, &wcW))
  723. {
  724. ZeroMemory(&wcW, sizeof(wcW));
  725. wcW.lpfnWndProc = COutlookExpress::InitWndProc;
  726. wcW.hInstance = g_hInst;
  727. wcW.lpszClassName = pwszInitWndClass;
  728. if (FALSE == RegisterClassWrapW(&wcW))
  729. {
  730. // In this case, we are in an error condition so don't care if PszToANSI fails.
  731. LPSTR pszInitWndClass = PszToANSI(CP_ACP, pwszInitWndClass);
  732. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_REG_WNDCLASS, IDS_ERROR_REASON1, pszInitWndClass);
  733. MemFree(pszInitWndClass);
  734. hr = TraceResult(E_FAIL);
  735. goto exit;
  736. }
  737. }
  738. // Create the OutlookExpressHiddenWindow
  739. if (NULL == g_hwndInit)
  740. {
  741. g_hwndInit = CreateWindowExWrapW(WS_EX_TOPMOST, pwszInitWndClass, pwszInitWndClass,
  742. WS_POPUP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
  743. NULL, NULL, g_hInst, NULL);
  744. if (NULL == g_hwndInit)
  745. {
  746. // In this case, we are in an error condition so don't care if PszToANSI fails.
  747. LPSTR pszInitWndClass = PszToANSI(CP_ACP, pwszInitWndClass);
  748. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_REG_WNDCLASS, IDS_ERROR_REASON1, pszInitWndClass);
  749. MemFree(pszInitWndClass);
  750. hr = TraceResult(E_FAIL);
  751. goto exit;
  752. }
  753. }
  754. // CoIncrementInit Global Options Manager
  755. if (FALSE == InitGlobalOptions(NULL, NULL))
  756. {
  757. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_INIT_GOPTIONS, IDS_ERROR_REASON1, NULL);
  758. hr = TraceResult(E_FAIL);
  759. goto exit;
  760. }
  761. // Prompt the user for a store location, if we don't have one already
  762. hr = InitializeLocalStoreDirectory(NULL, FALSE);
  763. if (hrUserCancel == hr || FAILED(hr))
  764. {
  765. // If not user cancel, then must be another error
  766. if (hrUserCancel != hr)
  767. {
  768. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_INITSTORE_DIRECTORY, IDS_ERROR_REASON1, NULL);
  769. TraceResult(hr);
  770. }
  771. // Done
  772. goto exit;
  773. }
  774. // This needs to stay in since the Intl guys want a way to work around people who aren't going to upgrade to the latest ATOK11.
  775. if (ISFLAGSET(dwFlags, MSOEAPI_START_SHOWSPLASH) && 0 == DwGetOption(OPT_NO_SPLASH)
  776. && ((g_dwAthenaMode & MODE_OUTLOOKNEWS) != MODE_OUTLOOKNEWS))
  777. {
  778. // Create me a splash screen
  779. hr = CoCreateInstance(CLSID_IESplashScreen, NULL, CLSCTX_INPROC_SERVER, IID_ISplashScreen, (LPVOID *)&m_pSplash);
  780. // If that worked, heck, lets show it
  781. if (SUCCEEDED(hr))
  782. {
  783. HDC hdc = GetDC(NULL);
  784. m_pSplash->Show(g_hLocRes, ((GetDeviceCaps(hdc, BITSPIXEL) > 8) ? idbSplashHiRes : idbSplash256), idbSplashLoRes, &m_hwndSplash);
  785. ReleaseDC(NULL, hdc);
  786. }
  787. // Trace
  788. else
  789. TraceResultSz(hr, "CoCreateInstance(CLSID_IESplashScreen, ...) failed, but who cares.");
  790. // Everything is good
  791. hr = S_OK;
  792. }
  793. cb = sizeof(dw);
  794. if (ERROR_SUCCESS != SHGetValue(HKEY_LOCAL_MACHINE, c_szRegFlat, c_szHideMessenger, &dwType, (LPBYTE)&dw, &cb))
  795. dw = 0xffffffff;
  796. cb = sizeof(dwVal);
  797. if (ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, c_szRegFlat, c_szHideMessenger, &dwType, (LPBYTE)&dwVal, &cb))
  798. dwVal = 0xffffffff;
  799. if (dw != 0xffffffff && dwVal != 0xffffffff)
  800. g_dwHideMessenger = max(dw, dwVal);
  801. else if (dw != 0xffffffff)
  802. g_dwHideMessenger = dw;
  803. else if (dwVal != 0xffffffff)
  804. g_dwHideMessenger = dwVal;
  805. else
  806. g_dwHideMessenger = BL_DEFAULT;
  807. // IntelliMouse support
  808. g_msgMSWheel = RegisterWindowMessage(TEXT(MSH_MOUSEWHEEL));
  809. AssertSz(g_msgMSWheel, "RegisterWindowMessage for the IntelliMouse failed, we can still continue.");
  810. // Create WNDCLASS for ThumbNail
  811. if (FALSE == GetClassInfo(g_hLocRes, WC_THUMBNAIL, &wc))
  812. {
  813. ZeroMemory(&wc, sizeof(wc));
  814. wc.lpfnWndProc = ThumbNailWndProc;
  815. wc.hInstance = g_hLocRes;
  816. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  817. wc.lpszClassName = WC_THUMBNAIL;
  818. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  819. if (FALSE == RegisterClass(&wc))
  820. {
  821. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_REG_WNDCLASS, IDS_ERROR_REASON1, WC_THUMBNAIL);
  822. hr = TraceResult(E_FAIL);
  823. goto exit;
  824. }
  825. }
  826. // Get the desktop Window
  827. hwndDesk = GetDesktopWindow();
  828. AssertSz(hwndDesk, "GetDesktopWindow returned NULL. We should be ok, I hope.");
  829. if (hwndDesk)
  830. {
  831. // Get the size of the desktop window
  832. GetWindowRect(hwndDesk, &rc);
  833. // sungr: following is a hack to avoid the fullscreen app detection hack that user does to modify the top-most state of the tray.
  834. rc.left += 20;
  835. rc.top += 20;
  836. rc.bottom -= 20;
  837. rc.right -= 20;
  838. }
  839. // Test to see if we should move the store
  840. cb = ARRAYSIZE(szFolder);
  841. if (ERROR_SUCCESS == AthUserGetValue(NULL, c_szNewStoreDir, &dwType, (LPBYTE)szFolder, &cb))
  842. {
  843. DWORD dwMoveStore = 0;
  844. DWORD cb = sizeof(dwMoveStore);
  845. AthUserGetValue(NULL, c_szMoveStore, NULL, (LPBYTE)&dwMoveStore, &cb);
  846. if (SUCCEEDED(RelocateStoreDirectory(g_hwndInit, szFolder, (dwMoveStore != 0))))
  847. {
  848. AthUserDeleteValue(NULL, c_szNewStoreDir);
  849. AthUserDeleteValue(NULL, c_szMoveStore);
  850. }
  851. }
  852. // CoIncrementInit Common Controls Library
  853. InitCommonControlsEx(&icex);
  854. // Create account manger
  855. if (NULL == g_pAcctMan)
  856. {
  857. hr = AcctUtil_CreateAccountManagerForIdentity(PGUIDCurrentOrDefault(), &g_pAcctMan);
  858. if (FAILED(hr))
  859. {
  860. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_CREATE_ACCTMAN, IDS_ERROR_REASON1, NULL);
  861. TraceResult(hr);
  862. goto exit;
  863. }
  864. pImnAdviseAccount = new CImnAdviseAccount();
  865. if (NULL == pImnAdviseAccount)
  866. {
  867. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_ALLOC_ACCTADVISE, IDS_ERROR_REASON1, NULL);
  868. hr = TraceResult(E_OUTOFMEMORY);
  869. goto exit;
  870. }
  871. hr = pImnAdviseAccount->Initialize();
  872. if (FAILED(hr))
  873. {
  874. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_INIT_ACCTADVISE, IDS_ERROR_REASON1, NULL);
  875. TraceResult(hr);
  876. goto exit;
  877. }
  878. // Register Advise sink
  879. Assert(g_dwAcctAdvise == 0xffffffff);
  880. hr = g_pAcctMan->Advise(pImnAdviseAccount, &g_dwAcctAdvise);
  881. if (FAILED(hr))
  882. {
  883. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_ADVISE_ACCTMAN, IDS_ERROR_REASON1, NULL);
  884. TraceResult(hr);
  885. goto exit;
  886. }
  887. }
  888. // Create the rules manager
  889. if (NULL == g_pRulesMan)
  890. {
  891. hr = HrCreateRulesManager(NULL, (IUnknown **)&g_pRulesMan);
  892. if (FAILED(hr))
  893. {
  894. MAKEERROR(&rError, IDS_ERROR_PREFIX1, idsErrorCreateRulesMan, IDS_ERROR_REASON1, NULL);
  895. TraceResult(hr);
  896. goto exit;
  897. }
  898. // CoIncrementInit the account manager
  899. hr = g_pRulesMan->Initialize(0);
  900. if (FAILED(hr))
  901. {
  902. MAKEERROR(&rError, IDS_ERROR_PREFIX1, idsErrorInitRulesMan, IDS_ERROR_REASON1, NULL);
  903. TraceResult(hr);
  904. goto exit;
  905. }
  906. }
  907. // Create the global connection manager
  908. if (NULL == g_pConMan)
  909. {
  910. g_pConMan = new CConnectionManager();
  911. if (NULL == g_pConMan)
  912. {
  913. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_ALLOC_CONMAN, IDS_ERROR_REASON1, NULL);
  914. hr = TraceResult(E_OUTOFMEMORY);
  915. goto exit;
  916. }
  917. // CoIncrementInit the Connection Manager
  918. hr = g_pConMan->HrInit(g_pAcctMan);
  919. if (FAILED(hr))
  920. {
  921. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_INIT_CONMAN, IDS_ERROR_REASON1, NULL);
  922. TraceResult(hr);
  923. goto exit;
  924. }
  925. }
  926. // Initialize the HTTP user agent
  927. InitOEUserAgent(TRUE);
  928. // Create the Spooler Object
  929. if (NULL == g_pSpooler)
  930. {
  931. hr = CreateThreadedSpooler(NULL, &g_pSpooler, TRUE);
  932. if (FAILED(hr))
  933. {
  934. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_CREATE_SPOOLER, IDS_ERROR_REASON1, NULL);
  935. hr = TraceResult(hr);
  936. goto exit;
  937. }
  938. }
  939. // Create the Font Cache Object
  940. if (NULL == g_lpIFontCache)
  941. {
  942. hr = CoCreateInstance(CLSID_IFontCache, NULL, CLSCTX_INPROC_SERVER, IID_IFontCache, (LPVOID *)&g_lpIFontCache);
  943. if (FAILED(hr))
  944. {
  945. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_CREATE_FONTCACHE, IDS_ERROR_REASON1, NULL);
  946. hr = TraceResult(E_OUTOFMEMORY);
  947. goto exit;
  948. }
  949. hr = g_lpIFontCache->Init(MU_GetCurrentUserHKey(), c_szRegInternational, 0);
  950. Assert(SUCCEEDED(hr));
  951. }
  952. // Create the Global Store Object
  953. hr = InitializeStore(dwFlags);
  954. if (FAILED(hr))
  955. {
  956. MAKEERROR(&rError, IDS_ERROR_PREFIX1, IDS_ERROR_OPEN_STORE, IDS_ERROR_REASON1, NULL);
  957. goto exit;
  958. }
  959. DoNewsgroupSubscribe();
  960. if (NULL == g_pSync)
  961. {
  962. g_pSync = new COfflineSync;
  963. if (NULL == g_pSync)
  964. {
  965. hr = TraceResult(E_OUTOFMEMORY);
  966. goto exit;
  967. }
  968. hr = g_pSync->Initialize();
  969. if (FAILED(hr))
  970. {
  971. TraceResult(hr);
  972. goto exit;
  973. }
  974. }
  975. // Start Background Compaction in XX Seconds
  976. if (DwGetOption(OPT_BACKGROUNDCOMPACT))
  977. SideAssert(SUCCEEDED(StartBackgroundStoreCleanup(30)));
  978. // CoIncrementInit Drag Drop Information
  979. if (0 == CF_FILEDESCRIPTORA)
  980. {
  981. CF_FILEDESCRIPTORA = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORA);
  982. CF_FILEDESCRIPTORW = RegisterClipboardFormat(CFSTR_FILEDESCRIPTORW);
  983. CF_FILECONTENTS = RegisterClipboardFormat(CFSTR_FILECONTENTS);
  984. CF_HTML = RegisterClipboardFormat(CFSTR_HTML);
  985. CF_INETMSG = RegisterClipboardFormat(CFSTR_INETMSG);
  986. CF_OEFOLDER = RegisterClipboardFormat(CFSTR_OEFOLDER);
  987. CF_SHELLURL = RegisterClipboardFormat(CFSTR_SHELLURL);
  988. CF_OEMESSAGES = RegisterClipboardFormat(CFSTR_OEMESSAGES);
  989. CF_OESHORTCUT = RegisterClipboardFormat(CFSTR_OESHORTCUT);
  990. }
  991. // Get the current default codepage
  992. cb = sizeof(dwVal);
  993. if (ERROR_SUCCESS == SHGetValue(MU_GetCurrentUserHKey(), c_szRegInternational, REGSTR_VAL_DEFAULT_CODEPAGE, &dwType, &dwVal, &cb))
  994. g_uiCodePage = (UINT)dwVal;
  995. // CoIncrementInit the Wab on first run
  996. cb = sizeof(dwVal);
  997. if (ERROR_SUCCESS != SHGetValue(HKEY_CURRENT_USER, c_szNewWABKey, c_szFirstRunValue, &dwType, &dwVal, &cb))
  998. HrInitWab(TRUE);
  999. //This call could fail if the registry gets trashed, but do we want an error box?
  1000. //According to takos, no...we do not.
  1001. HGetDefaultCharset(NULL);
  1002. exit:
  1003. // Is there an error ?
  1004. if (hrUserCancel != hr && ISFLAGSET(dwFlags, MSOEAPI_START_SHOWERRORS) && (FAILED(hr) || ERROR_SUCCESS != lResult))
  1005. {
  1006. // If ulError is zero, lets set it to a default
  1007. if (0 == rError.nErrorIds)
  1008. MAKEERROR(&rError, 0, IDS_ERROR_UNKNOWN, 0, NULL);
  1009. // Report the Error
  1010. _ReportError(g_hLocRes, hr, lResult, &rError);
  1011. }
  1012. // Release the mutex and signal the caller initialization is done
  1013. if (fReleaseMutex)
  1014. SideAssert(FALSE != ReleaseMutex(m_hInstMutex));
  1015. // Trace
  1016. //TraceInfo(_MSG("CoIncrementInit Count = %d, Reference Count = %d, Lock Count = %d", m_cDllInit, m_cDllRef, m_cDllLock));
  1017. // Cleanup
  1018. SafeRelease(pImnAdviseAccount);
  1019. // If we failed, decrement the reference count
  1020. if (FAILED(hr))
  1021. {
  1022. CloseSplashScreen();
  1023. CoDecrementInit("COutlookExpress", phInitRef);
  1024. }
  1025. else
  1026. Assert(g_pAcctMan);
  1027. // Time To Crank
  1028. TraceInfo(_MSG("Startup Time: %d", GetTickCount() - dwTickStart));
  1029. // Done
  1030. return hr;
  1031. }
  1032. // --------------------------------------------------------------------------------
  1033. // COutlookExpress::CloseSplashScreen
  1034. // --------------------------------------------------------------------------------
  1035. void COutlookExpress::CloseSplashScreen(void)
  1036. {
  1037. // Kill the splash screen
  1038. if (m_pSplash)
  1039. {
  1040. m_pSplash->Dismiss();
  1041. m_pSplash->Release();
  1042. m_pSplash = NULL;
  1043. // HACKHACKHACK
  1044. // This is needed because the splash screen might still be around after we
  1045. // free up OLE.
  1046. if (FALSE != IsWindow(m_hwndSplash))
  1047. {
  1048. SendMessage(m_hwndSplash, WM_CLOSE, 0, 0);
  1049. }
  1050. }
  1051. }
  1052. // --------------------------------------------------------------------------------
  1053. // COutlookExpress::CoDecrementInitDebug
  1054. // --------------------------------------------------------------------------------
  1055. #ifdef DEBUG
  1056. HRESULT COutlookExpress::CoDecrementInitDebug(LPCSTR pszSource, LPHINITREF phInitRef)
  1057. {
  1058. // Locals
  1059. BOOL fFound=FALSE;
  1060. LPINITSOURCEINFO pCurrent;
  1061. LPINITSOURCEINFO pPrevious=NULL;
  1062. // Trace
  1063. TraceCall("COutlookExpress::CoDecrementInitDebug");
  1064. // Invalid Args
  1065. Assert(pszSource);
  1066. // Do I need to do this
  1067. if (NULL == phInitRef || NULL != *phInitRef)
  1068. {
  1069. // Thread Safety
  1070. EnterCriticalSection(&m_cs);
  1071. // Find Source
  1072. for (pCurrent = g_InitSourceHead; pCurrent != NULL; pCurrent = pCurrent->pNext)
  1073. {
  1074. // Is this It ?
  1075. if (lstrcmpi(pszSource, pCurrent->pszSource) == 0)
  1076. {
  1077. // Increment Reference Count
  1078. pCurrent->cRefs--;
  1079. // Found
  1080. fFound = TRUE;
  1081. // No More Reference Counts ?
  1082. if (0 == pCurrent->cRefs)
  1083. {
  1084. // Previous ?
  1085. if (pPrevious)
  1086. pPrevious->pNext = pCurrent->pNext;
  1087. else
  1088. g_InitSourceHead = pCurrent->pNext;
  1089. // Free pszSource
  1090. g_pMalloc->Free(pCurrent->pszSource);
  1091. // Free pCurrent
  1092. g_pMalloc->Free(pCurrent);
  1093. }
  1094. // Done
  1095. break;
  1096. }
  1097. // Set Previous
  1098. pPrevious = pCurrent;
  1099. }
  1100. // Not Found, lets add one
  1101. Assert(fFound);
  1102. // TraceInfoTag
  1103. TraceInfoTag(TAG_INITTRACE, "********** CoDecrementInit **********");
  1104. // Find Source
  1105. for (pCurrent = g_InitSourceHead; pCurrent != NULL; pCurrent = pCurrent->pNext)
  1106. {
  1107. // TraceInfoTag
  1108. TraceInfoTag(TAG_INITTRACE, _MSG("Source: %s, Refs: %d", pCurrent->pszSource, pCurrent->cRefs));
  1109. }
  1110. // Thread Safety
  1111. LeaveCriticalSection(&m_cs);
  1112. }
  1113. // Call Actual
  1114. return(CoDecrementInitImpl(phInitRef));
  1115. }
  1116. #endif // DEBUG
  1117. // --------------------------------------------------------------------------------
  1118. // COutlookExpress::CoDecrementInitImpl
  1119. // --------------------------------------------------------------------------------
  1120. HRESULT COutlookExpress::CoDecrementInitImpl(LPHINITREF phInitRef)
  1121. {
  1122. // Locals
  1123. HRESULT hr=S_OK;
  1124. // Stack
  1125. TraceCall("COutlookExpress::CoDecrementInitImpl");
  1126. // If *phInitRef = NULL, then we should no do the CoDecrementInit
  1127. if (phInitRef && NULL == *phInitRef)
  1128. {
  1129. hr = S_OK;
  1130. goto exit;
  1131. }
  1132. // We must de-init on the same thread that we were created on...
  1133. if (m_dwThreadId != GetCurrentThreadId() && g_hwndInit && IsWindow(g_hwndInit))
  1134. {
  1135. // Thunk the shutdown to the correct thread
  1136. hr = (HRESULT) SendMessage(g_hwndInit, ITM_SHUTDOWNTHREAD, 0, (LPARAM)phInitRef);
  1137. }
  1138. else
  1139. {
  1140. // Forward everything off to the main function
  1141. hr = _CoDecrementInitMain(phInitRef);
  1142. }
  1143. if (!SwitchingUsers() && m_fIncremented && (m_cDllInit == 0))
  1144. {
  1145. SetQueryNetSessionCount(SESSION_DECREMENT);
  1146. m_fIncremented = FALSE;
  1147. }
  1148. // Uninitialize Ole
  1149. OleUninitialize();
  1150. exit:
  1151. return hr;
  1152. }
  1153. // --------------------------------------------------------------------------------
  1154. // COutlookExpress::_CoDecrementInitMain
  1155. //
  1156. // NOTE: We assume that we already have the critical section before this call
  1157. // --------------------------------------------------------------------------------
  1158. HRESULT COutlookExpress::_CoDecrementInitMain(LPHINITREF phInitRef)
  1159. {
  1160. // Stack
  1161. TraceCall("COutlookExpress::_CoDecrementInitMain");
  1162. // If *phInitRef = NULL, then we should no do the CoDecrementInit
  1163. if (phInitRef && NULL == *phInitRef)
  1164. return S_OK;
  1165. // Thread Safety
  1166. EnterCriticalSection(&m_cs);
  1167. // This should never happen. It could only happen if g_hwndInit was NULL.
  1168. AssertSz(m_dwThreadId == GetCurrentThreadId(), "We are not doing the last CoDecrementInit on the thread in which g_pInstance was created on.");
  1169. // Release
  1170. Assert(m_cDllInit);
  1171. m_cDllInit--;
  1172. // Not hit zero yet ?
  1173. if (m_cDllInit > 0)
  1174. {
  1175. LeaveCriticalSection(&m_cs);
  1176. goto exit;
  1177. }
  1178. // Leave Critical Section
  1179. LeaveCriticalSection(&m_cs);
  1180. // Validate
  1181. Assert(NULL == g_InitSourceHead);
  1182. // Take ownership of the mutex to block people from creating new insts while shutting down
  1183. WaitForSingleObject(m_hInstMutex, INFINITE);
  1184. // Cleanup the Trident data for this thread
  1185. //g_hLibMAPI
  1186. if (g_hlibMAPI)
  1187. {
  1188. FreeLibrary(g_hlibMAPI);
  1189. g_hlibMAPI = 0;
  1190. }
  1191. // Make sure we remove our new mail notification from the tray
  1192. UpdateTrayIcon(TRAYICONACTION_REMOVE);
  1193. // Close Background Compaction
  1194. SideAssert(SUCCEEDED(CloseBackgroundStoreCleanup()));
  1195. // Kill the Spooler
  1196. if (g_pSpooler)
  1197. {
  1198. CloseThreadedSpooler(g_pSpooler);
  1199. g_pSpooler = NULL;
  1200. }
  1201. // de-init the http user agent
  1202. InitOEUserAgent(FALSE);
  1203. // A bunch of de-init things
  1204. FInitRichEdit(FALSE);
  1205. Note_Init(FALSE);
  1206. Envelope_FreeGlobals();
  1207. // Make sure next identity can migrate
  1208. g_fMigrationDone = FALSE;
  1209. // De-initialize Multilanguage menu
  1210. DeinitMultiLanguage();
  1211. // Deinit Stationery
  1212. if (g_pStationery)
  1213. {
  1214. // Save the current list
  1215. g_pStationery->SaveStationeryList();
  1216. // Release the object
  1217. SideAssert(0 == g_pStationery->Release());
  1218. // Lets not free it again
  1219. g_pStationery = NULL;
  1220. }
  1221. // Release the font cache
  1222. SafeRelease(g_lpIFontCache);
  1223. // Simple MAPI Cleanup
  1224. #ifndef WIN16
  1225. SimpleMAPICleanup();
  1226. #endif
  1227. // Kill the Wab
  1228. HrInitWab(FALSE);
  1229. /*
  1230. We shouldn't have to do this anymore. This should be handled by IE when we decrement the session count
  1231. #ifndef WIN16 // No RAS support in Win16
  1232. if (g_pConMan && g_pConMan->IsRasLoaded() && g_pConMan->IsConnected())
  1233. g_pConMan->Disconnect(g_hwndInit, TRUE, FALSE, TRUE);
  1234. #endif
  1235. */
  1236. // Image Lists
  1237. FreeImageLists();
  1238. // Kill the account manager
  1239. if (g_pAcctMan)
  1240. {
  1241. CleanupTempNewsAccounts();
  1242. if (g_dwAcctAdvise != 0xffffffff)
  1243. {
  1244. g_pAcctMan->Unadvise(g_dwAcctAdvise);
  1245. g_dwAcctAdvise = 0xffffffff;
  1246. }
  1247. g_pAcctMan->Release();
  1248. g_pAcctMan = NULL;
  1249. }
  1250. Assert(g_dwAcctAdvise == 0xffffffff);
  1251. SafeRelease(g_pSync);
  1252. #ifndef WIN16 // No RAS support in Win16
  1253. SafeRelease(g_pConMan);
  1254. #endif
  1255. // Kill the rules manager
  1256. SafeRelease(g_pRulesMan);
  1257. // Take down the password cache
  1258. DestroyPasswordList();
  1259. // free the account data cache
  1260. FreeAccountPropCache();
  1261. // MIMEOLE Allocator
  1262. SafeRelease(g_pMoleAlloc);
  1263. // Kill g_hwndInit
  1264. if (g_hwndInit)
  1265. {
  1266. SendMessage(g_hwndInit, WM_CLOSE, (WPARAM) 0, (LPARAM) 0);
  1267. g_hwndInit = NULL;
  1268. }
  1269. // Kill the store
  1270. SafeRelease(g_pStore);
  1271. SafeRelease(g_pLocalStore);
  1272. SafeRelease(g_pDBSession);
  1273. // Global options
  1274. DeInitGlobalOptions();
  1275. // Run register window classes
  1276. UnregisterClass(c_szFolderWndClass, g_hInst);
  1277. UnregisterClassWrapW(STRW_MSOEAPI_INSTANCECLASS, g_hInst);
  1278. UnregisterClassWrapW(STRW_MSOEAPI_IPSERVERCLASS, g_hInst);
  1279. UnregisterClass(c_szFolderViewClass, g_hInst);
  1280. UnregisterClass(c_szBlockingPaintsClass, g_hInst);
  1281. UnregisterClass(WC_THUMBNAIL, g_hInst);
  1282. // Break Message Loop in RunShell if we are pumping messages and not switching identities
  1283. if (m_fPumpingMsgs && !m_fSwitchingUsers)
  1284. PostQuitMessage(0);
  1285. else
  1286. PostMessage(NULL, ITM_IDENTITYMSG, 0, 0);
  1287. MU_Shutdown();
  1288. // Relase the startup/shutdown mutex
  1289. ReleaseMutex(m_hInstMutex);
  1290. // Make sure mark this initialization thread as dead
  1291. m_dwThreadId = 0;
  1292. exit:
  1293. // We must have decremented succesfully
  1294. if (phInitRef)
  1295. *phInitRef = NULL;
  1296. // Trace
  1297. //TraceInfo(_MSG("_CoDecrementInitMain Count = %d, Reference Count = %d, Lock Count = %d", m_cDllInit, m_cDllRef, m_cDllLock));
  1298. // Done
  1299. return S_OK;
  1300. }
  1301. // --------------------------------------------------------------------------------
  1302. // COutlookExpress::ActivateWindow
  1303. // --------------------------------------------------------------------------------
  1304. HRESULT COutlookExpress::ActivateWindow(HWND hwnd)
  1305. {
  1306. // If hwnd is minimized, retstore it
  1307. if (IsIconic(hwnd))
  1308. ShowWindow(hwnd, SW_RESTORE);
  1309. // If the window is not enabled, set it to the foreground
  1310. if (IsWindowEnabled(hwnd))
  1311. SetForegroundWindow(hwnd);
  1312. // Otherwise, I have no clue what this does
  1313. else
  1314. {
  1315. SetForegroundWindow(GetLastActivePopup(hwnd));
  1316. MessageBeep(MB_OK);
  1317. return S_FALSE;
  1318. }
  1319. // Done
  1320. return S_OK;
  1321. }
  1322. // --------------------------------------------------------------------------------
  1323. // COutlookExpress::SetSwitchingUsers
  1324. // --------------------------------------------------------------------------------
  1325. HRESULT COutlookExpress::SetSwitchingUsers(BOOL bSwitching)
  1326. {
  1327. // Set the mode to whatever was passed in
  1328. m_fSwitchingUsers = bSwitching;
  1329. // if we are switching, we need to enter the mutex so that
  1330. // another process won't get started
  1331. if (bSwitching)
  1332. WaitForSingleObject(m_hInstMutex, INFINITE);
  1333. return S_OK;
  1334. }
  1335. // --------------------------------------------------------------------------------
  1336. // COutlookExpress::SetSwitchingUsers
  1337. // --------------------------------------------------------------------------------
  1338. void COutlookExpress::SetSwitchToUser(TCHAR *lpszUserName)
  1339. {
  1340. ULONG cchUserName = 0;
  1341. if (m_szSwitchToUsername)
  1342. {
  1343. MemFree(m_szSwitchToUsername);
  1344. m_szSwitchToUsername = NULL;
  1345. }
  1346. cchUserName = lstrlen(lpszUserName) + 1;
  1347. MemAlloc((void **)&m_szSwitchToUsername, cchUserName);
  1348. if (m_szSwitchToUsername)
  1349. {
  1350. StrCpyN(m_szSwitchToUsername, lpszUserName, cchUserName);
  1351. }
  1352. }
  1353. // --------------------------------------------------------------------------------
  1354. // COutlookExpress::BrowseToObject
  1355. // --------------------------------------------------------------------------------
  1356. HRESULT COutlookExpress::BrowseToObject(UINT nCmdShow, FOLDERID idFolder)
  1357. {
  1358. // Locals
  1359. HRESULT hr=S_OK;
  1360. HWND hwnd;
  1361. // Trace
  1362. TraceCall("COutlookExpress::BrowseToObject");
  1363. // Do we already have a global browser object ?
  1364. if (g_pBrowser)
  1365. {
  1366. // Get its Window
  1367. if (SUCCEEDED(g_pBrowser->GetWindow(&hwnd)))
  1368. {
  1369. // Activate that Window
  1370. IF_FAILEXIT(hr = ActivateWindow(hwnd));
  1371. }
  1372. // Tell the browser to browse to this object
  1373. IF_FAILEXIT(hr = g_pBrowser->BrowseObject(idFolder, 0));
  1374. }
  1375. // Otherwise, we need to create a new browser object
  1376. else
  1377. {
  1378. // We should always be on the correct thread here
  1379. if (m_dwThreadId == GetCurrentThreadId())
  1380. {
  1381. // Create a new browser object
  1382. IF_NULLEXIT(g_pBrowser = new CBrowser);
  1383. // CoIncrementInit It
  1384. IF_FAILEXIT(hr = g_pBrowser->HrInit(nCmdShow, idFolder));
  1385. }
  1386. // Otherwise, we need to thunk across to the init thread to make this happen.
  1387. // This can happen when the Finder.cpp does a BrowseToObject to open a messgae's container
  1388. else
  1389. {
  1390. // Thunk with a message
  1391. Assert(g_hwndInit && IsWindow(g_hwndInit));
  1392. IF_FAILEXIT(hr = (HRESULT)SendMessage(g_hwndInit, ITM_BROWSETOOBJECT, (WPARAM)nCmdShow, (LPARAM)idFolder));
  1393. }
  1394. }
  1395. exit:
  1396. // Done
  1397. return hr;
  1398. }
  1399. void COutlookExpress::_ProcessCommandLineFlags(LPWSTR *ppwszCmdLine, DWORD dwFlags)
  1400. {
  1401. Assert(ppwszCmdLine != NULL);
  1402. DWORD Mode = 0;
  1403. if (*ppwszCmdLine != NULL)
  1404. {
  1405. // '/mailonly'
  1406. if (0 == StrCmpNIW(*ppwszCmdLine, c_wszSwitchMailOnly, lstrlenW(c_wszSwitchMailOnly)))
  1407. {
  1408. SetStartFolderType(FOLDER_LOCAL);
  1409. Mode |= MODE_MAILONLY;
  1410. *ppwszCmdLine = *ppwszCmdLine + lstrlenW(c_wszSwitchMailOnly);
  1411. }
  1412. // '/newsonly'
  1413. else if (0 == StrCmpNIW(*ppwszCmdLine, c_wszSwitchNewsOnly, lstrlenW(c_wszSwitchNewsOnly)))
  1414. {
  1415. SetStartFolderType(FOLDER_NEWS);
  1416. Mode |= MODE_NEWSONLY;
  1417. *ppwszCmdLine = *ppwszCmdLine + lstrlenW(c_wszSwitchNewsOnly);
  1418. }
  1419. // '/outnews'
  1420. else if (0 == StrCmpNIW(*ppwszCmdLine, c_wszSwitchOutNews, lstrlenW(c_wszSwitchOutNews)))
  1421. {
  1422. SetStartFolderType(FOLDER_NEWS);
  1423. Mode |= MODE_OUTLOOKNEWS;
  1424. *ppwszCmdLine = *ppwszCmdLine + lstrlenW(c_wszSwitchOutNews);
  1425. }
  1426. }
  1427. if (!(dwFlags & MSOEAPI_START_ALREADY_RUNNING))
  1428. {
  1429. g_dwAthenaMode |= Mode;
  1430. }
  1431. }
  1432. // --------------------------------------------------------------------------------
  1433. // COutlookExpress::ProcessCommandLine
  1434. // --------------------------------------------------------------------------------
  1435. HRESULT COutlookExpress::ProcessCommandLine(INT nCmdShow, LPWSTR pwszCmdLine, BOOL *pfErrorDisplayed)
  1436. {
  1437. // Locals
  1438. HRESULT hr=S_OK;
  1439. LPWSTR pwszArgs;
  1440. FOLDERID idFolder=FOLDERID_ROOT;
  1441. HWND hwnd=NULL;
  1442. IF_DEBUG(DWORD dwTickStart=GetTickCount());
  1443. // Trace
  1444. TraceCall("COutlookExpress::ProcessCommandLine");
  1445. // Invalid Arg
  1446. Assert(pfErrorDisplayed);
  1447. // Do we have a command line
  1448. if (NULL == pwszCmdLine)
  1449. return S_OK;
  1450. // Goto Next Switch
  1451. if (*pwszCmdLine == L' ')
  1452. pwszCmdLine++;
  1453. // '/mailurl:'
  1454. if (0 == StrCmpNIW(pwszCmdLine, c_wszSwitchMailURL, lstrlenW(c_wszSwitchMailURL)))
  1455. {
  1456. SetStartFolderType(FOLDER_LOCAL);
  1457. pwszArgs = pwszCmdLine + lstrlenW(c_wszSwitchMailURL);
  1458. IF_FAILEXIT(hr = _HandleMailURL(pwszArgs, pfErrorDisplayed));
  1459. }
  1460. // '/newsurl:'
  1461. else if (0 == StrCmpNIW(pwszCmdLine, c_wszSwitchNewsURL, lstrlenW(c_wszSwitchNewsURL)))
  1462. {
  1463. SetStartFolderType(FOLDER_NEWS);
  1464. pwszArgs = pwszCmdLine + lstrlenW(c_wszSwitchNewsURL);
  1465. IF_FAILEXIT(hr = _HandleNewsURL(nCmdShow, pwszArgs, pfErrorDisplayed));
  1466. }
  1467. // '/eml:'
  1468. else if (0 == StrCmpNIW(pwszCmdLine, c_wszSwitchEml, lstrlenW(c_wszSwitchEml)))
  1469. {
  1470. pwszArgs = pwszCmdLine + lstrlenW(c_wszSwitchEml);
  1471. IF_FAILEXIT(hr = _HandleFile(pwszArgs, pfErrorDisplayed, FALSE));
  1472. }
  1473. // '/nws:'
  1474. else if (0 == StrCmpNIW(pwszCmdLine, c_wszSwitchNws, lstrlenW(c_wszSwitchNws)))
  1475. {
  1476. pwszArgs = pwszCmdLine + lstrlenW(c_wszSwitchNws);
  1477. IF_FAILEXIT(hr = _HandleFile(pwszArgs, pfErrorDisplayed, TRUE));
  1478. }
  1479. // Otherwise, decide where to start a browser at...
  1480. else
  1481. {
  1482. // Handle '/news'
  1483. if (0 == StrCmpNIW(pwszCmdLine, c_wszSwitchNews, lstrlenW(c_wszSwitchNews)))
  1484. {
  1485. // This sets g_dwIcwFlags
  1486. SetStartFolderType(FOLDER_NEWS);
  1487. if (g_pBrowser)
  1488. g_pBrowser->GetWindow(&hwnd);
  1489. hr = ProcessICW(hwnd, FOLDER_NEWS, TRUE);
  1490. if (hr != S_OK)
  1491. goto exit;
  1492. // Get Default News SErver
  1493. GetDefaultServerId(ACCT_NEWS, &idFolder);
  1494. }
  1495. // Handle '/mail /defclient'
  1496. else if (0 == StrCmpNIW(pwszCmdLine, c_wszSwitchMail, lstrlenW(c_wszSwitchMail)) ||
  1497. 0 == StrCmpNIW(pwszCmdLine, c_wszSwitchDefClient, lstrlenW(c_wszSwitchDefClient)))
  1498. {
  1499. // Locals
  1500. FOLDERINFO Folder;
  1501. FOLDERID idStore;
  1502. // This sets g_dwIcwFlags
  1503. SetStartFolderType(FOLDER_LOCAL);
  1504. if (g_pBrowser)
  1505. g_pBrowser->GetWindow(&hwnd);
  1506. hr = ProcessICW(hwnd, FOLDER_LOCAL, TRUE);
  1507. if (hr != S_OK)
  1508. goto exit;
  1509. // Get store ID of default account
  1510. if (FAILED(GetDefaultServerId(ACCT_MAIL, &idStore)))
  1511. idStore = FOLDERID_LOCAL_STORE;
  1512. // Get Inbox Id
  1513. if (SUCCEEDED(g_pStore->GetSpecialFolderInfo(idStore, FOLDER_INBOX, &Folder)))
  1514. {
  1515. idFolder = Folder.idFolder;
  1516. g_pStore->FreeRecord(&Folder);
  1517. }
  1518. }
  1519. // No switches
  1520. else
  1521. {
  1522. // default launch
  1523. // - if there is already a browser, just activate it
  1524. // - else if the option is set, select default inbox
  1525. // - else select the root (pidl = NULL)
  1526. if (g_pBrowser && SUCCEEDED(g_pBrowser->GetWindow(&hwnd)))
  1527. {
  1528. ActivateWindow(hwnd);
  1529. goto exit;
  1530. }
  1531. else if (DwGetOption(OPT_LAUNCH_INBOX) && (FALSE == ISFLAGSET(g_dwAthenaMode, MODE_NEWSONLY)))
  1532. {
  1533. // Locals
  1534. FOLDERINFO Folder;
  1535. FOLDERID idStore;
  1536. // This sets g_dwIcwFlags
  1537. SetStartFolderType(FOLDER_LOCAL);
  1538. // Get store ID of default account
  1539. if (FAILED(GetDefaultServerId(ACCT_MAIL, &idStore)))
  1540. idStore = FOLDERID_LOCAL_STORE;
  1541. // Get Inbox Id
  1542. if (SUCCEEDED(g_pStore->GetSpecialFolderInfo(idStore, FOLDER_INBOX, &Folder)))
  1543. {
  1544. idFolder = Folder.idFolder;
  1545. g_pStore->FreeRecord(&Folder);
  1546. }
  1547. }
  1548. }
  1549. // Browe to this new object, I assume if pidl=null, we browse to the root
  1550. IF_FAILEXIT(hr = BrowseToObject(nCmdShow, idFolder));
  1551. }
  1552. exit:
  1553. /*
  1554. // Cleanup
  1555. SafeMemFree(pszFree);
  1556. */
  1557. // Trace
  1558. TraceInfo(_MSG("Process Command Line Time: %d milli-seconds", GetTickCount() - dwTickStart));
  1559. // Done
  1560. return hr;
  1561. }
  1562. // --------------------------------------------------------------------------------
  1563. // COutlookExpress::_HandleFile
  1564. // --------------------------------------------------------------------------------
  1565. HRESULT COutlookExpress::_HandleFile(LPWSTR pwszCmd, BOOL *pfErrorDisplayed, BOOL fNews)
  1566. {
  1567. // Locals
  1568. HRESULT hr=S_OK;
  1569. INIT_MSGSITE_STRUCT initStruct;
  1570. DWORD dwCreateFlags = OENCF_SENDIMMEDIATE;
  1571. if (fNews)
  1572. dwCreateFlags |= OENCF_NEWSFIRST;
  1573. // Stack
  1574. TraceCall("COutlookExpress::_HandleFile");
  1575. // Invalid Arg
  1576. Assert(pfErrorDisplayed);
  1577. // Invalid Arg
  1578. if (NULL == pwszCmd || L'\0' == *pwszCmd)
  1579. {
  1580. hr = TraceResult(E_INVALIDARG);
  1581. goto exit;
  1582. }
  1583. // Does the file exist ?
  1584. if (FALSE == PathFileExistsW(pwszCmd))
  1585. {
  1586. // Locals
  1587. REPORTERRORINFO rError={0};
  1588. // Set hr
  1589. hr = TraceResult(MSOEAPI_E_FILE_NOT_FOUND);
  1590. // Duplicate It
  1591. LPSTR pszCmd = PszToANSI(CP_ACP, pwszCmd);
  1592. if (pszCmd)
  1593. {
  1594. // Make the rror
  1595. MAKEERROR(&rError, 0, IDS_ERROR_FILE_NOEXIST, 0, pszCmd);
  1596. rError.nHelpIds = 0;
  1597. // Show an error
  1598. *pfErrorDisplayed = _ReportError(g_hLocRes, hr, 0, &rError);
  1599. // Cleanup
  1600. MemFree(pszCmd);
  1601. }
  1602. // Done
  1603. goto exit;
  1604. }
  1605. initStruct.dwInitType = OEMSIT_FAT;
  1606. initStruct.pwszFile = pwszCmd;
  1607. hr = CreateAndShowNote(OENA_READ, dwCreateFlags, &initStruct);
  1608. exit:
  1609. // Done
  1610. return hr;
  1611. }
  1612. // --------------------------------------------------------------------------------
  1613. // COutlookExpress::_HandleNewsArticleURL
  1614. // --------------------------------------------------------------------------------
  1615. HRESULT COutlookExpress::_HandleNewsArticleURL(LPSTR pszServerIn, LPSTR pszArticle, UINT uPort, BOOL fSecure, BOOL *pfErrorDisplayed)
  1616. {
  1617. HRESULT hr=S_OK;
  1618. CHAR szAccountId[CCHMAX_ACCOUNT_NAME];
  1619. LPSTR psz = NULL,
  1620. pszBuf = NULL;
  1621. IImnAccount *pAccount=NULL;
  1622. INIT_MSGSITE_STRUCT initStruct;
  1623. LPMIMEMESSAGE pMsg = NULL;
  1624. Assert(pszServerIn);
  1625. // Stack
  1626. TraceCall("COutlookExpress::_HandleNewsArticleURL");
  1627. // Invalid Arg
  1628. Assert(pfErrorDisplayed);
  1629. // If a server was specified, then try to create a temp account for it
  1630. if (FALSE == FIsEmptyA(pszServerIn) && SUCCEEDED(CreateTempNewsAccount(pszServerIn, uPort, fSecure, &pAccount)))
  1631. {
  1632. // Get the Account name
  1633. IF_FAILEXIT(hr = pAccount->GetPropSz(AP_ACCOUNT_ID, szAccountId, ARRAYSIZE(szAccountId)));
  1634. }
  1635. // Otherwise, use the default news server
  1636. else
  1637. {
  1638. // If a server wasn't specified, then use the default account
  1639. IF_FAILEXIT(hr = GetDefaultNewsServer(szAccountId, ARRAYSIZE(szAccountId)));
  1640. }
  1641. // Bug #10555 - The URL shouldn't have <> around the article ID, but some lameoids probably will do it anyway, so deal with it.
  1642. if (FALSE == IsDBCSLeadByte(*pszArticle) && '<' != *pszArticle)
  1643. {
  1644. ULONG cchArticle;
  1645. cchArticle = lstrlen(pszArticle) + 4;
  1646. if (!MemAlloc((void **)&pszBuf, cchArticle))
  1647. {
  1648. hr = E_OUTOFMEMORY;
  1649. goto exit;
  1650. }
  1651. wnsprintf(pszBuf, cchArticle, TEXT("<%s>"), pszArticle);
  1652. psz = pszBuf;
  1653. }
  1654. else
  1655. {
  1656. psz = pszArticle;
  1657. }
  1658. hr = HrDownloadArticleDialog(szAccountId, psz, &pMsg);
  1659. if (S_OK == (hr))
  1660. {
  1661. Assert(pMsg != NULL);
  1662. initStruct.dwInitType = OEMSIT_MSG;
  1663. initStruct.pMsg = pMsg;
  1664. initStruct.folderID = FOLDERID_INVALID;
  1665. hr = CreateAndShowNote(OENA_READ, OENCF_NEWSFIRST, &initStruct);
  1666. }
  1667. else
  1668. {
  1669. // No errors if the user cancel'ed on purpose.
  1670. if (HR_E_USER_CANCEL_CONNECT == hr || HR_E_OFFLINE == hr)
  1671. hr = S_OK;
  1672. else
  1673. {
  1674. AthMessageBoxW(g_hwndInit, MAKEINTRESOURCEW(idsAthena), MAKEINTRESOURCEW(idsNewsTaskArticleError), 0, MB_OK|MB_SETFOREGROUND);
  1675. hr = S_OK;
  1676. }
  1677. }
  1678. exit:
  1679. // Cleanup
  1680. MemFree(pszBuf);
  1681. ReleaseObj(pAccount);
  1682. ReleaseObj(pMsg);
  1683. // Done
  1684. return hr;
  1685. }
  1686. // --------------------------------------------------------------------------------
  1687. // COutlookExpress::_HandleNewsURL
  1688. // --------------------------------------------------------------------------------
  1689. HRESULT COutlookExpress::_HandleNewsURL(INT nCmdShow, LPWSTR pwszCmd, BOOL *pfErrorDisplayed)
  1690. {
  1691. // Locals
  1692. HWND hwnd;
  1693. HRESULT hr=S_OK;
  1694. LPSTR pszCmd=NULL,
  1695. pszServer=NULL,
  1696. pszGroup=NULL,
  1697. pszArticle=NULL;
  1698. UINT uPort=(UINT)-1;
  1699. BOOL fSecure;
  1700. FOLDERID idFolder;
  1701. TCHAR szRes[CCHMAX_STRINGRES],
  1702. szError[MAX_PATH + CCHMAX_STRINGRES];
  1703. // Stack
  1704. TraceCall("COutlookExpress::_HandleNewsURL");
  1705. // Invalid Arg
  1706. Assert(pfErrorDisplayed);
  1707. Assert(pwszCmd != NULL);
  1708. Assert(*pwszCmd != 0);
  1709. // Since this is a URL, then don't need to worry about UNICODE
  1710. IF_NULLEXIT(pszCmd = PszToANSI(CP_ACP, pwszCmd));
  1711. // Un-escape the Url
  1712. UrlUnescapeInPlace(pszCmd, 0);
  1713. // Figure out if the URL is valid and what type of URL it is.
  1714. hr = URL_ParseNewsUrls(pszCmd, &pszServer, &uPort, &pszGroup, &pszArticle, &fSecure);
  1715. if ((hr == INET_E_UNKNOWN_PROTOCOL || hr == INET_E_INVALID_URL) &&
  1716. LoadString(g_hLocRes, idsErrOpenUrlFmt, szRes, ARRAYSIZE(szRes)))
  1717. {
  1718. // if bad url format, warn user and return S_OK as we handled it
  1719. // Outlook Express could not open the URL '%.100s' because it is not a recognized format.
  1720. // we clip the URL to 100 chars, so it easily fits in the MAX_PATH buffer
  1721. wnsprintf(szError, ARRAYSIZE(szError), szRes, pszCmd, lstrlen(pszCmd)>100?g_szEllipsis:c_szEmpty);
  1722. AthMessageBox(g_hwndInit, MAKEINTRESOURCE(idsAthena), szError, 0, MB_OK|MB_SETFOREGROUND);
  1723. return S_OK;
  1724. }
  1725. IF_FAILEXIT(hr);
  1726. // Compute the correct port number
  1727. if (uPort == -1)
  1728. uPort = fSecure ? DEF_SNEWSPORT : DEF_NNTPPORT;
  1729. // If we have an article, HandleNewsArticleURL
  1730. if (pszArticle)
  1731. {
  1732. // Launch a read note onto the article id
  1733. IF_FAILEXIT(hr = _HandleNewsArticleURL(pszServer, pszArticle, uPort, fSecure, pfErrorDisplayed));
  1734. }
  1735. // Otheriwse, create a PIDL and browse to that pidl (its a newsgroup)
  1736. else
  1737. {
  1738. // Locals
  1739. FOLDERID idFolder;
  1740. if (pszServer == NULL)
  1741. {
  1742. // If we have a browser, the its hwnd so that ICW has a parent
  1743. if (g_pBrowser)
  1744. g_pBrowser->GetWindow(&hwnd);
  1745. else
  1746. hwnd = NULL;
  1747. // Run the ICW if necessary
  1748. hr = ProcessICW(hwnd, FOLDER_NEWS, TRUE);
  1749. if (hr != S_OK)
  1750. goto exit;
  1751. }
  1752. // Create a PIDL for this newsgroup URL
  1753. if (SUCCEEDED(hr = GetFolderIdFromNewsUrl(pszServer, uPort, pszGroup, fSecure, &idFolder)))
  1754. {
  1755. // Browse to that object
  1756. IF_FAILEXIT(hr = BrowseToObject(nCmdShow, idFolder));
  1757. }
  1758. }
  1759. exit:
  1760. // Cleanup
  1761. SafeMemFree(pszCmd);
  1762. SafeMemFree(pszServer);
  1763. SafeMemFree(pszGroup);
  1764. SafeMemFree(pszArticle);
  1765. // Done
  1766. return hr;
  1767. }
  1768. // --------------------------------------------------------------------------------
  1769. // COutlookExpress::_HandleMailURL
  1770. //
  1771. // PURPOSE: Provides an entry point into Thor that allows us to be
  1772. // invoked from a URL. The pszCmdLine paramter must be a
  1773. // valid Mail URL or nothing happens.
  1774. //
  1775. // --------------------------------------------------------------------------------
  1776. HRESULT COutlookExpress::_HandleMailURL(LPWSTR pwszCmdLine, BOOL *pfErrorDisplayed)
  1777. {
  1778. // Locals
  1779. HRESULT hr=S_OK;
  1780. LPMIMEMESSAGE pMsg=NULL;
  1781. INIT_MSGSITE_STRUCT initStruct;
  1782. TCHAR szRes[CCHMAX_STRINGRES],
  1783. szError[MAX_PATH + CCHMAX_STRINGRES];
  1784. LPSTR pszCmdLine = NULL;
  1785. // Stack
  1786. TraceCall("COutlookExpress::_HandleMailURL");
  1787. // Invalid Arg
  1788. Assert(pfErrorDisplayed);
  1789. // No command line
  1790. if (NULL == pwszCmdLine || L'\0' == *pwszCmdLine)
  1791. {
  1792. hr = TraceResult(E_INVALIDARG);
  1793. goto exit;
  1794. }
  1795. // Since this is a URL, then don't need to worry about UNICODE
  1796. IF_NULLEXIT(pszCmdLine = PszToANSI(CP_ACP, pwszCmdLine));
  1797. // Create a Message Object
  1798. IF_FAILEXIT(hr = HrCreateMessage(&pMsg));
  1799. // NOTE: no URLUnescape in this function - it must be done in URL_ParseMailTo to handle
  1800. // URLs of the format:
  1801. //
  1802. // mailto:[email protected]?subject=AT%26T%3dBell&[email protected]
  1803. //
  1804. // so that the "AT%26T" is Unescaped into "AT&T=Bell" *AFTER* the "subject=AT%26T%3dBell&" blob is parsed.
  1805. hr = URL_ParseMailTo(pszCmdLine, pMsg);
  1806. if ((hr == INET_E_UNKNOWN_PROTOCOL || hr == INET_E_INVALID_URL) &&
  1807. LoadString(g_hLocRes, idsErrOpenUrlFmt, szRes, ARRAYSIZE(szRes)))
  1808. {
  1809. // if bad url format, warn user and return S_OK as we handled it
  1810. // Outlook Express could not open the URL '%.100s' because it is not a recognized format.
  1811. // we clip the URL to 100 chars, so it easily fits in the MAX_PATH buffer
  1812. wnsprintf(szError, ARRAYSIZE(szError), szRes, pszCmdLine, lstrlen(pszCmdLine)>100?g_szEllipsis:c_szEmpty);
  1813. AthMessageBox(g_hwndInit, MAKEINTRESOURCE(idsAthena), szError, 0, MB_OK|MB_SETFOREGROUND);
  1814. return S_OK;
  1815. }
  1816. IF_FAILEXIT(hr);
  1817. initStruct.dwInitType = OEMSIT_MSG;
  1818. initStruct.pMsg = pMsg;
  1819. initStruct.folderID = FOLDERID_INVALID;
  1820. hr = CreateAndShowNote(OENA_COMPOSE, OENCF_SENDIMMEDIATE, &initStruct);
  1821. exit:
  1822. // Cleanup
  1823. SafeRelease(pMsg);
  1824. MemFree(pszCmdLine);
  1825. // Done
  1826. return hr;
  1827. }
  1828. // --------------------------------------------------------------------------------
  1829. // COutlookExpress::InitWndProc
  1830. // --------------------------------------------------------------------------------
  1831. LRESULT EXPORT_16 CALLBACK COutlookExpress::InitWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  1832. {
  1833. // Locals
  1834. BOOL fRet;
  1835. HRESULT hr;
  1836. // Delegate to the Account Manager
  1837. if (g_pAcctMan && g_pAcctMan->ProcessNotification(msg, wp, lp) == S_OK)
  1838. return TRUE;
  1839. // Handle the Message
  1840. switch(msg)
  1841. {
  1842. case WM_ENDSESSION:
  1843. // if we get forced down by window, we don't exit clean, so deinit global opt it not called. We obviously don't have a mailbomb so clear the regkey.
  1844. SetDwOption(OPT_ATHENA_RUNNING, FALSE, NULL, 0);
  1845. break;
  1846. case WM_SETTINGCHANGE:
  1847. Assert (g_lpIFontCache);
  1848. if (g_lpIFontCache)
  1849. {
  1850. if (!wp || SPI_SETNONCLIENTMETRICS == wp || SPI_SETICONTITLELOGFONT == wp)
  1851. g_lpIFontCache->OnOptionChange();
  1852. }
  1853. break;
  1854. case ITM_WAB_CO_DECREMENT:
  1855. Wab_CoDecrement();
  1856. return 0;
  1857. case ITM_BROWSETOOBJECT:
  1858. return (LRESULT)g_pInstance->BrowseToObject((UINT)wp, (FOLDERID)lp);
  1859. case ITM_SHUTDOWNTHREAD:
  1860. return (LRESULT)g_pInstance->_CoDecrementInitMain((LPHINITREF)lp);
  1861. case ITM_POSTCOPYDATA:
  1862. if (lp)
  1863. {
  1864. g_pInstance->Start(MSOEAPI_START_ALREADY_RUNNING, (LPCWSTR)lp, SW_SHOWNORMAL);
  1865. MemFree((LPWSTR)lp);
  1866. }
  1867. break;
  1868. case WM_COPYDATA:
  1869. {
  1870. // Locals
  1871. COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT *)lp;
  1872. // Command-line
  1873. if (pCopyData->dwData == MSOEAPI_ACDM_CMDLINE)
  1874. {
  1875. // #25238: On Win95, OLE get's pissed if we syncronously do stuff on the
  1876. // WM_COPYDATA. On the most part it works, but if we show an error and pump messages
  1877. // then some messages get run out of sequence and we deadlock between msimn.exe and
  1878. // iexplore.exe. Now we post to ourselves as we don't care about the HRESULT anyway
  1879. // we free the duped string on the post
  1880. PostMessage(hwnd, ITM_POSTCOPYDATA, 0, (LPARAM)PszDupW((LPCWSTR)pCopyData->lpData));
  1881. return 0;
  1882. }
  1883. // Notification Thunk
  1884. else if (pCopyData->dwData == MSOEAPI_ACDM_NOTIFY)
  1885. {
  1886. // Locals
  1887. NOTIFYDATA rNotify;
  1888. LRESULT lResult=0;
  1889. // Crack the notification
  1890. if (SUCCEEDED(CrackNotificationPackage(pCopyData, &rNotify)))
  1891. {
  1892. // Otherwise, its within this process...
  1893. if (ISFLAGSET(rNotify.dwFlags, SNF_SENDMSG))
  1894. lResult = SendMessage(rNotify.hwndNotify, rNotify.msg, rNotify.wParam, rNotify.lParam);
  1895. else
  1896. PostMessage(rNotify.hwndNotify, rNotify.msg, rNotify.wParam, rNotify.lParam);
  1897. // Done
  1898. return lResult;
  1899. }
  1900. // Problems
  1901. else
  1902. Assert(FALSE);
  1903. }
  1904. }
  1905. break;
  1906. case MVM_NOTIFYICONEVENT:
  1907. g_pInstance->_HandleTrayIconEvent(wp, lp);
  1908. return (0);
  1909. }
  1910. // Delegate to default window procedure
  1911. return DefWindowProc(hwnd, msg, wp, lp);
  1912. }
  1913. HRESULT COutlookExpress::UpdateTrayIcon(TRAYICONACTION type)
  1914. {
  1915. NOTIFYICONDATA nid;
  1916. HWND hwnd = NULL;
  1917. ULONG i;
  1918. TraceCall("COutlookExpress::UpdateTrayIcon");
  1919. EnterCriticalSection(&m_cs);
  1920. // Make sure we have the init window around first
  1921. if (!g_hwndInit)
  1922. goto exit;
  1923. // Set up the struct
  1924. nid.cbSize = sizeof(NOTIFYICONDATA);
  1925. nid.uID = 0;
  1926. nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
  1927. nid.uCallbackMessage = MVM_NOTIFYICONEVENT;
  1928. if(m_hTrayIcon)
  1929. {
  1930. //Bug #86366 - (erici) Fixes leak. Don't create a new ICON each time COutlookExpress::UpdateTrayIcon is called.
  1931. nid.hIcon = m_hTrayIcon;
  1932. }
  1933. else
  1934. {
  1935. nid.hIcon = (HICON) LoadImage(g_hLocRes, MAKEINTRESOURCE(idiNewMailNotify), IMAGE_ICON, 16, 16, 0);
  1936. }
  1937. nid.hWnd = g_hwndInit;
  1938. LoadString(g_hLocRes, idsNewMailNotify, nid.szTip, sizeof(nid.szTip));
  1939. if (TRAYICONACTION_REMOVE == type)
  1940. {
  1941. Shell_NotifyIcon(NIM_DELETE, &nid);
  1942. }
  1943. // Add
  1944. if (TRAYICONACTION_ADD == type)
  1945. {
  1946. Shell_NotifyIcon(NIM_ADD, &nid);
  1947. }
  1948. g_pBrowser->WriteUnreadCount();
  1949. exit:
  1950. LeaveCriticalSection(&m_cs);
  1951. return (S_OK);
  1952. }
  1953. void COutlookExpress::_HandleTrayIconEvent(WPARAM wParam, LPARAM lParam)
  1954. {
  1955. HWND hwnd;
  1956. if (lParam == WM_LBUTTONDBLCLK)
  1957. {
  1958. if (g_pBrowser)
  1959. {
  1960. g_pBrowser->GetWindow(&hwnd);
  1961. if (IsIconic(hwnd))
  1962. ShowWindow(hwnd, SW_RESTORE);
  1963. SetForegroundWindow(hwnd);
  1964. PostMessage(hwnd, WM_COMMAND, ID_GO_INBOX, 0);
  1965. }
  1966. }
  1967. }