Page 1 of 1

Windows Live Messenger API How-To

Posted: Wed Mar 09, 2011 3:51 pm
by Codex
Hello and welcome to my tutorial on how to use the Windows Live Messenger API.
Tested and works with MSN 2011

Controls needed

2 Labels, name = lbl_st, text = unknown | name = "Label1", text = "My Status"
Timer1, enabled = true, interval = 100
Textbox1, text = "Email Address"
4 Buttons; text = "Add Contact" | text = "Load Online Contacts" | text = "Sign-out" | text = "Change Status"
Listbox1
Combobox1, items =
Code: Select all
Away
Be Right Back
Busy
Invisible
Offline
On the phone
Online
Out to lunch
Unknown
Image
First thing you need to do after you create your project is add a reference to the API. Go to "My Project" and click on the "References" tab. Then click on "Add..." and click on "COM" tab and scroll down till you find "Messenger API Type Library", and select it. At the bottom of the same page you will see checkboxed-listbox, scroll down to "MessengerAPI" and check it.
Image
Image
Now you go to your form and import these at the top.
Code: Select all
Imports MessengerAPI.MISTATUS
Imports MessengerAPI
Now after Public Class <form name> add this.
Code: Select all
    Public msn As New MessengerAPI.Messenger
    Public msnwindow As MessengerAPI.IMessengerWindow = msn.Window
Add this to form_load event:
Code: Select all
AddHandler msn.OnMyStatusChange, AddressOf msn_OnMyStatusChange
        Control.CheckForIllegalCrossThreadCalls = False
Add this after/before form_load event:
Code: Select all
        If mMyStatus = MISTATUS_AWAY Then
            lbl_st.Text = "Away"
        ElseIf mMyStatus = MISTATUS_BE_RIGHT_BACK Then
            lbl_st.Text = "Be Right Back"
        ElseIf mMyStatus = MISTATUS_BUSY Then
            lbl_st.Text = "Busy"
        ElseIf mMyStatus = MISTATUS_INVISIBLE Then
            lbl_st.Text = "Invisible"
        ElseIf mMyStatus = MISTATUS_OFFLINE Then
            lbl_st.Text = "Offline"
        ElseIf mMyStatus = MISTATUS_ON_THE_PHONE Then
            lbl_st.Text = "On the phone"
        ElseIf mMyStatus = MISTATUS_ONLINE Then
            lbl_st.Text = "Online"
        ElseIf mMyStatus = MISTATUS_OUT_TO_LUNCH Then
            lbl_st.Text = "Out to lunch"
        ElseIf mMyStatus = MISTATUS_UNKNOWN Then
            lbl_st.Text = "Unknown"
        End If
Button1_click (add contact) event:
Code: Select all
Try
            If Not TextBox1.Text = "Email Address" Then
                msn.AddContact(0, TextBox1.Text)
            End If
        Catch ex As Exception

        End Try
Button2_click (Change status) event:
Code: Select all
        Try
            If ComboBox1.SelectedItem = "Away" Then
                msn.MyStatus = MISTATUS_AWAY
            ElseIf ComboBox1.SelectedItem = "Be Right Back" Then
                msn.MyStatus = MISTATUS_BE_RIGHT_BACK
            ElseIf ComboBox1.SelectedItem = "Busy" Then
                msn.MyStatus = MISTATUS_BUSY
            ElseIf ComboBox1.SelectedItem = "Invisible" Then
                msn.MyStatus = MISTATUS_INVISIBLE
            ElseIf ComboBox1.SelectedItem = "Offline" Then
                msn.MyStatus = MISTATUS_OFFLINE
            ElseIf ComboBox1.SelectedItem = "On the phone" Then
                msn.MyStatus = MISTATUS_ON_THE_PHONE
            ElseIf ComboBox1.SelectedItem = "Online" Then
                msn.MyStatus = MISTATUS_ONLINE
            ElseIf ComboBox1.SelectedItem = "Out to lunch" Then
                msn.MyStatus = MISTATUS_OUT_TO_LUNCH
            ElseIf ComboBox1.SelectedItem = "Unknown" Then
                msn.MyStatus = MISTATUS_UNKNOWN
            End If
        Catch ex As Exception

        End Try
Button3_click (load online contacts) event:
Code: Select all
       Dim contacts As IMessengerContacts = msn.MyContacts
        Dim contact As IMessengerContact
        ListBox1.Items.Clear()
        For Each contact In contacts

            If Not contact.Status = MISTATUS.MISTATUS_OFFLINE Then
                ListBox1.Items.Add(contact.FriendlyName)
            End If
        Next
