none
Getting store ID (IOlkAccount) not present after first startup of Outlook - after account is added RRS feed

  • Question

  • Hi All,

    The scenario happens ONLY during the first time Outlook is started after a  new mailbox is added. All starts of Outlook after the initial start do not exhibit the issue. So the first start after the account/mailbox is added to Outlook is where the issue is.

    With the add-in,  we want to identify the account when a user selects a mail item in the inbox. We are able to retreive the store ID from MailFolder during the selection event. This process works every time. 

    However, retrieving the store ID using the account manager does not work. But strangely, Outlook spy does show the correct value within the account manager. So obviously, Outlook Spy must be aquiring the store ID differently than I am.

    My question, is there another way to retreive the IOlkAccount interface and query the store ID (PROP_ACCT_DELIVERY_STORE >>> PR_IPM_ID (0x00180102)). 

    I must be able to match the folder to the account every time with out fail, and it appears that the IOlkAccount is unreliable.

    Here is a code snippet.

    // W O R K S all the time !!!!! // Works on fodler selection event CComPtr<Outlook::MAPIFolder> spFolder = NULL; m_spExplorer->get_CurrentFolder(&spFolder); BSTR bstrStoreId = nullptr; spFolder->get_StoreID(&bstrStoreId); if (bstrStoreId) { std::wstring wsStoreId(bstrStoreId, ::SysStringLen(bstrStoreId)); } // F A I L S first start!!!! // Called on addin startup event (STDMETHOD(OnStartupComplete)(SAFEARRAY **custom)) // Get the accounts interface and get all accounts. // ... std::wstring wsStoreId; CComPtr<Outlook::_Accounts> spAccts; HRESULT hr = spNamespace->get_Accounts(&spAccts); if (SUCCEEDED(hr) && spAccts) { long lCount = 0L; spAccts->get_Count(&lCount); for (long l = 1L; l <= lCount; l++) { CComPtr<Outlook::_Account> spAcct; hr = spAccts->Item(_variant_t(l), &spAcct); if (SUCCEEDED(hr) && spAcct) { CAccount acct; CComPtr<Outlook::_Store> spDeliveryStore; hr = spAcct->get_DeliveryStore(&spDeliveryStore);

    // Returns 0x800C8101 first run after account installed

    if (SUCCEEDED(hr) && spDeliveryStore) // Fails to return the store interface { BSTR bstrStoreId = nullptr; spDeliveryStore->get_StoreID(&bstrStoreId); acct.m_wsFolderDeliveryEntryID = GetStringFromBSTR(bstrStoreId); BSTR bstrDisplayName = nullptr; spDeliveryStore->get_DisplayName(&bstrDisplayName); wsStoreId = GetStringFromBSTR(bstrDisplayName); } else { CComPtr<IUnknown> spUnk; spAcct->get_IOlkAccount(&spUnk); if (spUnk) { IOlkAccount* lpAccount = nullptr; hr = spUnk->QueryInterface(IID_IOlkAccount, reinterpret_cast<LPVOID*>(&lpAccount)); if (SUCCEEDED(hr) && lpAccount) { // Get the store entry ID ACCT_VARIANT pProperty = { NULL }; hr = lpAccount->GetProp(PR_IPM_ID, &pProperty);

    // THE value returned on first startup is E_ACCT_NOT_FOUND (0x800C8101)

    if (SUCCEEDED(hr) && pProperty.dwType == PT_BINARY && pProperty.Val.dw > 0) // FAILS { wsStoreId = ToHex((LPBYTE)pProperty.Val.bin.pb, pProperty.Val.dw); } lpAccount->Release(); } } } } } }

    Any suggestions would be greatly appreciated.

    Thanks,

    Tom


    Friday, September 28, 2018 7:55 PM