Click here to Skip to main content
15,867,750 members
Articles / Desktop Programming / ATL

How to Create Outlook AddIN / Plugin

Rate me:
Please Sign up or sign in to vote.
1.70/5 (14 votes)
22 Jun 2009CPOL3 min read 115.6K   1.9K   35   14
When i had searched on the net I found out that there is too less information for outlook addin creation in vc.I was only getting vb application on then Internet so here I have created application with all web site link which I found helpful to you. Now You can create plugin in vc easily.

Introduction

When I was working on outlook addin project I had searched lot on outlook addin creation in vc++ but I have found very few documents on the internet that's why when I got success in catching send and new mail event. I planned for updating thing for helping others.

I belive this will give you idea on how to create Add-ins.

Outlook Addin is created using ATL. This code helps you to capture events when Send Mail and New Mail received.

Using the code

Steps for creatding AddIN of outlook.

1. Create new project in vc++6.0. Select "ATL COM AppWizard" as project type and select "Dynamic Link Library" in ATL COM AppWizard Step 1 of 1. Click finish button on that window. ATL project dll is created.

2. In project click on Insert tab and select "New ATL Object". Select "Object" in category and "Simple Object" in objects then click "Next" button. In "Short Name" under Names tab write your add in name. Other tab Attributes select "Support ISupportedErrorInfo". Your AddIn interface is created.

3. Go to class view of your project and right click on your interface class name (Example if you have given interface name "AddIN" then in class view you will find "CAddIN" select this class and right click on that) inside popup click on implement Interface. If you are getting any Warning then just click "OK" button and you will get window with name "Browse Type Libraries". Browse "Microsoft Add-in Designer(1.0) " in that list and select it and click "OK" then you will get window with name "implement Interface" here we have to select "_IDTExtensiblity2" and click "OK".

Wizard will implement default methods of this interface that you can see inside class view. "_IDTExtensiblity2" interface needs to be implemented if we want to create addin of Office.

<P>
4. Go to AddIN header file and add following lines. 

extern _ATL_FUNC_INFO OnSendInfo;
extern _ATL_FUNC_INFO OnNewMailInfo;

public IDispEventSimpleImpl<1,CADDIN_Chaitanya,&__uuidof(<a href="outlook::ApplicationEvents">Outlook::ApplicationEvents</a>)>, 
public IDispEventSimpleImpl<2,CADDIN_Chaitanya,&__uuidof(<a href="outlook::ApplicationEvents">Outlook::ApplicationEvents</a>)>
 
public:
 typedef IDispEventSimpleImpl</*nID =*/ 1,CADDIN_Chaitanya, &__uuidof(<a href="outlook::ApplicationEvents">Outlook::ApplicationEvents</a>)> AppEvents;
 typedef IDispEventSimpleImpl</*nID =*/ 2,CADDIN_Chaitanya, &__uuidof(<a href="outlook::ApplicationEvents">Outlook::ApplicationEvents</a>)> AppEvents_New;     

BEGIN_SINK_MAP(CADDIN_Chaitanya)
 
SINK_ENTRY_INFO(1,__uuidof(<a href="outlook::ApplicationEvents),/*dispinterface*/0x0000F002,OnSend,&OnSendInfo">Outlook::ApplicationEvents),/*dispinterface*/0x0000F002,OnSend,&OnSendInfo</a>)
SINK_ENTRY_INFO(2,__uuidof(<a href="outlook::ApplicationEvents),/*dispinterface*/0x0000F003,OnNewMail,&OnNewMailInfo">Outlook::ApplicationEvents),/*dispinterface*/0x0000F003,OnNewMail,&OnNewMailInfo</a>) 
 
END_SINK_MAP() 
 
 // event handler functions
 void __stdcall OnNewMail();
 void __stdcall OnSend(); 
 
// At the add of the class add defination this line (Last line of the class defination)
  
