Welcome to MSDN Blogs Sign in | Join | Help

Misha Shneerson

VSTO internals and the little things about CLR, COM, Visual Studio and more ...
COM shim wizard for Visual Studio 2005

Finally! It took an eternity to get this thing published, but now you can go to MSDN and download COM shim wizard that work with Visual Studio 2005. Original COM shim wizard only worked with Visual Studio 2003 and so many people have requested an upgrade.

For those unfamiliar with the shims here is a short summary: if you are a C# or VB.NET developer writing a COM AddIn for Word, Excel, PowerPoint you want to isolate your AddIn from other managed components that are executing in the process. Here are some of the reasons for doing that. In other words you want to have your AddIn to run in the comfort of its own AppDomain. In the absence of proper VSTO support in this area, you would need to write your own unmanaged loader - yes, this is C++! The wizard can help you out here. After download and installing the COM shim wizard you will be able to create your own native loader in under 2 minutes. The best part - knowledge of C++ is optional.

Go to the background article or skip directly to the download.

Update Dec. 07 2007 : The very last and the best version of the com shim wizard is published here . It has a very nice advantage over previous versions because it uses COM aggregation technique (as opposed to COM containment) to execute the calls. This makes it completely unnecessary to duplicate interfaces on the native proxy class when you add those to the managed class. It also solves the ribbon callbacks issue (see Dmitrii's comments to the post).

 

Posted: Friday, June 09, 2006 3:20 PM by Misha Shneerson

Comments

Shamil Salakhetdinov said:

Hello Misha --

I did try COM Shim Wizard (http://www.microsoft.com/downloads/details.aspx?FamilyId=300A6CDB-84DD-4C62-B3BD-E79194D83494&displaylang=en) with VS2005 Prof + MS Access 2003 and it didn't run well enough to have my managed add-in loaded and activated.

This dirty hack in CLRLoader.cpp helped to make it working:

   // If S_FALSE is returned, it means the CLR has already been loaded

   if (hr == S_FALSE)

   {

       //+SS

       //return hr;

       return m_pHost->Start();

      //-SS

   }

Please comment on this issue/bug/feature...

Thank you.

Shamil

# October 23, 2006 6:41 AM

Misha Shneerson said:

Interesting ...

I have never tried this on Access, so this will need some more investigation (which I can not do right now :()

I would assume that something else calls CorBindToRuntimeEx but does not start the CLR.

# October 23, 2006 12:35 PM

Russell Proctor said:

Hi Misha,

I am writing an Excel COM add-in in Visual Studio 2005 targeting Office 2002 and Office 2003.

The download page gives the impression it will only work for Office 2007.

Would it be possible to confirm if this COM Shim will work when building COM add-ins for earlier versions of Office.

many thanks

Russell

# October 24, 2006 6:45 AM

Misha Shneerson said:

The shim itself does not rely on any particular version of Office be installed. So, yes, it should work with previous versions as well.

# October 25, 2006 2:27 AM

Russell Proctor said:

Hi Misha,

I have downloaded the COM shim for Visual Studio 2005 but there are no instructions telling me what to do next.

Would it be possible to point me in the right direction.

many thanks

Russell

# November 1, 2006 6:51 AM

Misha Shneerson said:

Looks like the link to the article (which contains all the instructions) did get broken. So this was the opportunity to fix it!

And here is the link in the cleart text:

http://msdn.microsoft.com/library/?url=/library/en-us/odc_vsto2005_ta/html/Office2003ShimWizard2.asp

# November 1, 2006 12:20 PM

Russell Proctor said:

Thank you for the link.

I am using Visual Studio Tools for Office 2005 and there is no C++ Projects in this version.

Does this COM Shim work with this version ?

many thanks

# November 2, 2006 5:21 AM

Misha Shneerson said:

Sorry, COM shim is a native C++ project. The wizard just helps creating it for you, but you need the corresponding part of VS to be installed in order to compile it.

# November 2, 2006 2:11 PM

Russell Proctor said:

Thanks,

Is there a way to create a COM Shim for an add-in written using Visual Studio Tools for Office 2005.

# November 2, 2006 3:09 PM

Misha Shneerson said:

Shims are for shared add-ins only and you do not need to create a shim for VSTO addins. VSTO runtime does take care of the appdomain isolation for you when it is loading the add-in.

# November 2, 2006 5:04 PM

Russell Proctor said:

If I create a Shared Add-in (using the IDExtensibility3 interface) that can be used with Office XP and Office  2003 using Visual Studio Tools for Office 2005 do I need to Shim it ?

Sorry for the confusion

# November 3, 2006 5:03 AM

Glen Harrison said:

Does Microsoft Plan to create VSTO addins for other Office Applications such as InfoPath, Project, or Visio? I am currently using the managed COM addin in VS 2005 approach to developing a MS Project addin. I think it would be nice to have this technology (VSTO) for all applications no just a few.

# November 28, 2006 12:56 PM

Misha Shneerson said:

VSTO2005SE supports add-ins for 6 Office apps - Excel, Word, Outlook, PPT, InfoPath and Visio.

Unfortunately MS Project is not supported by available versions of VSTO. We are hoping we will be able to support MS Project as well but I can not commit to this. But as Eric Lippert has mentioned (http://blogs.msdn.com/ericlippert/archive/2003/10/28/53298.aspx) it takes a lot of Microsoft employees to change a bulb. Meanwhile you can just use the COM shim wizards to generate the shim for your project.

# November 28, 2006 6:21 PM

Michell Cronberg said:

# December 4, 2006 9:51 AM

Glen Harrison said:

How do we create a installation/Setup for the newly created Shim with our project? I'm not sure how to deploy it.

# December 5, 2006 11:04 AM

Patrick Schmid said:

So how do I use the COM shim wizard for an Office 2007 add-in?

The shim doesn't implement IRibbonExtensibility and an Office 2007 add-in that wants to customize the Ribbon, needs to implement that interface. The result of using the current wizard is that my add-in crashes at runtime (I wonder why...maybe because my add-in implements IRibbonExtensibility but the shim doesn't?)

When will the wizard be updated? Or should I just forget about COM shims for Office 2007 add-ins?

Thanks,

Patrick Schmid

# December 11, 2006 6:14 AM

Donal Lafferty said:

Hi Misha,

Your blog has some very good details, and I would like to view the material referenced in the background article.  Unfortunately, it is broken.  Can you suggest an alternative location?

DL

# December 22, 2006 3:39 AM

Steven Payne said:

Hi Misha,

Thanks for the updated COM addin shim wizard -- we've been working around this for some time, and we're very glad to have the new version!

We've been experimenting with loading our own .config files into the AppDomain that the shim creates for our solution, so that we can take advantage of the ability to define app-level properties.  We've done this by modifying the C++ code that the wizard generates, in order to set the ConfigurationFile property on the DomainSetup object.  This is tedious for each project, and we would prefer to have this extra code defined in the template that the wizard uses to create the project.  I modified the source in the VCWizards\COMShims\AddinShim\Templates\1033 folder, but the wizard seems to be drawing from a different location.  Can you fill me in?  Or better yet, is this a change you folks can make and support in the released version of the wizard?  We've been setting .ConfigurationFile to the name of the managed assembly filename, plus the .config extension -- that way the VS.NET project can manage that file natively.

Thanks much...Steve

# February 19, 2007 3:45 PM

Andrew Whitechapel said:

Hi Steve

I talked with Misha about the issue of editing the template files. One thing to check is whether or not you're editing the correct copy. When you install the COM Shim Wizards, the installer lays the template files down in a known location, typically %programfiles%Microsoft\COM Shim Wizards 2.0.0.0. This is because at this time, the installer doesn't know where VS is installed. After laying down the files, a custom action runs, and this custom action figures out where VS is installed and then copies the templates to the expected location under %programfiles%Microsoft Visual Studio\.

VS finds these templates in this location - it never uses the "temporary" copies that were first installed.

On another note, we're finishing off a new version of the shim wizards - the main difference is that the new version supports the new extensibility interfaces. I'll be posting details on my blog very soon.

http://blogs.msdn.com/andreww/default.aspx

Andrew

# February 19, 2007 5:13 PM

Steven Payne said:

Thanks Andrew (and Misha) -- I located the files in the "correct" location, and once I added my customized code to that location then my new projects contain the modified code as expected.

I'd still like to hear comments about the use of .config files with assemblies loaded by the addin shim, and whether this could be added to the upcoming release (or future releases).  VSTO projects support this capability, however we're not moving to VSTO at this time for other technical reasons.  Configuration files in .NET afford many great capabilities for debugging and runtime application configuration, and I'd much rather see a supported method rather than the workarounds we're currently using.

Thanks much -- Steve

# February 20, 2007 12:54 AM

Misha Shneerson said:

Sure, Andrew has added the .config support. The appdomain will load the config file from <shimdirectory>\<assemblyname>.dll.config

# February 23, 2007 2:39 AM

John Smart said:

We have a lot of the older CAPI .wll code for WORD2002. We see WORD2007 mentions

a .wll add-in.  Is the CAPI lib approach obsolete, or is VSTO the new way? We are C/C++ coders.

Any advice on direction and tools welcomed.

# March 3, 2007 10:42 AM

Misha Shneerson said:

John, I am not familiar with WLLs so I can not really comment on the "obsoleteness" aspect of it.

VSTO tools though are primarily for developing add-ins (which are a lot like COM add-ins) using managed code (C#/VB.NET). We (VSTO team) believe that it is the better way to go because you can take advantage of the rich functionality which is available as part of .NET Framework. So, I think, going forward the majority of investments are Office development would be around managed code, so you might want to start looking in this direction. Having C++ skills is always a plus though and can always come handy especially when you are developing hybrid solutions where managed code interoperates with native.

# March 3, 2007 6:39 PM

FeBo said:

OK, this is driving me crazy :)

I wrote simple Word Add-in that perfoms a simple task when a button is clicked. It compiled Ok, setup part also "works", but I can't get it into Word.

As I've read, shimming would help. Great:

The end result is .dll, and when I try to shim it I get an error "Error PRJ0019: A tool returned an error code from "Performing registration".

My steps:

a) I built my add-in

b) file->new project -> VC++ ->COMshims->Addin Shim -> OK, I pick DLL built in step A

c) next, (check) Word, next, finish (as in article)

