Board index » delphi » Hooking Items.ItemAdd event in Outlook
Leonid Zeitlin
![]() Delphi Developer |
Hooking Items.ItemAdd event in Outlook2005-04-18 10:48:55 PM delphi56 Hi all, My Delphi applicaiton is working with Outlook via COM. I want to hook the ItemAdd event of the Items collection of a folder. I approached this as follows. First, created a class: TFolderItemsEventSink = class(TInterfacedObject, IDispatch) protected function GetTypeInfoCount(out Count: Integer): HResult; stdcall; function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall; function GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall; function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall; end; All methods are stubs - just return S_OK. Then I attempt to connect my class as a sink to the Items collection: var OutlookApplication : TOutlookApplication; Connection : Integer; ... Folder := OutlookApplication.GetNamespace('MAPI').GetDefaultFolder(olFolderSentMail); InterfaceConnect(Folder.Items, DIID_ItemsEvents, TFolderItemsEventSink.Create, Connection); InterfaceConnect works correctly. Now I expect that when an item is added to the Sent folder, my Invoke method is called. But it just never happens. What am I doing wrong? Can anyone suggest how to hook the event properly? Thanks, Leonid |