Special Edition Using Microsoft Office Outlook 2003
Another option you can take advantage of when developing with Outlook is to create a COM add-in. A COM add-in is a program that actually runs in process with Outlook. It loads when Outlook loads, and terminates when Outlook terminates. A COM add-in enables you to manipulate toolbars, menus, and even add additional property pages to the Tools, Options dialog box present in Outlook.
NOTE When developing a COM add-in, it can sometimes be tempting to instantiate your own Outlook application object. If you do so, any objects derived from that nondefault Outlook application object will trigger the object model guard. Only code that accesses objects derived from the default application object will be trusted.
You can create COM add-ins for Outlook using Visual Basic or the Microsoft Office Developer tools. Using Visual Basic or Visual Basic .NET is the most common method of COM add-in development. There are two main steps in developing your COM add-in. You must implement the IDTExtensibility2 interface within a class module of a DLL (dynamic link library), and then register that DLL as a COM add-in. NOTE In-depth instructions for creating a COM add-in are beyond the scope of this book. You can find details about creating COM add-ins on the MSDN Web site. You can also find detailed information in other books, such as Building Applications with Outlook 2002, by Randy Byrne. Although this book was written for Outlook 2002, much of the information it contains applies to Outlook 2003.
A full primer on creating an Outlook COM add-in is beyond the scope of this book. However, there are a few key concepts and issues to remember when developing a COM add-in. First, consider downloading a template to use in Visual Basic to help you get started. The best COM add-in template available can be found at Microeye's Web site: www.microeye.com. You can also write COM add-ins using the developer's version of Microsoft Office. That version usually ships with a sample COM add-in template for use with Office 2003 Developer. Using a template won't write your COM add-in for you. However, it will start you off on the right foot by providing the add-in designer as well as an already-created OutAddin class module. There are also plenty of comments along the way to help you work with your COM add-in. Another key point to remember is that COM add-in objects are trusted only when they're derived from the built-in application object. If you try to create your own application object or need to use CDO, you'll encounter the security prompts caused by the object model guard. When designing COM add-ins, you can use the add-in to create a property page to add to Outlook's Tools, Options dialog box. When designing your property page, you must be careful that your controls don't extend beyond the default size of the property page (200x200 pixels). If they do, your controls will be cut off as the Options box isn't resizable. COM add-ins can be very tricky to design. Because they load and run in-process with Outlook, they can often crash Outlook if errors aren't handled properly. One of the first pieces of code you should add to any procedure in your COM add-in is an error-handling routine. At the very least, add the following line of code to the beginning of your procedures: On Error GoTo ErrHandler At the end of each procedure, insert code similar to the following: ErrHandler: If Err.Number <> 0 then 'Do Something 'Log the error in a text file or display a message box. 'Set all object variables to nothing End If One of the easiest ways to troubleshoot your COM add-in is to log the errors to a text file. That way you can see exactly where the error occurred and what the error was. This can be the fastest way to debug your COM add-ins. With Outlook 2003's inherent trust of all COM add-ins, writing an add-in can be one of the easiest ways to distribute an application that interacts with Outlook. |