d) build- and I get the error :-S

What could be wrong? VS2005, MSO2003 (and 2007), Vista.

# March 18, 2007 1:41 PM

Trent Foley said:

I just downloaded and installed version 2 of the COM Shim Wizard, and when I attempt to create a new Addin Shim project, I receive "Automation server can't create object" error dialog and the project is never created.  I am running VS 2005 SP1 on Vista Business.  Any clues?

# June 27, 2007 5:12 PM

Misha Shneerson said:

I believe I know what might be going on.

When installing the COM shim wizard you are asked whether to install for "Just me" or "Everyone". The default is "Just me". This default would work for all OSs including Vista unless you do run VS 2005 in elevated mode (which I assume you do since this is how VS 2005 is recommended to be used on Vista). The workaround is to ininstall the COM shim wizard and then install it for "Everyone".

# June 27, 2007 5:26 PM

Trent Foley said:

That did the trick!  Thanks for your reply.

# June 28, 2007 10:50 AM

Singapura said:

Hi Misha,

After installing the shim, I am gettin this error "Not loaded. A runtime error occurred during the loading of the COM Add-in".  The same installer works on couple of other machines (standard build w/o admin access). What could be reason for the failure of COM shim to load?

Is there a way I can debug the add-in and figure out the error?

Appreciate your response.

