A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Event trigers only first two times from FromRegion.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 23rd 10, 02:59 PM posted to microsoft.public.outlook.program_addins
Lukasz
external usenet poster
 
Posts: 3
Default Event trigers only first two times from FromRegion.

Hello,

I have a custom VSTO Addin with FormRegion. In that add_in I wan't to hook to the events triggered when a user presses Reply or Forward buttons of the inspector window running my FormRegion. To do this I do:

Private Sub ChoixProjetRegion_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing

If TypeOf (Me.OutlookItem) Is Outlook.MailItem AND Me.OutlookFormRegion.FormRegionMode = Outlook.OlFormRegionMode.olFormRegionRead Then
AddHandler CType(Me.OutlookItem, Outlook.MailItem).Reply, (AddressOf OutlookApplication_ItemReply)

End If

End Sub



Private Sub OutlookApplication_ItemReply(ByVal Item As Object, ByRef Cancel As Boolean)
MsgBox("here")
End Sub

It works. I see My Message Box when I press Reply. The Problem Is that it only works the first two times. ie, on the reply window I close it, and press Reply again on the original window and I get my MsgBox again, followed by the reply window. I close it again, and click on Reply thisr time, but this time the Reply window comes on without the MsgBox.

If I keep closing the Reply window and pressing the Reply button again a few times, eventually I'll get:

"COM object that has been separated from its underlying RCW cannot be used."



Does anyone know what's going on?.
Submitted using http://www.outlookforums.com
  #2  
Old April 23rd 10, 03:58 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Event trigers only first two times from FromRegion.

Your handler is being eaten by the garbage collector. Make sure to declare
all relevant objects at class level, where they won't be garbage collected
and will remain in scope. You need a class level MailItem object that you
assign to that item and then you add the event handler to that class level
object.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Lukasz" lukaszmail[at]gmail[dot]com wrote in message
...
Hello,
I have a custom VSTO Addin with FormRegion. In that add_in I wan't to hook
to the events triggered when a user presses Reply or Forward buttons of
the inspector window running my FormRegion. To do this I do:

Private Sub ChoixProjetRegion_FormRegionShowing(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing

If TypeOf (Me.OutlookItem) Is Outlook.MailItem AND
Me.OutlookFormRegion.FormRegionMode =
Outlook.OlFormRegionMode.olFormRegionRead Then
AddHandler CType(Me.OutlookItem, Outlook.MailItem).Reply,
(AddressOf OutlookApplication_ItemReply)

End If

End Sub



Private Sub OutlookApplication_ItemReply(ByVal Item As Object, ByRef
Cancel As Boolean)
MsgBox("here")
End Sub

It works. I see My Message Box when I press Reply. The Problem Is that it
only works the first two times. ie, on the reply window I close it, and
press Reply again on the original window and I get my MsgBox again,
followed by the reply window. I close it again, and click on Reply thisr
time, but this time the Reply window comes on without the MsgBox.

If I keep closing the Reply window and pressing the Reply button again a
few times, eventually I'll get:

"COM object that has been separated from its underlying RCW cannot be
used."



Does anyone know what's going on?. Submitted using
http://www.outlookforums.com


  #3  
Old April 23rd 10, 04:42 PM posted to microsoft.public.outlook.program_addins
Lukasz
external usenet poster
 
Posts: 3
Default Event trigers only first two times from FromRegion.

That was it. Thank you Ken. It even took care of the COM error. My woes are not over though. Now the event handler executes between two and four times whenever I click on the Reply. Any idea why?

Thanks,

Lukasz

kenslovak wrote on Fri, 23 April 2010 10:58
Your handler is being eaten by the garbage collector. Make sure to declare
all relevant objects at class level, where they won't be garbage collected
and will remain in scope. You need a class level MailItem object that you
assign to that item and then you add the event handler to that class level
object.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Lukasz" lukaszmail[at]gmail[dot]com wrote in message
...
Hello,
I have a custom VSTO Addin with FormRegion. In that add_in I wan't to hook
to the events triggered when a user presses Reply or Forward buttons of
the inspector window running my FormRegion. To do this I do:

Private Sub ChoixProjetRegion_FormRegionShowing(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing

If TypeOf (Me.OutlookItem) Is Outlook.MailItem AND
Me.OutlookFormRegion.FormRegionMode =
Outlook.OlFormRegionMode.olFormRegionRead Then
AddHandler CType(Me.OutlookItem, Outlook.MailItem).Reply,
(AddressOf OutlookApplication_ItemReply)

End If

End Sub



Private Sub OutlookApplication_ItemReply(ByVal Item As Object, ByRef
Cancel As Boolean)
MsgBox("here")
End Sub

It works. I see My Message Box when I press Reply. The Problem Is that it
only works the first two times. ie, on the reply window I close it, and
press Reply again on the original window and I get my MsgBox again,
followed by the reply window. I close it again, and click on Reply thisr
time, but this time the Reply window comes on without the MsgBox.

If I keep closing the Reply window and pressing the Reply button again a
few times, eventually I'll get:

"COM object that has been separated from its underlying RCW cannot be
used."



Does anyone know what's going on?. Submitted using
http://www.outlookforums.com


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I print only event start times on a calendar? Jillsabub Outlook - Calandaring 1 February 2nd 10 04:05 PM
Explorer.SelectionChange event triggered multiple times Dorian Add-ins for Outlook 9 September 18th 08 06:07 PM
How reset all Calendar event times? Ken H Outlook - Calandaring 5 September 16th 08 03:33 PM
Print a calendar showing event times Adam H. Outlook - Calandaring 7 August 19th 08 10:16 PM
All-Day event times are glitched Jamie Outlook - Calandaring 1 April 1st 07 05:52 AM


All times are GMT +1. The time now is 12:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.