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