private:
 CComPtr<<a href="outlook::_Application">Outlook::_Application</a>> m_spApp;//application
 CComPtr<<a href="outlook::_Application">Outlook::_Application</a>> m_spApp_Event_Send_Mail;//application
 CComPtr<<a href="outlook::_Application">Outlook::_Application</a>> m_spApp_Event_New_Mail;//application
 
// Add this line in side OnConnetion    
                   
  CComQIPtr <<a href="outlook::_Application">Outlook::_Application</a>> spApp(Application); 
  ATLASSERT(spApp);
  m_spApp_Event_New_Mail = m_spApp_Event_Send_Mail  = m_spApp = spApp; //store the application object
  
  ////////////////////////  Application event  ////////////////////////////////////
  
  HRESULT hr = NULL;//DispEventAdvise((IDispatch*)spExplorer);
  
  hr = AppEvents::DispEventAdvise((IDispatch*)m_spApp_Event_Send_Mail,&__uuidof(<a href="outlook::ApplicationEvents">Outlook::ApplicationEvents</a>)); 
  if(FAILED(hr))
   return hr;
  
  hr = AppEvents_New::DispEventAdvise((IDispatch*)m_spApp_Event_New_Mail ,&__uuidof(<a href="outlook::ApplicationEvents">Outlook::ApplicationEvents</a>)); 
  if(FAILED(hr))
   return hr;     
 
  // Add this line inside OnDisconnection Methods
  hr = AppEvents::DispEventUnadvise((IDispatch*)m_spApp_Event_Send_Mail);
  hr = AppEvents_New::DispEventUnadvise((IDispatch*)m_spApp_Event_New_Mail); 
5. Go to File view and select AddIN cpp file and your need to add following lines.

_ATL_FUNC_INFO OnSendInfo ={CC_STDCALL,VT_EMPTY,1,VT_DISPATCH};        
_ATL_FUNC_INFO OnNewMailInfo ={CC_STDCALL,VT_EMPTY,0};
 
void __stdcall CADDIN_Chaitanya::OnNewMail()
{
 //AfxMessageBox("heloo");
    ::MessageBox(0,"Chaitanya New Mail","On New Mail",0);
}
void __stdcall CADDIN_Chaitanya::OnSend()  
//(IDispatch * /*Office::_CommandBarButton**/ Ctrl,bool)
{
 ::MessageBox(0,"Chaitanya Send ","On Send Clicked",0);
}</p>

Points of Interest

When I was going through the net I have not found single application with vc++ syntax explanation. That's why I am giving brief here.IDispEventSimpleImpl this is interface class that needs to be passes parameter properly.First of all you need to understand which event is under which class example some event are of ApplicationEvent some of are ExplorerEvent some are from ItemEvent and some from ItemEvents.

Here two event I have captured that both are of Application Events.

That's why my 3rd passing parameter to IDispEventSimpleImpl is that.

public IDispEventSimpleImpl<1,CADDIN_Chaitanya,&__uuidof(Outlook::ApplicationEvents)>,

public IDispEventSimpleImpl<2,CADDIN_Chaitanya,&__uuidof(Outlook::ApplicationEvents)>

Send Most Important thing is "0x0000F002" this kind of numbers this are dispinterface which we need to specifying inside Begin_Sink_Map for example::

SINK_ENTRY_INFO(1,__uuidof (Outlook::ApplicationEvents),/*dispinterface*/0x0000F002,OnSend,&OnSendInfo)

SINK_ENTRY_INFO(2,__uuidof(Outlook::ApplicationEvents),/*dispinterface*/0x0000F003,OnNewMail,&OnNewMailInfo)

If you will specified some wrong number then problem may happen you may not able to get event. This no you can easily get from net as vb codes.Third Most Important thing is "Advise" and "UnAdvise" in VC syntax is "DispEventAdvise" and "DispEventUnadvise" respectively. If we will not Advise in our code then we can not get event when outlook is generating that event.This 3 are most important factors which need to be understand properly when creating addin otherwise it will create problem for you in getting event of outlook.

