Click here to Skip to main content
15,073,250 members
Articles / Desktop Programming / ATL
Posted 23 May 2001


50 bookmarked

Automating the MSN Messenger

Rate me:
Please Sign up or sign in to vote.
3.24/5 (7 votes)
23 May 2001CPOL3 min read
Explains a little bit about event sinking and events of MSN Messenger

Image 1


This is basically to explain how to use an automation out of proc server. So I used MSN Messenger. My article explains a few things about MSN Messenger. It has one ATL class CIMSGEvents which handles the events fired by MSN Messenger. It catches events fired by MSN Messenger and just outputs about it in an EditBox.

Steps to use MSN Messenger

  1. Create a default MFC project (dialog based without using automation option).
  2. Open ClassWizard select automation tab and select the dlg class and click on add class from type library through type library of Messenger i.e. c:\program files\messenger\msmsgs.exe. Select from the list box the following classes:
    (Not very important but insert it to see the dispid for every event. You can also use OLE View to see them)
  3. Insert a new ATL object and name it something like IMSGEvents.

Into the Code

Both IMessengerApp3 and IMsgrObject2 are default interfaces of their CoClasses. Check it in OLE View. IMessengerApp3 dispinterface can be used for controlling the MSN app so first to deal with it. If you see it in generated code you will find it is derived from COleDispatchDriver. So now we need to call CoCreateInstance to initialize the MSN Messenger App like this:

HRESULT hres=CoCreateInstance(__uuidof(CLSID_MessengerApp),
    (void**)&m_MsnApp); // CLSID's and IID's are defined in 
                        // dialog header
if(FAILED(hres))AfxMessageBox("Cannot start msn app"); 

Now to the second dispinterface IMsgrObject2. This is a bit more important. We have to initialize it too so again use CoCreateInstance:

