Broken GetMAPIOBJECT() object when calling from the outside (E_NOINTERFACE)?

  • Thread starter Thread starter Xavier Roche
  • Start date Start date
X

Xavier Roche

Hi folks,

I am trying to get the MAPI object interface from a outlook item object
(OOM) such as _MailItem, and then fetch the MAPIProp interface pointer.
Inside a COM addin, everything's OK. But from an outside source, the
IUnknown MAPI interface refuses to return the MAPIProp interface
pointer, with a "No such interface supported" error.

I suspected some nasty threading model behind this, but everything's
working with threaded appartment model.

- MAPIInitialize/MAPILogonEx were called (among with other inits such as
CoInitializeEx(..))
- Both CoCreateInstance(.., CLSCTX_LOCAL_SERVER) and CLSCTX_ALL were
tested when creating the outlook application object
- GetMAPIOBJECT() was used instead of the MAPIOBJECT property as it is
the suggested method (http://support.microsoft.com/?kbid=296483)

Anyone having any clue is welcome!


Very simplified code:

- External code:

if (CLSIDFromProgID(L"Outlook.Application", &clsidOutlook) == S_OK) {
...
if ( ( hr = CoCreateInstance(clsidOutlook, NULL,
CLSCTX_LOCAL_SERVER,
__uuidof(Outlook::_Application), (void **)&m_spOutlook) ) == S_OK)
...
if ( ( hr =
spApp->raw_GetNamespace(_bstr_t("MAPI"), &m_spNamespace) )
== S_OK) {
...

- The non-working code outside addin:

// m_spNamespace was fetched using raw_GetNamespace("MAPI" (..))
HRESULT hr;
VARIANT empty;
empty.vt = VT_ERROR;
empty.scode = DISP_E_PARAMNOTFOUND;
CComPtr<IDispatch> item;
if (SUCCEEDED(hr
= m_spNamespace->raw_GetItemFromID(eid, empty, &item))
) {
CComQIPtr<Outlook::_MailItem> pMail(pDisp);
IUnknown* pUnk = pMail->GetMAPIOBJECT(); // See Q296483
IMAPIProp* pMapiProp = NULL;
if (SUCCEEDED(hr
= pUnk ->QueryInterface(IID_IMAPIProp, (void**)&pMapiProp)))
{..
} else {
_com_error e(hr);
_bstr_t err = e.ErrorMessage();
MessageBox(NULL, err, _T("Error"), MB_SETFOREGROUND);
}
}
 
Xavier said:
- MAPIInitialize/MAPILogonEx were called (among with other inits such as
CoInitializeEx(..))

Bug found: the MAPIInitialize/MAPILogonEx were actually.. not being
called, leading to a E_FAIL error.
 
Xavier, did you use the CDO namespace and includes to get the IMessage
interface or the MAPI? I thought I needed the MAPI one but can't get it to
link.

Visual C 6.0, Windows 2000, Outlook 2003. I am trying to QueryInterface()
on the MAPIOBJECT of a calendar item. When I link my program I get the
following error:
SelectEvents.obj : error LNK2001: unresolved external symbol _IID_IMessage


These are my includes:
#include "stdafx.h"

#define INITGUID
#include <objbase.h>
#define USES_IID_IMessage
#include <mapix.h>
#include <mapitags.h>
#include <mapidefs.h>
#include <mapiutil.h>
#include <mapiguid.h>
#include <imessage.h>

stdafx has altbase.h and the other standard windows include files in it.

This is the line in question:
hr = ptr_Mapi->QueryInterface(IID_IMessage, (void **)&lpIMsg);

Thanks.
 
Well, I found a post out of many that helped me order my includes correctly
to get my program to link. Something is still funny in that when I
reference my IMessage pointer it shows all the available properties and
functions (like get_To()) but if I try to use it I get an error the get_To()
is not a member of IMessage. Onward and upward....
 
Mike said:
SelectEvents.obj : error LNK2001: unresolved external symbol _IID_IMessage

Define the needed USES_XX macros before including mapi .h defs:

#define INITGUID
#define USES_IID_IMessage
#define USES_IID_IMAPIPropData
#define USES_IID_IMAPITable
...
#include <initguid.h>
#include <mapiguid.h>
#define USES_IID_IMessage

Ah, weird. This should do the trick.
 
I needed to have the includes in a very specific order. Once I did that
things started linking.
Thanks Xavier.
 
Back
Top