Click here to Skip to main content
6,822,123 members and growing! (17,451 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » COM / COM+ » General     Intermediate License: The Code Project Open License (CPOL)

Automating the MSN Messenger

By Tili

Explains a little bit about event sinking and events of MSN Messenger
VC6Win2K, MFC, ATL, COM, Dev
Posted:23 May 2001
Views:183,187
Bookmarked:49 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
17 votes for this article.
Popularity: 4.28 Rating: 3.48 out of 5
2 votes, 28.6%
1

2
1 vote, 14.3%
3
1 vote, 14.3%
4
3 votes, 42.9%
5

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)

About the Author

Tili


Member
I am 26 years old.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.
Occupation: Architect
Company: Faber Nitor
Location: Pakistan Pakistan

Other popular COM / COM+ articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 61 (Total in Forum: 61) (Refresh)FirstPrevNext
Generalbad word filter to protect my kids. PinmemberZUPERKOOL7:26 7 Feb '10  
GeneralWork offer: require MSN Messenger interaction Pinmemberchris_jw0019:36 6 Apr '07  
GeneralHow to get IID_IMessengerConversationWnd pointer when conversation window created? Pinmemberzhusq14:03 14 Apr '06  
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? PinmemberTili6:35 15 Apr '06  
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pinmemberzhusq10:24 21 Apr '06  
GeneralRe: How to get IID_IMessengerConversationWnd pointer when conversation window created? Pinmemberxc.sean5:49 19 Jul '07  
GeneralVOIP recorder Pinmembertriplebit9:04 4 Jan '06  
GeneralRe: VOIP recorder PinmemberTili12:16 4 Jan '06  
GeneralRe: VOIP recorder Pinmembertriplebit5:04 5 Jan '06  
GeneralRe: VOIP recorder PinmemberRajeche0:43 28 Aug '07  
GeneralOutlook to Messenger PinsussPaul Kranz3:36 2 Sep '04  
GeneralMSN 6.1 Pinmemberesanteva4:03 22 Mar '04  
GeneralRe: MSN 6.1 PinmemberTili7:26 22 Mar '04  
GeneralRe: MSN 6.1 Pinmemberkoo98:53 16 Apr '04  
GeneralRe: MSN 6.1 PinmemberTili10:01 17 Apr '04  
GeneralRe: MSN 6.1 Pinmemberkoo921:27 17 Apr '04  
GeneralRe: MSN 6.1 PinmemberTili8:49 18 Apr '04  
GeneralRe: MSN 6.1 PinmemberFJE6:02 20 Apr '04  
GeneralRe: MSN 6.1 PinmemberTili17:04 20 Apr '04  
GeneralRe: MSN 6.1 Pinmemberjauming18:44 19 Aug '07  
GeneralIs this same thing possible in VB.Net? Pinmembertvinci16:13 18 Aug '03  
GeneralRe: Is this same thing possible in VB.Net? PinmemberSoliant16:26 26 Aug '03  
GeneralHow to get Voice Conversation Invitation Notification? Pinmembervrf17:58 4 Jul '03  
GeneralRe: How to get Voice Conversation Invitation Notification? PinmemberTili0:46 5 Jul '03  
GeneralRe: How to get Voice Conversation Invitation Notification? Pinmembervrf18:46 6 Jul '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 23 May 2001
Editor: Nishant Sivakumar
Copyright 2001 by Tili
Everything else Copyright © CodeProject, 1999-2010
Web21 | Advertise on the Code Project