Home arrow C++ arrow Page 3 - Building An Outlook COM Add-In With VC /ATL
C++

Building An Outlook COM Add-In With VC /ATL


One of the great things about Windows is the ability that we have to create COM-based add-in's for the entire suit of Office 2000 applications. In this article, Amit shows us how to create an Outlook 2000 COM add-in using a pure Visual C ATL COM object. He starts by writing a basic functional COM add-in, and then adds standard user interface elements such as toolbars and menu items to Outlook. He finishes up by showing us how to respond to their events.

Author Info:
By: Amit Dey
Rating: 5 stars5 stars5 stars5 stars5 stars / 65
February 17, 2002
TABLE OF CONTENTS:
  1. · Building An Outlook COM Add-In With VC /ATL
  2. · Getting started
  3. · Building a minimal COM add-in
  4. · Command and conquer
  5. · Command and conquer (contd.)
  6. · Lord of the (disp) sinks
  7. · Conclusion

print this article
SEARCH DEVARTICLES

Building An Outlook COM Add-In With VC /ATL - Building a minimal COM add-in
(Page 3 of 7 )

We now know enough to go ahead and code up a minimal Outlook 2000 COM add-in. To build the add-in project files, fire up the Visual C++ IDE, create a new ATL COM App Wizard project, and name it "OutlookAddin".

In the Appwizard Step 1 of 1 dialog that follows, accept the default Server Type, Dynamic Link Library(DLL). Enable the "Allow merging of proxy-stub code" option and click finish. Click OK to generate the project files.

Click on the Insert -> New ATL Object menu item and insert a new ATL simple object into our project by choosing objects from category, and simple object from the objects list in the ATL object wizard dialog. Click next and type addin as the value of short name. In the attributes tab, check the support IsupportErrorInfo check box. Accept the default options for all of the other options, and click OK.

So far the wizard has given us an automation-compatible, dispinterface-savvy in process COM object housed in a DLL. A registry script (.rgs) to add the COM object specific registry entries has also been created for us. Build the project and make sure everything is in order (at this point you may also like to compile your projects .idl file).

We will now write our add-in specific code to implement the IDTExtensibility2 interface.This is where we let the implement interface ATL wizard kick in and make our life a lot easier. In class view, right-click on the CAddin class and choose implement interface. This brings up the ATL implement interface wizard. Click on add typelib, and in the browse type libraries dialog scroll down and check microsoft add-in designer (1.0). Click OK. Next, check the _IDTExtensibility2 interface from the list under the add-in designer objects tab of the implement interface dialog and click OK.

The wizard implements the selected interface for us by adding a default implementation for each of the five methods of the _IDTExtensibility2 interface to the CAddin class, and also updates the COM_INTERFACE_MAP() block. Each of the methods just returns E_NOTIMPL of course, and it's up to us to add the code so that they do something useful. For now however, our COM add-in is ready, except the for the necessary registry entries, which we will add next.

To register our add-in with the host application (in our case Outlook 2000), open the project's addin.rgs registry script file (located under File View -> Resource Files) and add the following text to the end of the file:

HKCU

{

Software

{

Microsoft

{

Office

{

Outlook

{

Addins

{

'OutlookAddin.Addin'

{

val FriendlyName = s 'ADOutlook2K Addin'

val Description = s 'ATLCOM Outlook Addin'

val LoadBehavior = d '00000008'

val CommandLineSafe = d '00000000'

}

}

}

}

}

}

}


Since we want our add-in to load at startup, LoadBehavior is set to 3.Now build the project. If everything is in order, the project gets built successfully and registers the add-in. To test the add-in, either run the project and specify the full path to Outlook 2000 (c:\Program Files\Microsoft Office\Office\Outlook.exe) as the value for "executable for debug session", or run Outlook 2000 outside of the Visual C++ IDE after you have registered the DLL. To check if our add-in has been registered successfully in Outlook, go to Tools -> Options. Under the "Other" tab, click Advanced Options -> COM Add-ins. An entry for our COM add-in should have been added to the add-ins available list; the string displayed is the value that we specified as 'FriendlyName' in our registry script:

Our add-in as displayed in Outlook 2000

While an addin can be programmed for different uses, there are certain tasks that will be common to everyone. Typically, they include adding user-interface elements like toolbars/tool bands and menu items to Outlook, through which the user can control the add-in.By clicking on these buttons and menu items, the user can access the add-in's functionality. Let's tackle such toolbar and menu item additions now.
blog comments powered by Disqus
C++ ARTICLES

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials