Click here to Skip to main content
6,821,293 members and growing! (18,908 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate License: The Code Project Open License (CPOL)

Outlook Plug-in using COM Shim (C#)

By Gigy

Outlook Plug-in using COM Shim wizard
C#1.0, Windows, .NET1.1VS.NET2003, Dev
Posted:27 Dec 2006
Views:23,725
Bookmarked:12 times
Unedited contribution
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 1.61 Rating: 2.07 out of 5
3 votes, 50.0%
1

2
1 vote, 16.7%
3

4
2 votes, 33.3%
5

Sample Image - Outlook_Pulgin.jpg

Introduction

This is a plug-in created for Outlook 2003 using C# and COM Shim wizard . This COM Shim wizard will come only when you install COMShimWizardSetup.msi, which can be downloaded from the Microsoft site. After installation you will get this wizard under Visual C++ Projects. This wizard is used to create a pure COM DLL. This is initiated by some similar project from code project. But I don't have that link at this moment to add the reference.

Background

I started creating the Outlook plug-in VC++ using the Shared - Addin wizard in VS 2003. The plug-in was working quite fine in all machines without much extra effort. Since the plug-in DLL created in VC++ was just a COM DLL and will get integrated with the Outlook application very easliy (I just closed my eyes for the programming effort ;) ). Once I started migrating the code from VC++ to C# for enhancing the plug-in issues arose.

  • The application started behaving differently in different machines
  • Most of the time it showed "plugin could not loading at the start up" and some Mscoree.dll
  • Or loaded half the plug-in and started behaving inconsistently

Using the Code

Almost all the code will be added by the wizards except your customization code. There are detailed explanation in Microsoft site about how to use Shared Add in and the Shim Wizard . The picture given below is taken from Microsoft site which tells about the use of Shim dll

The plug-in created using C# is called managed dll or rather managed assembly. When this has to load with some application, the CLR ( mscoree.dll) will do the proper conversion of this MSIL code to machine code . This works quite fine if all the security policies has followed as per Dot Net convention .

Deploying and installing a managed COM add-in securely in Microsoft� Office XP currently requires the assembly be hosted in an unmanaged COM add-in proxy component called a shim.

The shim is a Visual C++ Active Template Library (ATL) COM DLL. It exposes a COM-creatable class that acts as a proxy to the real managed extension class. The COM Shim Wizard registers the CLSID and ProgId for this class in the registry. In the case of COM add-ins and smart tags, the wizard also registers this class against all the target Office applications you choose. When the host Office application starts, it checks the registry to see which add-ins and smart tags to load, and then uses standard COM object creation to instantiate the registered proxy class. This action loads the COM shim DLL that is registered to proxy one of the add-ins or smart tags.

Strong Name

I moved the created snk file to the project parent folder and modified the AssemblyInfo.cs in the following manner:

[assembly: AssemblyKeyFile("..\\..\\CodeProjectTest.snk")]

Points of Interest

Only thing need to be take care is, we use the proper References. Here we need to use the interop assemblies. Component Object Model (COM) interop assemblies allow unmanaged (COM) code to be called from managed (.NET) code by using the Microsoft .NET Framework and the common language runtime. COM interop assemblies allow managed applications to bind to unmanaged types at compile time and provide information to the common language runtime about how the unmanaged types should be marshaled at run time.

It is important for security reasons to never fail to include the public key token in the ShimConfig.cpp file. This will get added by default through Shim wizard, if you have followes the proper steps

History

First Draft: 27 December 2006

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Gigy


Member
Gigy is a Software professional from India, now living in United States of America. He is having over 9 years of experience in various phases of software development. Worked in the capacity of Project Leader, Senior Software Engineer, Senior Programmer and Programmer in the development and maintenance of applications & products related to Online Banking, Insurance Brokerage, Image Processing, Healthcare Domain, Simulation, Graphics, Automation, Add - Ins and Porting.

He has worked in versatile technolgies viz. C, C++, MFC, Visual C++, COM, DCOM, ATL, Windows Services and Visual Studio IDE. Currently working in .Net Technologies - AJAX, C#, Visual Basic.NET, Managed C++, ASP.NET, SOAP, XML, DTD, XSL, Web Services and Visual Studio. NET 2005, 2008 IDEs.

He is presently working with NCR in Internet Banking Technologies. He has also worked with world reputed companies like Accenture, General Electric and Mphasis.

He is now focusing in WPF, Silverlight, WCF, Azure, MMC and Velocity Technologies

www.code.gigyonline.com
Occupation: Software Developer (Senior)
Company: NCR
Location: United States United States

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
GeneralMy vote of 1 Pinmemberrobinbobin124:08 2 Dec '08  
GeneralHow to remove the Add-in and the menu item that was added in Outlook? Pinmemberbarts00712:52 22 Nov '08  
Generalsnk file Pinmembermamtayg18:39 14 Sep '08  
QuestionHow to add the Plugin to the mail message window Pinmembereran3610:46 24 Jul '07  
GeneralHow to strongly name the COM Shim dll? Pinmembersingpura00121:58 28 Jun '07  
GeneralRe: How to strongly name the COM Shim dll? PinmemberGigy4:47 29 Jun '07  
GeneralRe: How to strongly name the COM Shim dll? Pinmembersingpura0015:22 30 Jun '07  
GeneralRe: How to strongly name the COM Shim dll? PinmemberGigy16:53 30 Jun '07  
GeneralRe: How to strongly name the COM Shim dll? Pinmemberchaizzilla13:20 25 Sep '08  
GeneralAbout Outlook Plugin's PinmemberPreeteesh Kakkar23:51 14 Mar '07  
GeneralRe: About Outlook Plugin's PinmemberGigy16:39 30 Jun '07  
Jokewrong image path Pinmemberchris_do2:13 27 Dec '06  
GeneralRe: wrong image path PinmemberGigy17:57 27 Dec '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 27 Dec 2006
Editor:
Copyright 2006 by Gigy
Everything else Copyright © CodeProject, 1999-2010
Web09 | Advertise on the Code Project