Thanks,

Singapura

# July 3, 2007 2:00 AM

Misha Shneerson said:

Singapura,

This might have either because your COM add-in is not registered correctly - in which case the shim will not be even loaded into the process, or, alternatively, if shim's OnConnection method fails.

Also, if you are running on Vista and the shim is installed the COM discover might fail if:

1. The shim was installed as "Just me"

2. The host process is running elevated OR UAC is turned off on the machine

Yes, debugging is possible. You will need to start host application under native debugger and put a breakpointer in the shim's code.

# July 3, 2007 2:46 AM

Adam said:

Hey there, so im going crazy trying to figure out what is going on...

My Managed add-in was working great, then i saw that the Com Shim was suggested. So i followed several suggestions here, and on MSDN, to get the SHIM up and running, so its all setup and its installing on my machine. Great! It runs much faster now.

Problem is, it doesnt seem to install correctly on any other machine but mine. The installer says completed but the add-in never loads. Its not in the Disabled Items menu and im not sure how to go about finding out whats going on?

Any help would be much appreciated!

# July 9, 2007 6:21 PM

Misha Shneerson said:

Adam, I can take a quick look at your MSI file and see if I can figure it out. Please use Email link at the right top corner of this page to contact me.

# July 10, 2007 2:20 AM

Adam said:

