Freigeben über


Part 3 – Back to the Basics, MSDN Must Reads

Matt Stehle used to be on my team prior and had blogged on the usage of Outlook Object Model (OOM) under .NET. However, his blog is being closed and I am re-blogging his content here.

The Outlook Developer Reference on MSDN has great information on .NET and COM interop which I would consider a prerequisite to any managed code development with Outlook Object Model.  It simply isn't enough to know how to accomplish tasks with OOM or to call GC.Collect here and there - it is important to understand the whole story... Introduction to Interoperability Between COM and .NET - This is a short and sweet run through of COM Interop and sets up a foundation for understanding where some of the issues come from in my previous posts (OOM.NET Part 1 & Part 2).  Be sure to pay attention to the following quote...

"...a COM client manages an internal reference count provided by IUnknown to free a coclass, a .NET client relies on the runtime garbage collector provided by the .NET platform to free an object..."

...That is why RelaseCOMObject is so important - in the Outlook world of item in reuse we cannot rely on the runtime garbage collector provided by the .NET platform to free an object.

There is also some 101 type information about what a PIA is found in Why Use the Outlook PIA - the take away from this is, "Any number of interop assemblies can exist to describe a given COM type. As publisher of the type library, Outlook provides a Primary Interop Assembly (PIA) that contains the official description of the COM-based Outlook object model."  Installing and Referencing the Outlook 2007 PIA takes the next step to show how to add the reference in Visual Studio.  The list of classes and interfaces in OOM as seen by VB6 or VBA differ greatly from what is seen in a .NET project - for an explanation of that phenomenon read, Relating the Outlook PIA with the Object Model.

The MSDN documentation hits on some of the points I made in Part 1 and Part 2 of OOM.NET:

Scoping Variables Appropriately in Event Handlers

Systematically Releasing Objects

Looking forward to Part 4 of OOM.NET...

A huge area of trouble is in the handling of events and how to structure code and understand the code in the PIA to prevent item leaks.  I'll be posting more information on this topic soon - in the meantime read the following two articles for some background information...

Connecting to Custom Event Handlers

Events in the Outlook PIA