[DUG] Trouple with Outlook Folder.Items

Jason Coley Jason at software-solutions.co.nz
Mon Jul 3 08:32:30 NZST 2006


I have some code that will iterate through some MAPI folders using their
Folder and Store Ids. This procedure is in a separate thread from my
Main App.

 

The line IDispatch(MyFolder) := NameSpace.GetFolderFromID works fine,
and returns a pointer to the folder. But if I try to access the Items of
the folder I am getting an access violation. Can anyone shed some light
on why this is happening? 

 

This same code works fine if I run it within an Exchange Extension addin
under the main thread. This is actually running in a separate exe.

 

var

  hr: HRESULT;

  MyFolder: MAPIFolder;

  tTemp: IMAPITable;

  iSess: IMAPISession;

  OLApplication: _ApplicationDisp;

 

begin

 

      MAPIInitialize(nil);

      MAPILogonEx(0, '', '', MAPI_BEST_ACCESS, iSess);

 

      IDispatch(OLApplication) :=
IDispatch(CoOutlookApplication.Create);

      for i := 0 to MyDList.Folders.Count - 1 do

      begin

        //Get IMAPITable

        try

          NameSpace := OLApplication.GetNamespace('MAPI');

          IDispatch(MyFolder) := NameSpace.GetFolderFromID(

                MyDList.Folders.Items[i].FolEID,

                MyDList.Folders.Items[i].StoreEID);

        except

          MyFolder := nil;

        end;

        if MyFolder = nil then goto cleanup;

 

        hr := (MyFolder.Items.RawTable as
IUnknown).QueryInterface(IID_IMAPITable, tTemp);

.......

End;

 

 

Regards

Jason

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20060703/42159d05/attachment.html


More information about the Delphi mailing list