Releasing COM objects

Add-in Express™ Support Service
That's what is more important than anything else

Releasing COM objects
Releasing COM objects - 4 quick questions 
Mike M.




Posts: 31
Joined: 2006-11-13
I am developing an Outlook Addin using Add-in Express 2007 for .NET. I am using Outlook 2003.

1) If the ADX add-in executes in its own appdomain then I can safely release COM objects without disturbing other add-ins and other add-ins cannot disturb my add-in. So does an ADX add-in execute in its own AppDomain? If it depends on whether the ADX loader is being used, how do I know if I am using the ADX loader?

2) Should I release the view object in the following scenario?

I have a method called by a before folder switch event handler which looks like this:

{
if (explorer == null) return;
View view = null;
try
{
view = (View)explorer.CurrentView;
if(view != null)
// do stuff with view.
}
finally
{
if (view != null) Marshal.ReleaseComObject(view);
}
}

Should the view be released ? ie. is the view RCW object created when I retrieve the current view, and thus I shuld release it before leaving the method, or is the object used again the next time the event is handled ?

3) Interpreting COM exception error codes. How does one generally interpret error codes reported in COM exception. For instance, if i get this errorcode -2044706811 in a COM exception with the message "The operation failed.", is there then anywhay or anywhere I can look up what the error code describes - besides from the very generic message "The operation failed" which does not help my to know what the reason for the error is?

4) How can I read the refcounts on Runtime Callable Wrappers for COM objects?

/Mike
Posted 11 May, 2007 02:12:41 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Mike.

1. You should have the Loader subdirectory into the project location.
2. Yes, the view object must be released in the 'finally' block.
3. In this case the "The operation failed." is the full description for the error. You can also search for more detailed information in the MSDN help.
4. The Marshal.ReleaseComObject method returns the counter. Please read the MSDN help to learn more about the Marshal class.


P.S. Note that we take up your forum requests in the order we receive them. Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.
Posted 11 May, 2007 10:07:41 Top
Mike M.




Posts: 31
Joined: 2006-11-13
Hi again

I just want to clarify your answer to 1): Is an ADX add-in executed in its own AppDomain ?

/Mike
Posted 12 May, 2007 03:02:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Yes, the add-in is loaded in a separate app domain if you use adxloader.
Posted 14 May, 2007 09:50:29 Top