Wednesday, June 08, 2005 12:01 PM bart

Personal messages in MSN 7.0 with C#

MSN Messenger 7.0 introduced the notion of a personal message, a small message that's not poisening your nickname if you want to share something with your contacts. Quite a lot of people are using this nowadays to put their favorite quote over there or just to share a random thought. Beside of the manual entry of a personal message, such a message can be automatically generated as well by an external application. This way, it's possible to show your friends "what you're listening to". Basically, a music player such as Windows Media Player does some IPC (Inter-Process Communication) to MSN Messager using the Win32 API every time the song which is currently playing changes. The nice thing is that you can write your own plug-in using some relatively simple C#:

  1. Create a Windows Forms application and open the source code view for the Form1.cs form.
  2. Add the namespace:

    using System.Runtime.InteropServices;

  3. In the class definition, put two DllImports as follows:

    [DllImport("user32", EntryPoint="SendMessageA")]
    private static extern int SendMessage(int Hwnd, int wMsg, int wParam, int lParam);

    [DllImport("user32", EntryPoint="FindWindowExA")]
    private static extern int FindWindowEx(int hWnd1, int hWnd2, string lpsz1, string lpsz2);

  4. Import the WM_COPYDATA constant for the Win32 API calls:

    private
    const short WM_COPYDATA = 74;

  5. Declare a struct for the IPCs we're going to perform:

    public struct COPYDATASTRUCT
    {
         public int dwData;
         public int cbData;
         public int lpData;
    }

    public COPYDATASTRUCT data;

I forgot this function in my initial post:

public int VarPtr(object e)
{
     GCHandle GC = GCHandle.Alloc(e, GCHandleType.Pinned);
     int gc = GC.AddrOfPinnedObject().ToInt32();
     GC.Free();
     return gc;
}

Now the plumbing is done, we can start implementing the IPC-method to MSN. The only thing you need to know is the identification string of the MSN Messager 7 application, which is "MsnMsgrUIManager". The code for the method is displayed below:

private void SendMSNMessage(bool enable, string category, string message)
{
    
string buffer = "\\0" + category + "\\0" + (enable ? "1" : "0") + "\\0{0}\\0" + message + "\\0\\0\\0\\0\0";
    
int handle = 0;

     data.dwData = 0x0547;
     data.lpData = VarPtr(buffer);
     data.cbData = buffer.Length * 2;

     handle = FindWindowEx(0, handle, "MsnMsgrUIManager",
null);
     if (handle > 0)
          SendMessage(handle, WM_COPYDATA, 0, VarPtr(data));
}

Basically, this method takes three parameters. The first indicated whether to display a message or not. The second one contains a category which can be "Office", "Games" or "Music". The last parameter takes the message itself. Assuming MSN Messenger 7.0 is running on your machine (in the current user session), a call to:

SendMSNMessage(true, "Office", "Hello World");

would put "(Office logo) Hello World" behind your nickname in MSN. By calling:

SendMSNMessage(false, "Office", "");

the message will be gone and the old personal message of MSN will be restored. Note that for this to work, you should put on the feature "What I'm listening to" in MSN 7.0. It's this feature which listens to incoming IPC messages in order to display them.

