Google

Tuesday, May 1, 2007

Using MSN’s API with VB.NET

Open VS and then create a new VB.NET "Windows Forms" project.After creating the project add a reference to Interop.MessengerAPI.dll .

Import the Namespace

Imports MessengerAPI


Create an instance of MessengerClass

Public msn As New MessengerAPI.MessengerClass
Public msnwindow As MessengerAPI.IMessengerWindow


Now all methods can be called directly. Here I used two textboxes one for email and one for password.


Sample code for Sign in

Try
msnwindow = CType(msn.Window, MessengerAPI.IMessengerWindow)
msn.Signin(CType(msnwindow.HWND, Integer), txtemail.Text, txtpassword.Text)
Catch ex As Exception
MsgBox(ex.Message)
End Try


For MSN API events you can add your own handlers.


AddHandler msn.OnMyStatusChange, AddressOf msn_OnMyStatusChange



Private Sub msn_OnMyStatusChange(ByVal hr As Integer, ByVal mMyStatus As MISTATUS)

' code to handle status change
End Sub