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

Article translations Article translations
Article ID: 296483 - View products that this article applies to.
This article was previously published under Q296483
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

Symptoms

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)

Cause

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.

Resolution

To use the MAPIOBJECT property, use CDO to obtain it from the corresponding CDO object.

Status

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);
}
				

Properties

Article ID: 296483 - Last Review: October 26, 2013 - Revision: 3.0
Applies to
  • Microsoft Outlook 98 Standard Edition
  • Microsoft Outlook 2000 Standard Edition
  • Microsoft Outlook 2002 Standard Edition
Keywords: 
kbnosurvey kbarchive kbmsg kbprb KB296483

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com