Finally a note on how personal messages are sent to your friends. In contrast to your nickname on MSN, which is centrally stored on the MSN Directory Servers, the Personal Message is not sent to Microsoft and is shared with your friends in a peer-to-peer fashion. So, when someone is viewing his/her MSN contact list or when someone is chatting with you, the message will be send to that person. The same holds for your display picture, which is also sent peer-to-peer. So, you don't have to worry about privacy issues ("oh no, Microsoft can see this message" simply doesn't hold) and as the matter in fact, storing the personal message in a directory service would be one of the worst things to do. As the personal message can change quite often (assume you're playing a CD of 60 minutes with 100 tracks :o, or just write a program using the displayed code to change the message every second or so) this would be the ideal feature to create a DDoS attack on the MSN servers. That's in my opinion one of the reasons (beside privacy, you don't want Microsoft to know what music you're playing) why personal messages are computer-bound and not MSN-member-bound.

Using the displayed code, I created a simple countdown for product releases that puts something like "Countdown to XYZ - D days, H hours, M minutes, S seconds" behind my name on MSN. Note however, that the refresh speed (peer-to-peer) is somewhere between 5 and 10 seconds on the average, so your contacts won't see a smooth countdown in seconds.

Have fun!

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under: ,

Comments

# Change the MSN personal message with c#

Wednesday, June 08, 2005 2:32 PM by TrackBack

Having just installed Messenger 7.0  (I use it a ton for work,  its easier than the phone sometimes)...

# re: Personal messages in MSN 7.0 with C#

Friday, June 10, 2005 9:19 AM by bart

Thanks for the idea, but that code doesn't seem to be safe for 64-bit. Try http://www.pinvoke.net/ for your DLL Imports, as they're mostly correct.

Basically, use IntPtr for handles and pointers.

I also think it can be done with Marshal instead of VarPtr (is that from VB?).

# re: Personal messages in MSN 7.0 with C#

Monday, June 27, 2005 8:42 PM by bart

i want some ideas for the msn messenger personal message but nothing has cum up in the piece of writing

# re: Personal messages in MSN 7.0 with C#

Tuesday, June 28, 2005 4:16 PM by bart

Odd... It doesn't work here either on my 64bit machine. However, I'm running an i386 build of XP, not the 64bit. I thought it'd map it like it would on i386...?

# re: Personal messages in MSN 7.0 with C#

Thursday, July 14, 2005 2:56 AM by bart

i would like to get msn message 7.0 how do i get it please email me if u can d=send it to me at bad_gurl169@hotmail.com

# re: Personal messages in MSN 7.0 with C#

Thursday, July 14, 2005 5:27 PM by bart

very good sometimes

# re: Personal messages in MSN 7.0 with C#

Saturday, July 16, 2005 8:52 PM by bart

i need some help wiv my personal message

# re: Personal messages in MSN 7.0 with C#

Tuesday, July 19, 2005 11:10 PM by bart

Works great for me. What I'd like to do is make it clickable though so I can share URLs with it. Not sure if that'd work though.

# re: Personal messages in MSN 7.0 with C#

Tuesday, August 23, 2005 11:23 PM by bart

Hey um..for the music thing. I click the "show what i'm listening to" and listen to music in my Windows Media Player..yet it still does not show on my msn. Odd thing is it used to fine, it just started doing this? this there something else you need to do or something?

Thanks

# re: Personal messages in MSN 7.0 with C#

Wednesday, August 24, 2005 3:36 PM by bart

Can't work it out!
can someone teach me that...

# re: Personal messages in MSN 7.0 with C#

Thursday, September 01, 2005 10:15 AM by bart

Jenna, all you do is first on msn click on display what i am listeing to, then if you are using WMP open it then at the top click on tools, then pug-ins then just click on MSN messenger plug-in. Now whenever you listen to something in WMP it will be displayed as your personal message. If you want help for using it for something like Itunes just post on here :D

# re: Personal messages in MSN 7.0 with C# (cont'd) - Integrating Outlook Calendar

Wednesday, October 12, 2005 4:47 PM by TrackBack

# MSN API: Sådan skifter du din "personal message" med .net

Wednesday, March 22, 2006 10:09 PM by Kenneth Auchenberg

Hej folkens
En fra min klasse skulle bruge en lille konsol-app hvor han fra command prompt kunne ændre...

# MSN API: Sådan skifter du din "personal message" med .net

Wednesday, March 22, 2006 10:12 PM by Kenneth Auchenberg

Hej folkens
En fra min klasse skulle bruge en lille konsol-app hvor han fra command prompt kunne ændre...

# MSN API: Sådan skifter du din "personal message" med .net

Wednesday, March 22, 2006 10:14 PM by Kenneth Auchenberg

Hej folkens
En fra min klasse skulle bruge en lille konsol-app hvor han fra command prompt kunne ændre...

# FVN Blog » Blog Archive » ??????MSN/WLM Add-in?????????

# Be Recursive » Blog Archive » Interacting with Napster through C#

Pingback from  Be Recursive  » Blog Archive   » Interacting with Napster through C#

# Shoutt: Mensaje personal rotativo en MSN | guianze

Tuesday, February 24, 2009 10:13 AM by Shoutt: Mensaje personal rotativo en MSN | guianze

Pingback from  Shoutt: Mensaje personal rotativo en MSN | guianze

# msn pm pictures

Monday, June 06, 2011 2:06 PM by msn pm pictures

Pingback from  msn pm pictures

# dball pills

Saturday, December 17, 2016 5:07 AM by dball pills

Pingback from  dball pills