Click here to Skip to main content
Click here to Skip to main content

Automating the MSN Messenger

, 23 May 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
Explains a little bit about event sinking and events of MSN Messenger

Introduction

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:
    IMessengerApp3
    IMsgrObject2
    DMsgrObjectEvents
    (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),
    NULL,CLSCTX_LOCAL_SERVER,
    __uuidof(IID_IMessengerApp3),
    (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),
    NULL,CLSCTX_LOCAL_SERVER,
    __uuidof(IID_IMsgrObject2),(void**)&m_MsgObject);
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;
    mpUnk=m_MsgObject;

    HRESULT hres=mpUnk->QueryInterface(IID_IConnectionPointContainer,
        (void**)&punkICPC);
           // query the iunknown for connectionpointcontainer

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

    // find the IID_DMsgrObjectEvents to see if it is supported
    hres=punkICPC->FindConnectionPoint(
          __uuidof(IID_DMsgrObjectEvents),&spCPC);
    if(FAILED(hres))
          AfxMessageBox("Cannot get IID_DMsgrObjectEvents interface");
    //finally advise the MsgrObject to get events
    hres=spCPC->Advise(pMsgEvents,&m_dwAdviseCookie);
    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
STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS*,
    VARIANT*, EXCEPINFO*, UINT*);
    
// 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

pDispParams->rgvarg[0]

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.

License

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

Share

About the Author

Tili
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 www.asteriskpbx.com and VoIP products.
I am currently based in Karachi,Pakistan.
Follow on   Twitter

Comments and Discussions

 
Generalbad word filter to protect my kids. PinmemberZUPERKOOL7-Feb-10 7:26 
GeneralRe: bad word filter to protect my kids. PinmemberTili11-Apr-11 3:25 
GeneralWork offer: require MSN Messenger interaction Pinmemberchris_jw006-Apr-07 19:36 
QuestionHow to get IID_IMessengerConversationWnd pointer when conversation window created? Pinmemberzhusq14-Apr-06 14:03 
AnswerRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? PinmemberTili15-Apr-06 6:35 
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pinmemberzhusq21-Apr-06 10:24 
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pinmemberxc.sean19-Jul-07 5:49 
GeneralVOIP recorder Pinmembertriplebit4-Jan-06 9:04 
GeneralRe: VOIP recorder PinmemberTili4-Jan-06 12:16 
GeneralRe: VOIP recorder Pinmembertriplebit5-Jan-06 5:04 
GeneralRe: VOIP recorder PinmemberRajeche28-Aug-07 0:43 
GeneralOutlook to Messenger PinsussPaul Kranz2-Sep-04 3:36 
GeneralMSN 6.1 Pinmemberesanteva22-Mar-04 4:03 
GeneralRe: MSN 6.1 PinmemberTili22-Mar-04 7:26 
GeneralRe: MSN 6.1 Pinmemberkoo916-Apr-04 8:53 
GeneralRe: MSN 6.1 PinmemberTili17-Apr-04 10:01 
GeneralRe: MSN 6.1 Pinmemberkoo917-Apr-04 21:27 
GeneralRe: MSN 6.1 PinmemberTili18-Apr-04 8:49 
GeneralRe: MSN 6.1 PinmemberFJE20-Apr-04 6:02 
GeneralRe: MSN 6.1 PinmemberTili20-Apr-04 17:04 
GeneralRe: MSN 6.1 Pinmemberjauming19-Aug-07 18:44 
QuestionIs this same thing possible in VB.Net? Pinmembertvinci18-Aug-03 16:13 
AnswerRe: Is this same thing possible in VB.Net? PinmemberSoliant26-Aug-03 16:26 
QuestionHow to get Voice Conversation Invitation Notification? Pinmembervrf4-Jul-03 17:58 
AnswerRe: How to get Voice Conversation Invitation Notification? PinmemberTili5-Jul-03 0:46 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 24 May 2001
Article Copyright 2001 by Tili
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid