Monthly Archives: December 2006

Windows Live Messenger Add-Ins

When software applications do what they are advertised to do users are happy (generally), but what if you want to do more? Thats where you generally start looking for some method to extend the application. Not every application will allow this, but Windows Live Messenger (WLM) is one that does (at least currently with version 8.0). How, you ask? By writing your very own Add-In with the Messenger Add-In API …

WLM only offers this one API (Application Programming Interface), so it’s not like Microsoft Excel where you have a vast array to pick from (i.e. .NET APIs, C APIs, COM Automation, VBA and XLM). You do get to pick a language that supports .NET and then proceed with the following:

  1. Download and install the .Net 2.0 SDK . This is a minimum requirement. You can also use Visual Studio .NET 2005, or Visual Studio Express (which is a free download), both of which come with the .NET 2.0 SDK.
  2. Write your Add-In. Compile and get the DLL. Full instructions, along with the special reg-key to set, and what to call your DLL to make things work are on MSDN .
  3. Add the Add-In to Windows Live Messenger.

The code is simple enough. Below is an example of an Add-In that updates your personal status message every few seconds to show how long you have been online.

using System;
using System.Timers;
using Microsoft.Messenger;
namespace WLM
{
  public class CounterAddIn : IMessengerAddIn
  {
    static MessengerClient m_client;
    static int m_cSeconds;
    Timer m_timer;

    void IMessengerAddIn.Initialize(MessengerClient client)
    {
      m_client = client;
      m_client.AddInProperties.FriendlyName = "CounterAddIn";
      m_cSeconds = 0;
      m_timer = new Timer(3000);
      m_timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
      m_timer.Enabled = true;
    }

  private static void OnTimedEvent(object source, ElapsedEventArgs e)
  {
    m_cSeconds += 3;
    m_client.AddInProperties.PersonalStatusMessage = "Online for " + m_cSeconds.ToString() + " seconds.";
    }
  }
}

You can also do things such as change your personal image, status, or even respond to users messages (although users always know that the Add-in is running) with automated replies.

One important step is setting the magic registry key such that Messenger lets you add your own custom Add-In. When the key is set correctly Messenger provides controls on its Options page for Add-In support.

Key: HKEY_CURRENT_USER\Software\Microsoft\MSNMessenger\AddInFeatureEnabled

Value: DWORD set to “1” to enable, and “0” to disable Add-Ins.

Manual vs automatic memory management

Good memory management is essential for writing software applications that perform well. If the application takes too long to start or frustrates you as it completes operations, it doesn't make for a good experience. And there are many factors such as response time, working set, and hardware requirements to consider when dealing with performance. However memory management is a key ingredient, and deciding between manual and automatic systems can make a big difference.

This is such a large topic. Where should I start? …

Lets start with some definitions. Manual memory management is when the programmer manually controls the lifetime of allocated memory by specifically allocating and freeing it in a deterministic fashion. Alternatively, automatic memory management tries to determine what memory is no longer used and frees it automatically instead of relying on the programmer to identify it. Automatic memory management is sometimes referred to as Garbage Collection (GC), however "garbage" could be defined as anything, so the term is a little vague. GC often refers to tracing garbage collection, one form of automatic memory management. Reference counting is an alternative automatic memory management method (when you Release an object it isn't necessarily freed, it all depends on the reference count, so as a consumer you do not control memory deallocation). The choice here is mostly independent of programming language. There are some languages that support manual management (such as C, C++), others that support automatic management with tracing GCs (such as Java, and C#), and others still that support both (like D).

So which one is better? Well the truth is that it all depends. There are many pros and cons to each method (discussed at length on wikipedia). In the end you have to pick the solution based on your specific requirements. However today lets talk about performance in particular. If you have some crazy high performance requirements (perhaps a real-time application), what do you do? …. you get more control.

By using manual memory management you are gaining more control over when memory is allocated and deallocated, giving you, the developer, more control over how to deal with it. You can then be mindful of such things as memory locality, consumption in tight loops, and memory reuse, while avoiding indeterministic deallocation (tracing garbage collectors). You can still have enough control with automatic memory management if you stick with ref counting as a means to control memory/object lifetime. However there is a cost to be paid for these advantages, mostly in development difficulty – the more control you have, the more likely you are to make mistakes (mistakes here lead to memory leaks). And mistakes are bugs.. some bad, some really bad.