You are currently offline, waiting for your internet to reconnect

PRB: E_FAIL Calling QueryInterface from an IUnknown Pointer Obtained from MAPIOBJECTProperty

This article was previously published under Q296483
This article has been archived. It is offered "as is" and will no longer be updated.
When you query for a specific MAPI interface by using a pointer that you obtained from an Outlook object's MAPIOBJECT property, you may receive the following error message:
0x80004005 (E_FAIL)
The MAPIOBJECT property is available only for compatibility with Microsoft Collaboration Data Objects (CDO) 1.21. It is a hidden property of Outlook Object Model objects, and is not meant to be used from the Outlook object. The MAPIOBJECT property is meant to be used from the corresponding CDO object.
To use the MAPIOBJECT property, use CDO to obtain it from the corresponding CDO object.
This behavior is by design.
More information
The following code sample uses the Outlook Object Model to demonstrate the problem:
//Add code above to get an instance of the Outlook application//and get the MAPI namespace.RecipientPtr  recipient;AddressEntry* pAddressEntry = NULL;IMailUser* pMailUser = NULL;IUnknown* pUnk = NULL;HRESULT hr;pNameSpace->get_CurrentUser(&recipient);// Get the AddressEntry of the current user.recipient->get_AddressEntry(&pAddressEntry);//Get the MAPIOBJECT of the AddressEntry.pAddressEntry->get_MAPIOBJECT(&pUnk);//The following line fails with 0x80004005:hr = pUnk->QueryInterface(IID_IMailUser, (void**) &pMailUser);				
The following code sample uses a CDO that allows proper access to the MAPIOBJECT property:
//Add code above to log on to a CDO session.AddressEntryPtr pAddrEntry = NULL;IMailUser* pMailUser = NULL;IUnknown* pUnk = NULL;pAddrEntry = pSession->GetCurrentUser();pUnk = pAddrEntry->GetMAPIOBJECT();HRESULT hr = pUnk->QueryInterface(IID_IMailUser, (void**) &pMailUser);if(pMailUser){	SPropTagArray props;	props.aulPropTag[0] = PR_EMAIL_ADDRESS;	props.cValues = 1;	SPropValue* vals = NULL;	unsigned long valCount = 0;	hr = pMailUser->GetProps(&props, 0, &valCount, &vals);	MessageBox(NULL, vals->Value.lpszA, "Debug", MB_OK);}				

Article ID: 296483 - Last Review: 10/26/2013 14:58:00 - Revision: 3.0

Microsoft Outlook 98 Standard Edition, Microsoft Outlook 2000 Standard Edition, Microsoft Outlook 2002 Standard Edition

  • kbnosurvey kbarchive kbmsg kbprb KB296483