Introduction
- Select new ATL COM Wizard - and then select DLL Project.
- Add an ATL Object through Wizard.
- Implement Interface -> Add Type Lib -> Microsoft Add-in Designer ->
_IDTExtensibility2
.
- Add Outlook architecture and Outlook library in stdafx.h. This changes according to your system configuration where you have installed Office.
This is pertaining to Microsoft Office XP:
#import "C:\Program Files\Common Files\Microsoft
Shared\Office10\mso.dll" rename_namespace("Office"),
named_guids using namespace Office;
#import "D:\Program Files\Microsoft Office\Office10\MSOUTL.olb"
rename_namespace("Outlook"), named_guids,
raw_interfaces_only using namespace Outlook;
For Office 2000:
#import "D:\Program Files\Microsoft Office\Office\mso9.dll"
rename_namespace("Office"), named_guids using namespace Office;
#import "D:\Program Files\Microsoft Office\Office\MSOUTL9.olb"
rename_namespace("Outlook"), named_guids,
raw_interfaces_only using namespace Outlook;
- Add Registry entry in Addin.rgs.
HKCU
{
Software
{
Microsoft
{
Office
{
Outlook
{
Addins
{
'MyAddin.Addin'
{
val FriendlyName = s 'My Outlook Addin'
val Description = s 'Outlook Addin'
val LoadBehavior = d '00000016'
val CommandLineSafe = d '00000000'
}
}
}
}
}
}
}
- Add member variables in Addin.h.
- Add the following code in Addin.h's
OnConnection
method: STDMETHOD(OnConnection)(IDispatch * Application,
ext_ConnectMode ConnectMode, IDispatch * AddInInst,
SAFEARRAY * * custom)
{
CComQIPtr <Outlook::_Application> spApp(Application);
ATLASSERT(spApp);
m_spApp = spApp;
spApp->ActiveExplorer(&spExplorer);
HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if(FAILED(hr))
return hr;
ATLASSERT(spCmdBars);
CComVariant vName("MyAddin Toolbar");
CComPtr <Office::CommandBar> spNewCmdBar;
CComVariant vPos(1);
CComVariant vTemp(VARIANT_TRUE);
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);
CComPtr < Office::CommandBarControls> spBarControls;
spBarControls = spNewCmdBar->GetControls();
ATLASSERT(spBarControls);
CComVariant vToolBarType(1);
CComVariant vShow(VARIANT_TRUE);
CComPtr < Office::CommandBarControl> spNewBar;
spNewBar = spBarControls->Add(vToolBarType,
vEmpty, vEmpty, vEmpty, vShow);
ATLASSERT(spNewBar);
_bstr_t bstrNewCaption(OLESTR("Item1"));
_bstr_t bstrTipText(OLESTR("Tooltip for Item1"));
CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
ATLASSERT(spCmdButton);
spCmdButton->PutVisible(VARIANT_TRUE);
spCmdButton->PutCaption(OLESTR("MyButton"));
spCmdButton->PutEnabled(VARIANT_TRUE);
spCmdButton->PutTooltipText(OLESTR("Tooltip for MyButton"));
spCmdButton->PutTag(OLESTR("Tag for MyButton"));
spNewCmdBar->PutVisible(VARIANT_TRUE);
m_spButton = spCmdButton;
return E_NOTIMPL;
}
- Save and compile the Project.
That's it!!!!...... You have successfully added a new Toolbar with a new Button placed in it!!!!!
Congrats....your first step in Add-in tutorial is over!!!!!!!!
How To See My Add-in???
--->Open Outlook Express. Since in Registry Settings, for Load Behavior we have specified 00000016, this loads our add-in at startup of Outlook Express each time. The other load behaviors are as follows:
- 00000008 - Load By Demand.
- 00000003 - Load at Startup only once.
--->I request all the users to use 00000016 because it can relieve confusion of how to load an add-in.
If Add-in not loaded...then how to load???
--->The work is simple....Open Outlook Express... choose Tools....Options.... you will get a tab, choose 'other' options from the tab... and then choose 'Advanced Options'... and then 'COM Add-ins'...you will now see your registered add-ins list... choose your add-in and press OK.
So your first task of adding a Button is over...soon you will have the code for responding to the Button Click produced to you.....
Please feel free to send your reviews to chakkaradeepcc@yahoo.com.
Credits:
- This tutorial was based on the idea of Amit Dey in his tutorial, Building an Office2K COM add-in with VC++/ATL.
So all my thanks goes to Mr.Amit Dey who was 'the guru' for me to Add-ins.
- And I mention Igor Tandek of Microsoft Corporation for his great help in making me understand the Inner Concepts of Add-ins along with ATL COM.
A small request to Amit Dey....any contact number or address or mail-id?