Problem migrating addin from 2003 to 2007

J

Jon Rizzo

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 
J

Jon Rizzo

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.
 
K

Ken Slovak - [MVP - Outlook]

Sounds like something wasn't released. Did you call Marshal.ReleaseComObject
on the Inspector related objects and wait for the garbage collector to
finalize?
 
J

Jon Rizzo

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)
 
K

Ken Slovak - [MVP - Outlook]

That save message would only appear if there are still live references
somewhere to your objects.
 
M

-mhd

Jon Rizzo said:
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
 
J

Jon Rizzo

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 
J

Jon Rizzo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top