My PhotoBruno Brás Silva

09, April 1986

info@brunosilva.net

Sintra Lisbon Portugal

Messenger Plus! Live and .NET working together

Posted on 8:34pm 11/30/2007 by Bruno Silva in Programming

I and some colleagues are working in a university assignment which involves manipulating Windows Live Messenger messages. Since the official API doesn’t allow us to alter the messages we had to use Messenger Plus! Live. In the other hand the rest of our project was meant to be developed in .NET because we wanted to use web-services and other .NET features that can help us to do a decent project without too much trouble.

I will briefly try to explain to you how you can create a .NET class library and use it in a Messenger Plus! Plugin (which is written in Javascript).

First of all you have to create your class library in Visual Studio 2005.

Visual Studio 2005

Then write down your login into the new Class1.cs file (or Class1.vb, if you prefer programming in that awful language :-P) I have highlighted some elements that you must have. You will notice the declaration of an interface. Honestly, I haven’t tried this code without it, and in the place I learned how to do this they mentioned the need to have it.

using System;

using System.Collections;

using System.Text;

using System.Runtime.InteropServices;

using System.Collections.Generic;

namespace myFirstPlugin{

    public interface PluginInterface{

        string addToLog(string sender,string recipient,string message);

        string getFullLog();

    }

    [ClassInterface(ClassInterfaceType.AutoDual)]

    public class Plugin{

        public class Message{

            string sender;

            string recipient;

            string message;

            public Message(string sender, string recipient, string message){

                this.sender = sender;

                this.recipient = recipient;

                this.message = message;

            }

        }

        private List<Message> _log new List<Message>();

        public string addToLog (string sender, string recipient, string message){

            _log.Add(new Message(sender, recipient, message));

            return sender + recipient + message;

        }

        public string getFullLog(){

            string log = “”;

            foreach (Message msg in _log)

                                  log += msg.sender + “>” + msg.recipient + “: “ + msg.message + “\r\n”;

                            return log;

        }

    }

}

All the extra code will be used to create an ActiveX control, which can be used in Javascript code in a HTML page or in this case in a Messenger Plus! plugin.

You can compile your class just to make sure it is ok, but to use it in your plugin the easy way is to compile it from Visual Studi 2005 Command Prompt. Run it with administrator privileges.

 

Visual Studio 2005 Command Prompt

Change to your Class Library Project directory. You will have to create a Key.

> sn -k sgKey.snk 

Compile your class signing your Assembly with a Strong Name. This way you will avoid some security warnings when you register your Assembly and use your ActiveX control.

> csc /t:library Plugin.cs /keyfile:sgkey.snk

This next step must be done in every computer where you install your plugin. In VS Command Prompt the executable is in PATH. In other computers, you can find it in \Windows\Microsoft.NET\Framework\v2.0.XXXXX\.

> regasm Plugin.dll /tlb:PluginNet.dll /codebase

(after this command you won’t be able to delete Plugin.dll. You must unregister the Assembly using: regasm /unregister Plugin.dll)

Ok. The .Net part is done! Now let’s do some Javascript.

When you reach this step you must install Messenger Plus! Live. Then create a new plugin like shown in the picture.

Messenger Plus! Live

In the script window you can create an object of your class and use it as you want! In the middle of the code I have some comments that can help you to understand myFirstPlugin.

var myPlugin; //store object during chat session

var lastSent; //just a trick to prevent an outbound message from being seen as an inbound message. Kind of a Messenger Plus! bug…

function OnEvent_ChatWndCreated(ChatWnd){

    //new chat window -> new plugin object

    myPlugin= new ActiveXObject(“MyFirstPlugin.Plugin”);

}

function OnEvent_ChatWndDestroyed(ChatWnd){

    //in the end print out the log

    Debug.Trace(myPlugin.getFullLog());

}

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind){

    //messageKind == 1 is a user message. Other values means nudges, winks, etc.

    if(MessageKind==1 && lastSent!=Message){

        //get your buddy e-mail. Assumes that you’re not in a group chat

        var e = new Enumerator(ChatWnd.Contacts);

        var email;

        for(; !e.atEnd(); e.moveNext()) {

            var Contact = e.item();

            email= Contact.Email;

        }

        //log you message into the plugin

        myPlugin.addToLog(Messenger.MyEmail,email,Message);

        return Message;

    }else{

        lastSent=“”;

        return Message;

    }

}

//Same stuff as above

function OnEvent_ChatWndSendMessage(ChatWnd,Message){

    var e = new Enumerator(ChatWnd.Contacts);

    var email;

    for(; !e.atEnd(); e.moveNext()) {

        var Contact = e.item();

        email= Contact.Email;

    }

    myPlugin.addToLog(email,Messenger.MyEmail,Message);

    lastSent=Message;

    return Message;

}

In the end enable your plugin and pray that it works :)

One Response to “Messenger Plus! Live and .NET working together”

  1. falta aqui um toque humano, mas aos poucos vou-te dando a volta para pores mais cor nisto lol :D

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Bruno Silva | Powered by Wordpress