Showing posts with label Legacy Code. Show all posts
Showing posts with label Legacy Code. Show all posts

Monday, 6 April 2009

Integrating Instant MSN messenger in ASP.NET

Though this feature may be available in MS sharepoint portals but some time we need to embed MSN windows(not live messenger) Messenger in our own non portal website .Before starting our mission, we need RCW(Runtime callable Wrapper) interfaces for messenger so .Net Environment can understand old Com's Methods and properties.
Note:You also need to know about STA and MTA Thread pool.
  • Open Menu->Type "C:\Program Files\Messenger" in Run.
  • msmsgs.exe is our target to convert it to .Net assembly.
We will use TLBImp.exe tool that will import metadata from msmsgs type library and convert it to .Net assembly where Metadata will be stored in assembly manifest.All Methods and properties from Com components will be exposed through new generated dll. However it is nessary that old COMs should be existed and should be registered in registry before Generating RCW wrapper(.Net dll).

  • Goto MS visual studio 2005 tools->open Visula studio 2005 Command prompt.
  • type following command
C:\Program Files\Microsoft Visual Studio 8\VC>tlbimp.exe "C:\Program Files\Messe nger\msmsgs.exe" /out:C:\inetpub\wwwroot\myWebsitedirectory\inetpubdotnetmsgr.dll
  • On Solution Explorer in VS 2005 , right click and Add Reference
Select Converted Dll from Add refernence window.

Now Switch to code view and this code.

Normal 0 false false false MicrosoftInternetExplorer4

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using inetpubdotnetmsgr;

public partial class Messenger : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (IsPostBack==false)

{

MsgrObjectClass _messngerobject = new MsgrObjectClass();

_messngerobject.Logoff();

//IMsgrService _ImessngerService = _messngerobject.IMsgrObject_Services.PrimaryService;

_messngerobject.Logon("myuserid@hotmail.com", "mypassword", _messngerobject.Services.PrimaryService);

IMsgrUsers _Users = _messngerobject.get_List(MLIST.MLIST_CONTACT);

foreach (IMsgrUser _user in _Users)

{

ListBox1.Items.Add(_user.EmailAddress.ToString());

}

}

}

}



You aslo need to set permission on new generated Dll for asp.net User.