Ok, so i finally made some ground on whats going on, i made a basic addin and set it to be available for Word, Excel and Project. Then i compiled, tested, works. Now i followed the docs on making a shim with the wizard to a t, made it available for word, excel and project. Neither the add-in or the shim are signed just to get it working. Created the installer and installed, the AddIn works for word and excel but when it fires up in Project, nothing happens, and the LoadBehavior in the registry is set from 3 to 2. I know its not the AddIn code, is this a bug anyone else has run into?

My addin is only for Project and i would love to get it running but im getting no where.

# July 12, 2007 3:03 PM

Adam Behrle said:

Adam,

I've been running into this as well. Everything would work fine for my Shimmed addin for Project in Windows Server 2003, but wouldn't load in XP (LoadBehavior changed from 3 to 2).

I implemented Shamil Salakhetdinov's "hack" above, changing part of the LoadCLR function in CLRLoader.cpp to:

if (hr == S_FALSE)

{

      return m_pHost->Start();

      //return hr;

}

This seems to work in both environments for Project 2003. I still need to test it for Project 2007.

Misha, did you ever get a chance to investigate this?

Thanks,

Adam Behrle

QuantumPM

# August 14, 2007 12:34 PM

Biju Alapatt said:

Hi Misha

I 'm little confused about my Word 2003 Add-In deployment.  

1)   I Have created the Word 2003 Shared Add-in with a strong key and build it using C#.

2)   Run the COM Shim wizard 2.0 and selected Word only

3)   Finished the Shim Wizard and build the C++ Project.  I got "AddinShim1.dll" and "AddinShim1.tlb" in     the  Debug directory.

4)   On the default setup project that added with the Shared Add-in, I have added the "AddinShim1.dll" to "File System" and run 'Rebuild'.

After deploying to another Win XP machine, the Add-in is loading with Word.

Could you help me?

# September 2, 2007 10:54 AM

Andrew Whitechapel said:

The latest version of the COM shim wizards was released back in the summer, here . With the help of Adam

# November 25, 2007 7:43 PM

Noticias externas said:

The latest version of the COM shim wizards was released back in the summer, here . With the help of Adam

# November 25, 2007 8:04 PM

Dmitri Zouchinski said:

Hi Misha

My Excel COMAddIn has ribbon and creates custom task panels. I can add IRibbonExtensibility and ICustomTaskPaneConsumer to Connection Proxy object but ribbon callbacks is a real problem. COM Shim has to be updated with every new method added to COM AddIn.

I have created simple DLL project that loads mscoree.dll in DllMain and passes all calls to DllCanUnloadNow and DllGetClassObject to mscoree.dll. It seems to do the trick. All I do is sign my dll and replace mscoree.dll in InprocServer32 with full path to my dll.

Do you know if this way can cause any problems?

Thanks,

Dmitri Zouchinski

# December 6, 2007 11:27 AM

Misha Shneerson said:

Hello Dmitri,

I would not recommend doing this trick mainly because your add-in is loaded into default AppDomain and if more than one add-in is loaded there - they might start stepping on each other's toes.

The latest version of ShimWizard (http://msdn2.microsoft.com/en-us/library/bb508939.aspx) uses a little bit different technology for proxying - it is not even direct proxying but aggregation of interfaces exposed by the managed object. This makes the need to duplicate callbacks unnecessary. So, I suggest you to use this approach instead.

# December 7, 2007 5:14 PM

Kish said:

Hi Misha,

This is a great tool for isolation. i am working on an add-in for outlook 2003 and 2007 with c# (not VSTO), can i use this approach to add com shim project to my solution and release the project to production environment after testing cycle?

thanks

kish

# December 8, 2007 5:14 AM

Misha Shneerson said:

Hi Kish,

The article is out there so that other people could use it. So, the answer is yes, of course!

# December 8, 2007 2:58 PM

prasan83 said:

Hi Misha,

I just came across your blog while searching on COM-SHIM :), its very informative!!

We have used COM-SHIM version 2.3 in our Outlook Add-in which has been developed by using IDTExtensibility2.

We are facing issues related to the after integration with the COM-SHIM project.

Code Snippet:

Outlook.ApplicationClass _app = new Outlook.ApplicationClass();

Outlook.Application olApp = (Outlook.Application)_app;

Outlook.MAPIFolder root = Folder.GetRootFolder(olApp.Session);

string folderName = FedExFolderManager.FedExFolderName;

foreach (Outlook.MAPIFolder f in root.Folders)

