PRB: E_FAIL Calling QueryInterface from an IUnknown Pointer Obtained from MAPIOBJECTProperty (296483)



The information in this article applies to:

  • Microsoft Outlook 98
  • Microsoft Outlook 2000
  • Microsoft Outlook 2002

This article was previously published under Q296483

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

Modification Type:MinorLast Reviewed:3/4/2004
Keywords:kbMsg kbprb KB296483