Listbox1_doubleclick event:
Code: Select all
        Dim contacts As IMessengerContacts = msn.MyContacts
        Dim vContact As IMessengerContact
        For Each Contact As IMessengerContact In contacts
            If ListBox1.SelectedItem = Contact.FriendlyName Then
                vContact = msn.GetContact(Contact.SigninName, Contact.ServiceId)
            End If
        Next
        msn.InstantMessage(vContact)
Button4_click (sign-out) event:
Code: Select all
msn.Signout()
Timer1_tick event:
Code: Select all
        If msn.MyStatus = MISTATUS_AWAY Then
            lbl_st.Text = "Away"
        ElseIf msn.MyStatus = MISTATUS_BE_RIGHT_BACK Then
            lbl_st.Text = "Be Right Back"
        ElseIf msn.MyStatus = MISTATUS_BUSY Then
            lbl_st.Text = "Busy"
        ElseIf msn.MyStatus = MISTATUS_INVISIBLE Then
            lbl_st.Text = "Invisible"
        ElseIf msn.MyStatus = MISTATUS_OFFLINE Then
            lbl_st.Text = "Offline"
        ElseIf msn.MyStatus = MISTATUS_ON_THE_PHONE Then
            lbl_st.Text = "On the phone"
        ElseIf msn.MyStatus = MISTATUS_ONLINE Then
            lbl_st.Text = "Online"
        ElseIf msn.MyStatus = MISTATUS_OUT_TO_LUNCH Then
            lbl_st.Text = "Out to lunch"
        ElseIf msn.MyStatus = MISTATUS_UNKNOWN Then
            lbl_st.Text = "Unknown"
        End If
*BONUS*
Might not work on some versions of msn. How to login.
Button_click (login) event
Code: Select all
msn.Signin(0, "USERNAME", "PASSWORD")
There are many more features you can do, just try it yourself.

Comment, Rate, +rep :)

Thanks
CodexVideos

Re: Windows Live Messenger API How-To

Posted: Wed Mar 09, 2011 7:33 pm
by mandai
I get this error when I try to make a new instance of MessengerAPI.Messenger: Creating an instance of the COM component with CLSID {B69003B3-C55E-4B48-836C-BC5946FC3B28} from the IClassFactory failed due to the following error: 8007000e.
I have windows live messenger installed.

Re: Windows Live Messenger API How-To

Posted: Wed Mar 09, 2011 7:36 pm
by Codex
mandai wrote:
I get this error when I try to make a new instance of MessengerAPI.Messenger: Creating an instance of the COM component with CLSID {B69003B3-C55E-4B48-836C-BC5946FC3B28} from the IClassFactory failed due to the following error: 8007000e.
I have windows live messenger installed.
Is this your error : System.OutOfMemoryException

Re: Windows Live Messenger API How-To

Posted: Wed Mar 09, 2011 7:54 pm
by mandai
I don't see any OutOfMemoryException messages.

Re: Windows Live Messenger API How-To

Posted: Wed Mar 09, 2011 9:55 pm
by code it
mandai wrote:
I get this error when I try to make a new instance of MessengerAPI.Messenger: Creating an instance of the COM component with CLSID {B69003B3-C55E-4B48-836C-BC5946FC3B28} from the IClassFactory failed due to the following error: 8007000e.
I have windows live messenger installed.

I think you need to be logged off of msn and then leave msn open,it worked for me!

Re: Windows Live Messenger API How-To

Posted: Wed Mar 09, 2011 10:52 pm
by Scottie1972
mandai wrote:
I don't see any OutOfMemoryException messages.
I did a simple Google Search for
CLSID {B69003B3-C55E-4B48-836C-BC5946FC3B28} error code.

It is amazing what you can find out when you know how to using the internet. :)

This link in the MSDN forums mentioned something about the program my be incompatible with your system.
It recommends all sorts of fixes. Mostly editing your Registry.
http://social.msdn.microsoft.com/Forums ... 0270238aca


Now this post on C# Sharpcorner ( scroll down to the bottom of the page and reead some of the feedbacks) state that this code may only work with MSN Messenger 8.1 and NOT Windows Live Messenger. I do believe
that these 2 software are completely different from each other.
http://www.c-sharpcorner.com/uploadfile ... enger.aspx


But in my humble opinion the CLSID is a registry error code. So I would tend to think you could start there.
CLSID {B69003B3-C55E-4B48-836C-BC5946FC3B28}


BTW, this is no way pointed at you personally.
I figured I would do a Google Search and see what pops up.
Like I said, " I was amazed at what I found."

Scottie1972