{

   if (f.Name == folderName)

   {

      f.Delete();

      break;

   }

}

olApp = null;

root = null;

*****************

//For example, this code was running fine before integration, but now it gives a null exception at (Outlook.MAPIFolder f in root.Folders)

We are trying to meet deadline on fixing this issue here, any help on this COM-SHIM integration will be highly appreciated.

Have a great day :)

-Prasanjit

# December 8, 2007 4:51 PM

dzouch said:

Misha

Thank you for the advice.

I have tried latest COM Shim Wizard and it works. Ribbon callbacks are now functional.

I know I am whingeing but as I use Custom Task Pane I need .Net controls to be created from ProgId. Wizard only create proxy for COM AddIn. What are the consequences of leaving other controls from the same assembly in hands of mscoree.dll?

Dmitri Zouchinski

# December 13, 2007 8:39 AM

Misha Shneerson said:

Hello Dmitri,

You will need to regasm your UserControl that will go into the Custom Task Pane. If you are OK with the registry impact of regasming - then it is fine - the control will be instantiated in the calling AppDomain. Alternatively you can use VSTO add-ins support which provides a registry-free way of instantiating controls for the Custom Task Pane.

# December 13, 2007 12:15 PM

jayg89 said:

I love the 2.3 COM Shim wizard and have used in successfully in an Access 2007 application. I am having trouble installing the wizard in the Visual Studio 2008 environment. Is it compatible with VS 2008?

Thanks!

Jay

# December 20, 2007 5:10 PM

Misha Shneerson said:

Jay,

I did quick tests on VS 2008 and they do seem to work. However, our setup would not automatically install classes for VS 2008.

Below are some manual steps you can do to set up wizards for VS 2008

On a machine with Visual Studio 2008 (notice that if you are working on Vista - the setup might fail. If this is happening - please let me know and I can provide working setup)

1. Install Com Shim wizards

2. Open explorer and navigate to %programfiles%\Microsoft\COM Shim Wizards v2.3.0.0

3. From VCWizards directory: copy ComShims folder into %programfiles%\Microsoft Visual Studio 9.0\VC\VCWizards  folder

4. Go back to %programfiles%\Microsoft\COM Shim Wizards v2.3.0.0

5. From vc\vcprojects: copy ComShims into %ProgramFiles%\Microsoft Visual Studio 9.0\VC\vcprojects

6. Now, go into %ProgramFiles%\Microsoft Visual Studio 9.0\VC\vcprojects\ComShims folder - you will see a bunch of vsz files.

  Open each and everyone of those files in an editor and replace:

Wizard=VsWizard.VsWizardEngine.8.0 ----> Wizard=VsWizard.VsWizardEngine.9.0

6. Start VS 2008 and you should be able to see and use the wizards now.

# April 3, 2008 4:00 PM

Alistair Thompson said:

I have created an Addin for Outlook2007 that adds a button to the ribbon for a mail message that is being read. This worked fine but after creating the shim with v2.3 of the wizard Outlook crashes.  Outlook starts OK but it is when I click on a message to read that it then crashes.  I have tried to attach the debugger but I can't get that to work so it is hard to know how to track down the problem.  

Any ideas what is going wrong or how to debug it?

Alistair

# April 7, 2008 11:13 AM

Misha Shneerson said:

Alistair,

Did you try attaching native debugger to see what the problem is? let's take it offline - please use the email link to contact me directly.

# April 7, 2008 2:37 PM

Clark said:

Hi Misha

Very interesting article. It should solved my problem of conflict between my addin for outlook and mscrm outlook addin.

I work on vista and Visual Studio 2008, but the com shim wizard failed to install. Can you provide me working setup?

Thanks

# June 6, 2008 5:20 AM

Clark said:

Ok, it works Misha!

I have follow this :

To install the COM Shim Wizard on Windows Vista

To run the entire install process as elevated, click Start, right-click the Command Prompt, and then select Run as administrator.

Run the COMShimWizardSetup.msi from the elevated command prompt.

Select the Install for all users option, which registers the wizards to the HKLM subkey, where Vista can find the entries.

# June 6, 2008 5:50 AM

ayon said:

Hi,

I have written a C# COM add-in Using VS 2008 .I have deployed it in XP with Outlook 2007. I have used COM SHIM . My question is , will it work on Windows Vista with Outlook 2007 and 2003?

# May 6, 2009 8:49 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker