Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / May 2008

Tip: Looking for answers? Try searching our database.

Problem migrating addin from 2003 to 2007

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Rizzo - 12 May 2008 15:28 GMT
Hello,

I am trying to migrate an application thatwas written for Outlook 2003 to
work with 2007.  I am having a particularly difficult time with an issue
documented here: http://support.microsoft.com/kb/929593 .  The issue is that
Item.Close can no longer be called from the Inspector.Close event.  In the
2003 version of my program, the code catches the Item.Close event, asks the
user if they wanted to save their changes and then 'does some stuff' if they
say yes, 'does some other stuff' if they say No, and does something
completely different if they cancel.  When the function is done,
Item.Close(olDiscard) is called because my application had already handled
the save (if necessary).  If I didn't do it this way, the user would get two
"do you want to save" prompts: one from me, and one from Outlook.  Now, in
Outlook 2007, it appears that I can no longer call Item.Close from the
Item.Close event.  Unfortunately, if I skip this call, the item seems to
somehow get 'stuck' in Outlook, and when the application is closed, Outlook
asks if I want to save changes for an item that is no longer visible & should
have been closed already.  

Is there another way to accomplish what I am trying to do?  In other words,
I need to replace the Item.Close event with my own code which asks the user
if they want to save, and bypasses Outlook's prompt for the same.  

Thank you,

Jon Rizzo
Langan Engineering & Environmental Services
Ken Slovak - [MVP - Outlook] - 12 May 2008 15:58 GMT
Outlook 2003 SP3 also implements the same restriction.

Set up a timer to fire shortly after the event handler ends and call Close
in the timer elapsed event handler.

Signature

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

> Hello,
>
[quoted text clipped - 31 lines]
> Jon Rizzo
> Langan Engineering & Environmental Services
Jon Rizzo - 12 May 2008 21:14 GMT
Thank you for the suggestion.  I moved the 'close' call to a timer event, so
it now saves and closes properly.  Unfortunately, when Outlook exits, it
(Outlook) still asks "Do you want to save changes".  There aren't any open
inspectors, so I can't explain why this message is appearing.  

> Outlook 2003 SP3 also implements the same restriction.
>
[quoted text clipped - 36 lines]
> > Jon Rizzo
> > Langan Engineering & Environmental Services
Ken Slovak - [MVP - Outlook] - 12 May 2008 21:52 GMT
Sounds like something wasn't released. Did you call Marshal.ReleaseComObject
on the Inspector related objects and wait for the garbage collector to
finalize?

Signature

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

> Thank you for the suggestion.  I moved the 'close' call to a timer event,
> so
> it now saves and closes properly.  Unfortunately, when Outlook exits, it
> (Outlook) still asks "Do you want to save changes".  There aren't any open
> inspectors, so I can't explain why this message is appearing.
Jon Rizzo - 13 May 2008 14:05 GMT
I am releasing both the item and the inspector in a loop to ensure that all
references are released:
   Do
       refsLeft =
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
   Loop While (refsLeft > 0)

> Sounds like something wasn't released. Did you call Marshal.ReleaseComObject
> on the Inspector related objects and wait for the garbage collector to
[quoted text clipped - 5 lines]
> > (Outlook) still asks "Do you want to save changes".  There aren't any open
> > inspectors, so I can't explain why this message is appearing.
Ken Slovak - [MVP - Outlook] - 13 May 2008 14:15 GMT
That save message would only appear if there are still live references
somewhere to your objects.

Signature

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

> I am releasing both the item and the inspector in a loop to ensure that
> all
[quoted text clipped - 3 lines]
> System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
>    Loop While (refsLeft > 0)
Jon Rizzo - 14 May 2008 14:12 GMT
I am really stumped on this one.  My problem seems to stem from the fact
that my code is not explicitly creating any new com objects (only grabbing
objects opened by the user), so I'm not sure which pointers need to be
released.  I never received this message in Outlook 2003.  I have isolated
the problem down to a fairly simple buildable example.  I know that it is a
lot to ask, but would you mind taking a look at the sample to see if you can
tell what's I'm missing?  All you need to do to demonstrate the problem is
build the program, run outlook, open a contact, close the contact (without
saving) and then close outlook.

Jon

> That save message would only appear if there are still live references
> somewhere to your objects.
[quoted text clipped - 6 lines]
> > System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
> >    Loop While (refsLeft > 0)
Ken Slovak - [MVP - Outlook] - 14 May 2008 14:38 GMT
Is that code too long to post here? If so send me a copy, but I can't
promise when I'll get a chance to review it, my time is pretty booked up.

Signature

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

> I am really stumped on this one.  My problem seems to stem from the fact
> that my code is not explicitly creating any new com objects (only grabbing
[quoted text clipped - 9 lines]
>
> Jon
Jon Rizzo - 14 May 2008 15:47 GMT
Thanks, ken.  It's not terribly long, but it contains 2 classes, so it might
be a bit confusing to post here.  I emailed it to your mvps.org email
address.  Thank you!!

Jon

> Is that code too long to post here? If so send me a copy, but I can't
> promise when I'll get a chance to review it, my time is pretty booked up.
[quoted text clipped - 12 lines]
> >
> > Jon
-mhd - 13 May 2008 17:59 GMT
>I am releasing both the item and the inspector in a loop to ensure that all
>references are released:
>    Do
>        refsLeft =
>System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
>    Loop While (refsLeft > 0)

I hope you have a safety valve such as a counter set to some
comfortably big number for example, so that the loop doesn't get stuck
in perpetuity. Maybe even every 5 loops do a DoEvents.

-mhd

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.