BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hooking Items.ItemAdd event in Outlook

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Leonid Zeitlin
Guest





PostPosted: Mon Apr 18, 2005 2:48 pm    Post subject: Hooking Items.ItemAdd event in Outlook Reply with quote



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


Back to top
George Birbilis
Guest





PostPosted: Tue Apr 19, 2005 12:09 pm    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote



Quote:
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:

I suppose you should return that you implement a certain method (fixed Name)
for it to call you back on that ID. There was a nice tutorial for COM
callbacks / event sinks etc. for Delphi online. Let me know if you can't
find it (had found it using Copernic agent)


--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
--------------



Back to top
Leonid Zeitlin
Guest





PostPosted: Tue Apr 19, 2005 12:12 pm    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote



Hi George,
Do you have a link to that tutorial? I can't seem to find it.

BTW, even GetIDsOfNames is not called for my sink object.

Thanks,
Leonid


"George Birbilis" <birbilis (AT) kagi (DOT) com> сообщил/сообщила в новостях следующее:
news:4264f50a (AT) newsgroups (DOT) borland.com...
Quote:
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:

I suppose you should return that you implement a certain method (fixed
Name)
for it to call you back on that ID. There was a nice tutorial for COM
callbacks / event sinks etc. for Delphi online. Let me know if you can't
find it (had found it using Copernic agent)


--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
--------------





Back to top
Dmitry Streblechenko
Guest





PostPosted: Tue Apr 19, 2005 6:10 pm    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote

Nope, all event interfaces are dispinterfaces, they do not have a v-table.
Everything is done through IDispatch.Invoke.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"George Birbilis" <birbilis (AT) kagi (DOT) com> wrote

Quote:
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:

I suppose you should return that you implement a certain method (fixed
Name) for it to call you back on that ID. There was a nice tutorial for
COM callbacks / event sinks etc. for Delphi online. Let me know if you
can't find it (had found it using Copernic agent)


--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
--------------





Back to top
Dmitry Streblechenko
Guest





PostPosted: Tue Apr 19, 2005 6:13 pm    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote

You *must* store Folder.Items in a global (class) variable to make sure it
is referenced and alive at all times. The way yourr code is implemented
right now, the compiler creates an implicit local variable to store
Folder.Items, which is then dereferenced and released as soon as it goes out
of scope (the current method?).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Leonid Zeitlin" <lz (AT) csltd (DOT) com.ua> wrote

Quote:
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





Back to top
George Birbilis
Guest





PostPosted: Wed Apr 20, 2005 1:30 am    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote

I think it was:
http://www.gekko-software.nl/Delphi/art10.htm
or one of the other articles at that site (don't have that page cached to
take a look)

Quote:
Do you have a link to that tutorial? I can't seem to find it.

BTW, even GetIDsOfNames is not called for my sink object.

Thanks,
Leonid


"George Birbilis" <birbilis (AT) kagi (DOT) com> сообщил/сообщила в новостях
следующее:
news:4264f50a (AT) newsgroups (DOT) borland.com...
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:

I suppose you should return that you implement a certain method (fixed
Name)
for it to call you back on that ID. There was a nice tutorial for COM
callbacks / event sinks etc. for Delphi online. Let me know if you can't
find it (had found it using Copernic agent)


--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
--------------







Back to top
Leonid Zeitlin
Guest





PostPosted: Wed Apr 20, 2005 10:54 am    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote

Thanks a lot, Dmitry, your suggestion solved my problem.

Regards,
Leonid

"Dmitry Streblechenko" <dmitry (AT) dimastr (DOT) com> сообщил/сообщила в новостях
следующее: news:42654a35$1 (AT) newsgroups (DOT) borland.com...
Quote:
You *must* store Folder.Items in a global (class) variable to make sure it
is referenced and alive at all times. The way yourr code is implemented
right now, the compiler creates an implicit local variable to store
Folder.Items, which is then dereferenced and released as soon as it goes
out
of scope (the current method?).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Leonid Zeitlin" <lz (AT) csltd (DOT) com.ua> wrote in message
news:4263c8d7 (AT) newsgroups (DOT) borland.com...
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







Back to top
Leonid Zeitlin
Guest





PostPosted: Thu Apr 21, 2005 11:42 am    Post subject: Re: Hooking Items.ItemAdd event in Outlook Reply with quote

Thanks for the link, George

Regards,
Leonid


"George Birbilis" <birbilis (AT) kagi (DOT) com> сообщил/сообщила в новостях следующее:
news:42664384 (AT) newsgroups (DOT) borland.com...
Quote:
I think it was:
http://www.gekko-software.nl/Delphi/art10.htm
or one of the other articles at that site (don't have that page cached to
take a look)

Do you have a link to that tutorial? I can't seem to find it.

BTW, even GetIDsOfNames is not called for my sink object.

Thanks,
Leonid


"George Birbilis" <birbilis (AT) kagi (DOT) com> сообщил/сообщила в новостях
следующее:
news:4264f50a (AT) newsgroups (DOT) borland.com...
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:

I suppose you should return that you implement a certain method (fixed
Name)
for it to call you back on that ID. There was a nice tutorial for COM
callbacks / event sinks etc. for Delphi online. Let me know if you
can't
find it (had found it using Copernic agent)


--
-----
George Birbilis (birbilis (AT) kagi (DOT) com)
Microsoft Most Valuable Professional
MVP J# for 2004 & 2005
http://www.kagi.com/birbilis
--------------









Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.