QueryInterface for IID_IMAPIGetSession not working


  • I'm trying to get the current MAPI session in a wrapped PST provider. From the documentation, is sounds like you need to QueryInterface the provider's MAPI support object. So I do something like

    // IID_IMAPIGetSession
    DEFINE_GUID(IID_IMAPIGetSession, 0x614ab435, 0x491d, 0x4f5b, 0xa8, 0xb4, 0x60, 0xeb, 0x3, 0x10, 0x30, 0xc6);

    HRESULT CMSProvider::Logon(IMAPISupport* support, ...)


        IMAPIGetSession* session;

        support->QueryInterface(IID_IMAPIGetSession, (void**)&session);


    The QI fails with E_NOINTERFACE. Any idea what's wrong?

    Tuesday, July 05, 2011 6:32 PM


All replies

  • Are you using Outlook 2010?
    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Wednesday, July 06, 2011 2:50 PM
  • Yes. Tried 2007 too with the same results.

    It sounds like the IMAPIGetSession interface is one that's available for a service provider to use to get the current session rather than being one that the provider implements for Outlook to use. Does that sound right to you?

    Wednesday, July 06, 2011 4:09 PM
  • I have not tried to use IMAPIGetSession, but yes, that souds right.

    Can you try to use IMAPISupport provided in your service entry function instead of IMSProvider::Logon?


    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Wednesday, July 06, 2011 4:43 PM
  • I tried ServiceEntry and got the same result. So either the documentation is wrong or I'm not using it correctly.
    Thursday, July 07, 2011 5:08 PM
  • support->QueryInterface(&IID_IMAPIGetSession, (void**)&session);
    Thursday, July 07, 2011 5:38 PM
  • That won't compile. Neither will

    support->QueryInterface(&IID_IDispatch, (void**)&session);


    support->QueryInterface(IID_IDispatch, (void**)&session);


    Thursday, July 07, 2011 7:46 PM
  • Hi Chunk,

    What is the status of the problem on your side? If you still need any assistant about the problem, I will involve some one who are more familiar about this.

    Best Regards,

    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 11, 2011 11:06 AM
  • Nothing has changed. I still can't do a IMAPISupport::QueryInterface for IID_IMAPIGetSession. I would greatly appreciate any help you can give.



    Monday, July 11, 2011 5:55 PM
  • Sorry - I was looking at some C code for reference - should have looked at C++. As far as I can tell, your QI should have worked. You may want to open a case so we can debug the reason for the failure.
    Monday, July 11, 2011 9:54 PM
  • I went ahead and debugged this - it turns out this interface is only available on the support object passed to transport providers through TransportLogon. Address book and message store providers get a different support object which does not support this interface. This is a documentation bug which I will work to get addressed. Sorry for the confusion!
    Tuesday, July 12, 2011 3:25 PM
  • Bad news but thanks. How can a store provider get the session? MAPILogonEx?
    Tuesday, July 12, 2011 7:48 PM
  • I suppose that would work. Typically, a provider shouldn't need to access a MAPI session for the normal course of its work.
    Tuesday, July 12, 2011 7:55 PM
  • You can implement a dummy COM add-in in the same dll, retrieve IMAPISession from Namespace.MAPIOBJECT in OOM and share the session in a global variable.
    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Tuesday, July 12, 2011 8:11 PM
  • Such a solution would lock your add-in to only working when loaded in-proc with Outlook. MAPI gets used by other applications and such dependencies are discouraged.
    Wednesday, July 13, 2011 1:12 PM
  • True, but it would not be any worse than the Hotmail provider checking if the parent process name is outlook.exe :-)
    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Wednesday, July 13, 2011 2:21 PM
  • Touche, but we can always try to do better.

    • Marked as answer by Chuck Bohling Friday, July 15, 2011 5:08 PM
    Wednesday, July 13, 2011 7:21 PM