Outlook + getitemfromid + MAPI_E_NOT_FOUND

Giganews Newsgroups
Subject: Outlook + getitemfromid + MAPI_E_NOT_FOUND
Posted by:  Marcin Junger (marcin.jung…@sage.com)
Date: Tue, 03 Jul 2007

Hello,
I'm trying to find deleted tasks in Outlook. As there is no way to catch
outlook deletion, I loop through my own list of items and for each item
i call the following function:

function SafeGetItemFromId(aNameSpace: _NameSpace;aStoreId: WideString;
aEID: AnsiString): variant;
begin
    VarClear(Result);
    try
      Result := aNameSpace.GetItemFromID(aEID,aStoreId);
    except
      on E:EOleSysError do begin
        //An exception will be thrown if we can't find the appointment =>
        // if we couldn't find it the user might have deleted it, so
        // we pass across the serverID to CRM to request a delete from CRM.
        Log(Format('SafeGetItemFromId: Exception while searchng for
item:%0:s (error code: %1:x, getlasterror cod:%3:x, error msg:
%2:s)',[aEID,e.ErrorCode,e.Message,GetLastError]));
        if (e.ErrorCode = HRESULT($8004010F)) then begin
          Log('SafeGetItemFromId: item not found, not reraising
exception...')
        end else begin
          raise
TAdvException.Create(e,'MJ681','Globals->SafeGetItemFromId');
        end;
      end;
    end;
end;

GetItemFromID should raise exception with code = HRESULT($8004010F). The
problem is that e.ErrorCode is different each time I start up outlook...

How can I get MAPI error code?
thanks
Marcin Junger

Replies