Tuesday, February 24, 2009
Tuesday, January 20, 2009
Writing Outlook 2007 Addins using C#.Net (using a COM Shim)
Addins that are developed in .Net need something Microsoft are calling a “COM shim”, which basically receives OL2007’s COM requests and passes them to the .NET assembly and back again. Its because Office is still COM based, so treats the core .Net DLL (mscoree.dll) as one single COM object. The COM is written in C++ (although I’m unsure whether this would be managed C++ - if it is, surely its still .NET thus defeating the purpose), but can still be added into the .Net solution for the addin, since we can mix projects in different CLR languages in the same solution.
To a .NET developer, native C++ with COM looks like a foreign language. Thankfully, some employees at Microsoft recognized this and Microsoft provides an unsupported wizard to create a COM shim, the COM Shim Wizard. This allows you to auto-generate (mostly) the required shim for the addin by passing it the .Net Addin assembly that you wish to “wrap”.
How to actually use the COM Shim
- Run the COM shim wizard for your add-in
- Verify that the COM shim is working:
- Add e.g. a MessageBox to your OnConncetion method in your .NET Connect class. If the MessageBox fires, then you know that your .NET add-in is being loaded correctly. Keep in mind that any Ribbon modifications will not be displayed at this point in time.
- Open the Add-Ins dialog (e.g. Outlook Options, Add-Ins). Your add-in name has to be listed with the DLL of the Shim. If it still says mscoree.dll there, then your shim is not loading. Most likely, your .NET add-in is overwriting the entry in the registry for the shim DLL, which means the shim will not be loaded. Make sure that “Register for COM interop” is switched off in the project settings for your .NET add-in. If you forgot to switch that setting off, rebuild the COM shim after you switched it off.
- If your add-in shows up with the correct DLL, but doesn’t load (runtime error in the Add-Ins dialog), then you should check whether you are strong-naming the .NET DLL (Signing in the project properties). Also make sure to not delay sign at this point in time. If you forgot to strong name it, you might just want to delete the shim and run the wizard again, or edit the ShimConfig.cpp file to list the correct public key.
- If you correctly strong-named it, but it still doesn’t load, then check whether you actually copied the .NET DLL into the same directory that Visual Studio creates the Shim DLL. The COM Shim works by looking for your .NET DLL in the same directory the Shim DLL is in. If your .NET DLL is not there, then it cannot be loaded. Visual Studio doesn’t copy the file for you automatically.
- Once you have a working Shim, you can start modifying it to support IRibbonExtensibility. The first modification you have to make is to import the main Office DLL, so that your COM shim knows about IRibbonExtensibility. To do this, open “stdafx.h”, and paste the following into the file:
#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSO.DLL" raw_interfaces_only, raw_native_types, named_guids, auto_search
You have to paste this immediately after the two #import statements that are already in the file (the first one for “mscorlib.tlb”, the second one starting with “libid:”. If the DLL is located in a different directory (or different drive), then adjust the path accordingly, even though I believe Visual Studio might find the DLL automatically at compile time and adjust the path itself. - Open “ConnectProxy.h” and add
using namespace Office;
After the #include statements on the top. - In “ConnectProxy.h”, find the COM_MAP. The COM_MAP begins with “BEGIN_COM_MAP(CConnectProxy)”. You need to add
COM_INTERFACE_ENTRY_AGGREGATE(IID_IRibbonExtensibility, m_pConnect)
At the end of the COM MAP. This statement will make the shim supply your Connect class to Office when it asks for the IRibbonExtensibility interface. After this modification, your COM MAP statement should look like this:BEGIN_COM_MAP(CConnectProxy)
COM_INTERFACE_ENTRY2(IDispatch, AddInDesignerObjects::IDTExtensibility2)
COM_INTERFACE_ENTRY(AddInDesignerObjects::IDTExtensibility2)
COM_INTERFACE_ENTRY_AGGREGATE(IID_IRibbonExtensibility, m_pConnect)
END_COM_MAP() - With these three additional lines in the COM shim, you should now have a working COM shim that supports RibbonX. Compile the Shim and open your Office application again to test it.
Saturday, January 10, 2009
Windows 7
Monday, November 17, 2008
Monday, October 13, 2008
Hanging out with the BBC online
Sunday, September 28, 2008
MySQL hacker needs $400K for his son's bone-marrow transplant
MySQL hacker needs $400K for his son's bone-marrow transplant: "The MySQL community -- who create, maintain and support the leading free database -- are raising funds for Andrii Nikitin, a MySQL support engineer in Ukraine whose little boy, Ivan, needs a $400,000 bone-barrow transplant.
'My family got bad news - doctors said allogenic bone marrow transplantation is the only chance for my son Ivan.
'8 months of heavy and expensive immune suppression brought some positive results so we hoped that recovering is just question of time.
'Ivan is very brave boy - not every human meets so much suffering during whole life, like Ivan already met in his 2,5 years. But long road is still in front of us to get full recover - we are ready to come it through.
'Ukrainian clinics have no technical possibility to do such complex operation, so we need 150-250K EUR for Israel or European or US clinic. The final decision will be made considering amount we able to find. Perhaps my family is able to get ~60% of that by selling the flat where parents leave and some other goods, but we still require external help.'
Donate to help Andrii Nikitin's son Ivan
(Via Boing Boing.)