If you have any problem then you can make not here. I will try best to give you convicing reply.

Other Links

Links of Msdn and codeproject which can help you for your understanding and development.

http://support.microsoft.com/kb/196776/
http://support.microsoft.com/kb/199870/
http://support.microsoft.com/kb/220600
http://support.microsoft.com/kb/230689/EN-US/

http://msdn2.microsoft.com/en-us/library/aa662931(office.11).aspx

http://msdn2.microsoft.com/en-us/library/aa201312(office.11).aspx
http://msdn2.microsoft.com/en-us/library/aa189757(office.10).aspx
http://msdn2.microsoft.com/en-us/library/aa155732(office.10).aspx
http://msdn2.microsoft.com/en-us/library/ms268749(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/aa141349(office.10).aspx
http://msdn2.microsoft.com/en-us/library/aa189757(office.10).aspx


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
com Add - in

http://msdn2.microsoft.com/en-us/library/aa155767(office.10).aspx
http://msdn2.microsoft.com/en-us/library/aa140126(office.10).aspx
http://msdn2.microsoft.com/en-us/library/aa167881(office.11).aspx http://support.microsoft.com/kb/q241287/ http://support.microsoft.com/kb/q199870/

/////////////////////// Sink Event

http://msdn2.microsoft.com/en-us/library/yscwkhd6(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/kdbd8xsk(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/aa155701(office.10).aspx
http://msdn2.microsoft.com/en-us/library/aa155701(office.10).aspx#odc_ch11olevents_topic2
http://www.codeguru.com/forum/printthread.php?t=269119

License

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


Written By
Technical Lead Tata Consultancy Servcies
India India
I have experience in iOs, Objective C,Java,C++/Vc++ 6.0,vc.Net,MFC,ATL,COM,WTL.

You can contact me on chaitanya.ce@gmail.com if you have any query.

Comments and Discussions

 
GeneralMy vote of 5 Pin
tarun_198024-Aug-10 7:57
tarun_198024-Aug-10 7:57 
GeneralMy vote of 1 Pin
rajas22-Jun-09 22:53
rajas22-Jun-09 22:53 
GeneralPharsing the mail context Pin
Arie Levy17-Apr-09 22:55
Arie Levy17-Apr-09 22:55 
GeneralRe: Pharsing the mail context Pin
chaitanya shah22-Jun-09 0:48
chaitanya shah22-Jun-09 0:48 
Getting TO CC & BCC is very easy. That will be available once you have instance of that mail in fiels. I have no idea for alias. If you still find in retreving To please let me know.
GeneralRe: Pharsing the mail context Pin
Ram Shelke21-Jul-15 4:01
Ram Shelke21-Jul-15 4:01 
GeneralAddIn for Outlook Express Pin
chanakya_India16-Dec-08 17:38
chanakya_India16-Dec-08 17:38 
QuestionError while creating a plugin for windows media player. Pin
amiya das4-Jan-08 2:13
amiya das4-Jan-08 2:13 
GeneralAddin crashes with Outlook 2000 Pin
_AnsHUMAN_ 10-Dec-07 19:01
_AnsHUMAN_ 10-Dec-07 19:01 
GeneralProblem running the Addin Pin
c19694824-Jun-07 4:51
c19694824-Jun-07 4:51 
GeneralRe: Problem running the Addin Pin
chaitanya shah26-Jun-07 20:26
chaitanya shah26-Jun-07 20:26 
GeneralAwesome article Pin
LearningPhase22-Jun-07 7:30
LearningPhase22-Jun-07 7:30 
GeneralRe: Awesome article Pin
chaitanya shah26-Jun-07 20:31
chaitanya shah26-Jun-07 20:31 
GeneralVery Informatiove Pin
Sudhir Mangla9-Apr-07 17:58
professionalSudhir Mangla9-Apr-07 17:58 
GeneralRe: Very Informatiove Pin
chaitanya shah9-May-07 9:16
chaitanya shah9-May-07 9:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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