MS Office Forum / Outlook / Programming Add-Ins / April 2004
Problem firing up NewInspector events
|
|
Thread rating:  |
jbhan - 23 Mar 2004 02:30 GMT Hi all,
I have a windows form which I want attached to each new Inspector window I open (I am using windows api to achieve that using the handle of each new Inspector window I open). I have implemented an Inspector wrapper to achieve this.
The problem is the NewInspector event fires very erratically. Sometimes when I open outlook it fires fine for upto 10/15 new inspector windows that I open and then sometimes it fires the first time and then it does not.
I used outlook spy and from there I could detect that the event is in fact firing each time but the event handler in my code works sometimes and sometimes it does not. Is there something which causes the new inspector event to stop firing, anyone has any ideas about what I am missing here? Btw I am using c# and .NET for this. Any help will be really appreciated!
Thanks, jbhan
Dmitry Streblechenko \(MVP\) - 23 Mar 2004 06:46 GMT Do you keep Application.Inspectors referenced at all time using a class member?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> Hi all, > [quoted text clipped - 18 lines] > Thanks, > jbhan jbhan - 23 Mar 2004 19:33 GMT Hi Dmitry,
Yes, I am. I have a static property in a class which stores the Inspectors and I have a corresponding event handler specified for the NewInspector event on that collection of Inspectors.
In the New Inspector event I am calling a function which which goes on to create my sticky window . The first time round when I install my addin and then run Outlook the new Inspector event handler is executed each time a new inspector window opens. But when I close Outlook and open it second time, the new inspector event handler is executed only for the first inspector window that I open and not subsequently.
Is it posssible that something in my code is causing the event handler to be disassociated with the event? What could cause and event handler to stop handling the event? I could post sections of my code if required.
Please any help or pointer would be great, I just can't imagine what could be causing the event handler to stop functioning!
Jbhan
>-----Original Message----- >Do you keep Application.Inspectors referenced at all time using a class [quoted text clipped - 29 lines] > >. Dmitry Streblechenko \(MVP\) - 23 Mar 2004 23:57 GMT When you close Outlook, before launching it for the second time, do you see outlook.exe in the Task Manager?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> Hi Dmitry, > [quoted text clipped - 67 lines] > > > >. jbhan - 24 Mar 2004 00:57 GMT No, I am making sure I do the clean up. So once I close the Outlook explorer I make sure there are no references to Outlook objects remaining in memory. Outlook.exe process is not left running once I close the explorer.
But I did notice one more thing, when I debug through my code exactly at the line where I specify the event handler for my Inspector object or MailItem object I get a System.ExecutionEngineException error in my addin dll and then the application hangs. This happens only in debug mode , if I run the application normally I see no errors.
I don't know what I am doing wrong, I thought creating the Inspector wrapper would solve a whole lot of problems but if I can't get a NewInspector event its not going to be of any use!
Any thoughts?
Thanks for your time!
jbhan
>-----Original Message----- >When you close Outlook, before launching it for the second time, do you see [quoted text clipped - 81 lines] > >. Dmitry Streblechenko \(MVP\) - 24 Mar 2004 01:33 GMT Hmmm... Hard to say, this is one of the reasons I am not using .Net for any kind of Outlook development... You do get a call to OnConnection both times, right?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> No, I am making sure I do the clean up. So once I close > the Outlook explorer I make sure there are no references [quoted text clipped - 117 lines] > > > >. jbhan - 24 Mar 2004 02:03 GMT Yes, OnConnection get called everytime.Its just that the New inspector event handler is getting called in an erratic fashion. What could cause the event handler to get disassociated from the event (since the event is getting fired correctly at all times)? Could it be something to do with creating a windows form from within outlook, process/threading issues affecting event handling in outlook? Any ideas? Appreciate your help!
jbhan
>-----Original Message----- >Hmmm... Hard to say, this is one of the reasons I am not using .Net for any [quoted text clipped - 129 lines] > >. Dmitry Streblechenko \(MVP\) - 24 Mar 2004 08:57 GMT I have no idea... What if you remove all the custom processing and just leave the code that sets up the event handler?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> Yes, OnConnection get called everytime.Its just that the > New inspector event handler is getting called in an [quoted text clipped - 169 lines] > > > >. jbhan - 24 Mar 2004 19:26 GMT Then it works. Something about creating the windows form in the event handler is causing problems and I can't quite figure out what.
>-----Original Message----- >I have no idea... What if you remove all the custom processing and just [quoted text clipped - 180 lines] > >. I just noticed for some reason, the addin is unloaded when I restart outlook. Thats why event handler is not getting fired! Whats causing outlook to unload the addin?
>-----Original Message----- >Then it works. Something about creating the windows form [quoted text clipped - 218 lines] >> >. Dmitry Streblechenko \(MVP\) - 25 Mar 2004 01:52 GMT Does your addin raise any errors?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> I just noticed for some reason, the addin is unloaded > when I restart outlook. Thats why event handler is not [quoted text clipped - 234 lines] > >> > >. jbhan - 27 Mar 2004 00:21 GMT Hi Dmitry..Thank you so much for your patience and time in helping out here! I did have an error while loading the addin, that is fixed now but the inspector event is still giving the same problems. For a moment I thought I had figured out the issue here! :( As workaround have implemented a timer which checks the Inspectors collection for any new Inspectors. Not the best of solutions but it seems to be working so far.
I have another question though if you don't mind me asking in the same thread!
Based on certain conditions I want to cancel the mail item send event and instead move my mail to a folder that I have created ..a sort of pseudo Outbox for my custom processing. I can cancel the event but the inspector window does not close, I tried calling the inspector as well as mail item close methods ( in the mailitem send event) but both give me errors.I am using Outlook 2003. Is there any way to achieve closing an inspector window after cancelling the send event?
Thanks once again for your time! Really appreciate it!
jbhan
>-----Original Message----- >Does your addin raise any errors? [quoted text clipped - 244 lines] > >. Dmitry Streblechenko \(MVP\) - 29 Mar 2004 05:35 GMT Since you cannot close the inspector in the Send event, you could add add a custom property (using MailItem.UserProperties collection), then use a timer to check if that property is set on all messages open in the inspectors, remove the property, save the message, then close the inspector.
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool
> Hi Dmitry..Thank you so much for your patience and time > in helping out here! [quoted text clipped - 295 lines] > > > >. Chet - 19 Apr 2004 05:24 GMT Hi I have created an addin for outlook in VB6.0. Each time a new inspector is opened I check to see if it is a mailitem and if so I add a command bar and button to the inspector window. The button works fine until another inspector window is opened and then it stops working and will only work for the new inspector window. I know this happens becuase when the NewInspector event fires I set the command bar button to the new inspector and therefore will only work for the newest one opened. How do I get it to still work for all the other inspectors that are already opened.
Private Sub ins_NewInspector(ByVal inspector As Outlook.inspector)
Dim cb As CommandBar
On Error Resume Next If TypeName(inspector.CurrentItem) = "MailItem" Then If Not inspector.IsWordMail Then Set cb = inspector.CommandBars("FilePro Bar") If cb Is Nothing Then Set cb = inspector.CommandBars.Add("FilePro Bar", msoBarTop, , True) Set cbAttachDoc = cb.Controls.Add(1, , , , True) With cbAttachDoc .Caption = "&Attach document" .FaceId = 271 .Style = msoButtonIconAndCaption .ToolTipText = "Attach document from FilePro" End With End If cb.Visible = True End If End If End Sub
Ken Slovak - [MVP - Outlook] - 19 Apr 2004 16:19 GMT You need to use an Inspector wrapper and declare your buttons in the wrapper class using a unique Tag property for each button so each fires an individual and unique Click event handler. This is a similar concept to the Explorer wrapper class and collection used in the ItemsCB COM addin sample (VB 6) on the Resources page at www.microeye.com
I use code something like the following. This example only shows a MailItem declared WithEvents, to handle other item types you'd add additional declarations. In the code that adds the class to the wrapper collection you would check for the type of the item in the new Inspector (Inspector.CurrentItem) and add or not add the class based on that, depending if you wanted to handle the events for that item type.
The following code is a skeleton for an Inspector class module, that gets put into a collection when NewInspector fires and is removed from the collection when the Inspector is closed. Handling the collection is similar to how it's done in the Explorer wrapper code in ItemsCB.
VB 6 code:
Private WithEvents m_objInsp As Outlook.Inspector Private WithEvents m_objMail As Outlook.MailItem
Private m_lngID As Long
Private Sub Class_Initialize() On Error Resume Next
Set m_objInsp = Nothing Set m_objMail = Nothing End Sub
Private Sub Class_Terminate() On Error Resume Next
Set m_objInsp = Nothing Set m_objMail = Nothing End Sub
Public Property Let Inspector(objInspector As Outlook.Inspector) On Error Resume Next
Set m_objInsp = objInspector Set m_objMail = objInspector.CurrentItem End Property
Public Property Get Inspector() As Outlook.Inspector On Error Resume Next
Set Inspector = m_objInsp End Property
Public Property Let Key(lngID As Long) On Error Resume Next
m_lngID = lngID End Property
Public Property Get Key() As Long On Error Resume Next
Key = m_lngID End Property
'********************************************************************* 'Event Procedure: m_objInsp_Close() 'Destroy Inspector object in InspWrap '********************************************************************* Private Sub m_objInsp_Close() On Error Resume Next
basOutlInsp.KillInsp m_lngID, Me Set m_objInsp = Nothing
If Err <> 0 Then AddInErr Err, "clsInspWrap", "m_objInsp_Close" End If End Sub
You can now add button creation to this code, remembering to use a unique Tag property for each button in each Inspector.
 Signature Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm
> Hi I have created an addin for outlook in VB6.0. Each time a new inspector > is opened I check to see if it is a mailitem and if so I add a command bar [quoted text clipped - 28 lines] > End If > End Sub
|
|
|