CodeSnippet: Setting WLM Status
edit: weird wordpress error made this private rather than published, oops.
Given I'm now a MSP who isn't able to do the usual running of sessions, I thought I'd write some blog posts aimed at sharing code/techniques to achieve some coolish things. The first of which will cover how I set the custom status in Windows Live Messenger.
Requirements
- Windows Live Messenger (v8+ should work) with "Show What I'm Listening To" enabled
- Visual Studio (C# Express or greater)
Introduction
Windows Live Messenger (WLM) has the ability to set status messages in two forms, "Personally Messages" (PSMs) where the user sets their status themselves, or "Now Playing" (NPM) messages which can be set programmatically and will be the the focus of this article. While you can set PSMs programmatically, it isn't nearly as interesting, and has some side effects (such as overwriting the original PSM).
Windows Media Player has a "Now Playing" plugin which sets the NPM to the song currently being played. Similar plugins exist for other media players such as WinAMP. There are other uses, such as letting friends know what games you're playing.
How it works

WLM "listens" to Dynamic Data Exchanges over the Windows Messaging Layer; that is, external programs (or addins) pass a message to WLM which then sets the status itself. There isn't a specific managed method for DDE, so Platform Invoke (P/Invoke) is needed. PInvoke allows you to call unmanaged functions within managed code. If you haven't specifically used PInvoke before, it can look a little weird, so here's an example
using System.Runtime.InteropServices;[DllImport("user32.dll", SetLastError = true)] private static extern int FindWindow(String lpClassName, String lpWindowName);
This would then allow us to use the function FindWindow from the user32.dll. Our little application uses functions from User32.dll, FindWindow, FindWindowEx, and SendMessage. FindWindowEx finds the WLM "Window" so it know where to send the message, and SendMessage (funnily enough) sends the message.
WLM requires a specific format of the, but within that format there is a bit of wriggle room. You get to send a "format" parameter, which can look like "I'm playing {0} by {1}" where {0} and {1} represent the next two parameters.
I've attached the source code, which includes a sample application, for changing the NPM message. It's all fairly straight forward so there really isn't much more I can write in this article.
Credits
- Code is based off VB.NET/VB6/C++ code found at http://forums.fanatic.net.nz/index.php?showtopic=11311
Notes
Lots of applications still use DDE despite it being "superseded" by other communication techniques. I'll come back to DDE in another article, and look at the alternatives.



