Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DeleteMessage not working properly

11 views
Skip to first unread message

pp

unread,
Jul 2, 2009, 5:26:01 AM7/2/09
to

Hi,

I have implemented a library for use with VB code that gets round security
prompts. I recently optimised this library as I discovered it was making
many unnecessary MAPI logons, so that it just logs on on initialisation and
off once done. Since this optimisation, the DeleteMessage function has shown
very strange behaviour.

The first call to DeleteMessage (code below) works, and some subsequent ones
may too. However, after a while, the call fails. More than this though, it
doesn't actually return - there is no error code, no crash, nothing. There
is no loop, and once the call has failed (i.e. return it NOT given back to
the VB calling code), the CPU useage is normal.

What would cause this? It has only happened since I changed the code to use
the existing MAPI session (which works for all the other functions needing it
fine - even after the DeleteMessage call has failed). As a workaround I have
amended my VB code to instantiate a new object before calling the
DeleteMessage function - but this isn't ideal (it means more MAPILogons,
which should be unnecessary) - I would like to know what is wrong and fix it.

Thanks.

Code is:

STDMETHODIMP CPMapiWrapper::DeleteMessage(/*[in]*/VARIANT pMailItem,
/*[out]*/ VARIANT *result)
{
LPUNKNOWN unk = NULL;

if (pMailItem.vt == (VT_DISPATCH | VT_BYREF)) unk =
getMapiobjectProperty(*(pMailItem.ppdispVal));
else if (pMailItem.vt == (VT_DISPATCH)) unk =
getMapiobjectProperty(pMailItem.pdispVal);
else return E_INVALIDARG;
if (!unk) return E_NOINTERFACE;

HRESULT hr = deleteMessage(unk, result);
unk->Release();

return hr;
}


HRESULT CPMapiWrapper::deleteMessage(LPUNKNOWN unk, VARIANT *result)
{
CComQIPtr<IMessage, &IID_IMessage> msg;
msg = unk;

HRESULT hr=E_FAIL;
LPMDB pStore = NULL;

CComVariant v;
VariantInit(&v);
v=_T("FAILED");

// Get required properties
SizedSPropTagArray(3, rcols) = {3, {PR_ENTRYID, PR_PARENT_ENTRYID,
PR_STORE_ENTRYID}};
ULONG pcount;
SPropValue *props=0;
hr = msg->GetProps((SPropTagArray*)&rcols,0,&pcount,&props);

if (SUCCEEDED(hr) && (pcount==3))
{
// Now delete the item
ULONG ulObjType = 0;
LPMAPIFOLDER lpFolder = NULL;
if (!lpSession==NULL)
{
hr = lpSession->OpenMsgStore(NULL, props[2].Value.bin.cb,
(ENTRYID*)props[2].Value.bin.lpb,NULL, MAPI_BEST_ACCESS,
&pStore);//OpenEntry(pProp3->Value.bin.cb, (ENTRYID*)pProp3->Value.bin.lpb,
&IID_IUnknown, MAPI_BEST_ACCESS,&ulObjType,(LPUNKNOWN*)&pStore);
if(SUCCEEDED(hr) && pStore)
{
hr = pStore->OpenEntry(props[1].Value.bin.cb,
(ENTRYID*)props[1].Value.bin.lpb, &IID_IMAPIFolder,
MAPI_MODIFY,&ulObjType,(LPUNKNOWN*)&lpFolder);
if (SUCCEEDED(hr) && (!lpFolder==NULL))
{
ENTRYLIST list;
list.cValues = 1;
list.lpbin = &props[0].Value.bin;
if (ulObjType == MAPI_FOLDER) {
hr=lpFolder->DeleteMessages(&list,0L,NULL,0);
if ( hr == S_OK )
v=_T("SUCCESS");
else if ( hr == MAPI_W_PARTIAL_COMPLETION )
v = _T("PARTIAL SUCCESS");
else if ( hr == MAPI_E_NOT_FOUND )
v = _T("Not found");
else
v = hr;
}
else
{
v = _T("Failed to obtain folder.");
}
lpFolder->Release();
ULONG uflags=0;
pStore->StoreLogoff(&uflags);
pStore->Release();
}
}
else
{
v=_T("Failed to open store.");
}
}
else
{
v = _T("No session initialised.");
}
}
else
{
v = _T("Couldn't read message properties.");
}
v.Detach(result);
return hr;
}

pp

unread,
Jul 2, 2009, 5:28:01 AM7/2/09
to

In case it helps, this is the initialize function for the class:

STDMETHODIMP CPMapiWrapper::Initialize()
{
#define MAPI_NO_COINIT 0x08
MAPIINIT_0 MAPIINIT = { 0, MAPI_MULTITHREAD_NOTIFICATIONS | MAPI_NO_COINIT };
HRESULT hr = MAPIInitialize(&MAPIINIT);
if(hr == MAPI_E_UNKNOWN_FLAGS)
{
MAPIINIT.ulFlags &= ~MAPI_NO_COINIT;
hr = MAPIInitialize(&MAPIINIT);
}
if (FAILED(hr)) hr = MAPIInitialize (NULL);
if (SUCCEEDED(hr)) hr = MAPILogonEx(0, NULL, NULL, MAPI_EXTENDED,
&lpSession);
if (SUCCEEDED(hr)) bSessionLoggedOn = true;
return hr;
}

Dmitry Streblechenko

unread,
Jul 3, 2009, 1:49:06 AM7/3/09
to

If you are using your code alongside the Outlook Object Model, why not
retrieve IMAPISession from Namespace.MAPIOBJECT in OOM instead of calling
MAPILogon?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"pp" <p...@discussions.microsoft.com> wrote in message
news:79E2293F-2C25-44B2...@microsoft.com...

pp

unread,
Jul 3, 2009, 4:50:00 AM7/3/09
to

Because this needs to work with Outlook 2000 and above. I think the
Namespace.MAPIOBJECT isn't available in OL2000?

Dmitry Streblechenko

unread,
Jul 5, 2009, 12:11:23 PM7/5/09
to

Why not branch based on the version of Outlook installed?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"pp" <p...@discussions.microsoft.com> wrote in message

news:BBA2493C-FF17-4880...@microsoft.com...

pp

unread,
Jul 5, 2009, 2:21:09 PM7/5/09
to

Either way, I don't see how that is anything to do with the problem at hand?
0 new messages