HRESULT hres=CoCreateInstance(__uuidof(CLSID_MsgrObject),
if(FAILED(hres))AfxMessageBox("Cannot get msgr Object");

The third task, a little more complicated, is to make a connection and advise the Messenger. We have to find the IID_DMsgrObjectEvents interface and get event notification. I used the following code:

IConnectionPoint* spCPC;
IUnknown* mpUnk;
IConnectionPointContainer* punkICPC;

HRESULT hres=mpUnk->QueryInterface(IID_IConnectionPointContainer,
       // query the iunknown for connectionpointcontainer

if(FAILED(hres))AfxMessageBox("Cannot get IConnectionPoint interface");

// find the IID_DMsgrObjectEvents to see if it is supported
      AfxMessageBox("Cannot get IID_DMsgrObjectEvents interface");
//finally advise the MsgrObject to get events
if(FAILED(hres))AfxMessageBox("Failed to advise");

Now move to CIMSGEvents and override the Invoke method so to see what event is going on. Declare this in the header and source file:

// in header file
// in cpp file
HRESULT CIMSGEvents::Invoke(DISPID dispidMember, 
    REFIID riid, LCID lcid, WORD wFlags,
    DISPPARAMS* pDispParams, VARIANT* pvarResult,
    EXCEPINFO*  pExcepInfo,  UINT* puArgErr)
return S_OK;

Now to see which event is being fired you can check the dispidMember. See the source for more info. It is very important to note that the parameters you see listed in OLE View are accessed in reverse. So to access the last parameter you have to use code like this


and to access first parameter you have to use the number which is the maximum number of parameters, like for 4th param you have to use pDispParams->rgvarg[3]. So I tried to catch all the events and then output it in an EditBox just to see what happens when the user performs certain actions. It works like a spy.

Thanks and Forgive me

I would like to say thanks to Michael Dunn for his cool articles on COM otherwise I wouldn't have started using COM otherwise, and thanks to Mumtaz Zaheer for always helping me. I have been trying to program since I was sixteen and now I am precisely eighteen. I have been programming COM for past 2 months so you see it's a long period. Well I have submitted this article to ask you people if I have done it the right way or not. So forgive me if I have done anything wrong because I am a beginner. I am basically a student of Chartered Accountancy in Pakistan so I also need some comments about which course line for programming I concentrate more on, like MTS which would relate to my Accountancy Skills. Please give comments.


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


About the Author

CEO Nerdiacs Pte Ltd
Pakistan Pakistan
I'm a drop out of Chartered Accountancy at ICAP but currently continuing Managment Accountancy at CIMA (UK) but i do programming as hobby.
I usually work in C++, MFC, COM. Other languages/techs I like to play with are C#, VB, ASP, PHP, MSSQL, MySQL, Perl and Flash.
These days I usually play with Open Source Switch/PBX on Linux and VoIP products.
I am currently based in Karachi,Pakistan.

Comments and Discussions

Generalbad word filter to protect my kids. Pin
ZUPERKOOL7-Feb-10 6:26
MemberZUPERKOOL7-Feb-10 6:26 
GeneralRe: bad word filter to protect my kids. Pin
Tili11-Apr-11 2:25
MemberTili11-Apr-11 2:25 
GeneralWork offer: require MSN Messenger interaction Pin
chris_jw006-Apr-07 18:36
Memberchris_jw006-Apr-07 18:36 
QuestionHow to get IID_IMessengerConversationWnd pointer when conversation window created? Pin
zhusq14-Apr-06 13:03
Memberzhusq14-Apr-06 13:03 
AnswerRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pin
Tili15-Apr-06 5:35
MemberTili15-Apr-06 5:35 
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pin
zhusq21-Apr-06 9:24
Memberzhusq21-Apr-06 9:24 
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pin
xc.sean19-Jul-07 4:49
Memberxc.sean19-Jul-07 4:49 
GeneralVOIP recorder Pin
triplebit4-Jan-06 8:04
Membertriplebit4-Jan-06 8:04 
GeneralRe: VOIP recorder Pin
Tili4-Jan-06 11:16
MemberTili4-Jan-06 11:16 
GeneralRe: VOIP recorder Pin
triplebit5-Jan-06 4:04
Membertriplebit5-Jan-06 4:04 
GeneralRe: VOIP recorder Pin
Rajeche27-Aug-07 23:43
MemberRajeche27-Aug-07 23:43 
GeneralOutlook to Messenger Pin
Paul Kranz2-Sep-04 2:36
MemberPaul Kranz2-Sep-04 2:36 
GeneralMSN 6.1 Pin
esanteva22-Mar-04 3:03
Memberesanteva22-Mar-04 3:03 
GeneralRe: MSN 6.1 Pin
Tili22-Mar-04 6:26
MemberTili22-Mar-04 6:26 
GeneralRe: MSN 6.1 Pin
koo916-Apr-04 7:53
Memberkoo916-Apr-04 7:53 
GeneralRe: MSN 6.1 Pin
Tili17-Apr-04 9:01
MemberTili17-Apr-04 9:01 
GeneralRe: MSN 6.1 Pin
koo917-Apr-04 20:27
Memberkoo917-Apr-04 20:27 
GeneralRe: MSN 6.1 Pin
Tili18-Apr-04 7:49
MemberTili18-Apr-04 7:49 
GeneralRe: MSN 6.1 Pin
FJE20-Apr-04 5:02
MemberFJE20-Apr-04 5:02 
GeneralRe: MSN 6.1 Pin
Tili20-Apr-04 16:04
MemberTili20-Apr-04 16:04 
GeneralRe: MSN 6.1 Pin
jauming19-Aug-07 17:44
Memberjauming19-Aug-07 17:44 
QuestionIs this same thing possible in VB.Net? Pin
tvinci18-Aug-03 15:13
Membertvinci18-Aug-03 15:13 
AnswerRe: Is this same thing possible in VB.Net? Pin
Soliant26-Aug-03 15:26
MemberSoliant26-Aug-03 15:26 
QuestionHow to get Voice Conversation Invitation Notification? Pin
vrf4-Jul-03 16:58
Membervrf4-Jul-03 16:58 
AnswerRe: How to get Voice Conversation Invitation Notification? Pin
Tili4-Jul-03 23:46
MemberTili4-Jul-03 23:46 

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.