Fanatic Live: Msn Messenger 7 Current Playing Song - Fanatic Live

Jump to content

This is not a support forum!

This forum is intended for users to post source they have created and want to share, it is not to be used for asking for source. New topics made here require moderator approval, and questions will be deleted.
  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Msn Messenger 7 Current Playing Song the new code Rate Topic: -----

#1 User is offline   shaneh

  • Nudging is fun!
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 14-February 05

Posted 04 March 2005 - 04:41 AM

roughly...

COPYDATASTRUCT msndata;
#define MSNMusicString L"\\0Music\\0%d\\0%s\\0%s\\0%s\\0%s\\0%s\\0"
#define MSNFormat L"{0} - {1}"
WCHAR buffer[500];
bool bshow = 1;

wsprintfW(buffer, MSNMusicString, bshow, MSNFormat, L"Title", L"Artist", L"Album", L"WMContentID");

HWND msnui = NULL;
msndata.dwData = 0x547;
msndata.lpData = &buffer;
msndata.cbData = (lstrlenW(buffer)*2)+2;
while (msnui = FindWindowEx(NULL, msnui, "MsnMsgrUIManager", NULL))
{
  SendMessage(msnui, WM_COPYDATA, (WPARAM)hwndParent, (LPARAM)&msndata);
}


I am still determining what else can be passed instead of "Music". You can change the format to be "Listening to {0} by {1} on the ablum {2} with id {3}" etc.

You may be able to pass a {4} string as well, though Im not sure what should be there yet.

/edit: made a typo fix.
/edit: fixed the title/artist order.

Take a look at the sourcecode to foo_msn, a foobar2000 plugin, for a real world example. Available at: http://www.myplugins.info

This post has been edited by shaneh: 18 April 2005 - 07:32 AM

0

#2 User is offline   shaneh

  • Nudging is fun!
  • PipPip
  • Group: Members
  • Posts: 17
  • Joined: 14-February 05

Posted 09 March 2005 - 01:43 AM

Note with iTunes, it actually uses the string:

iTunes\0Music\001\0etc\...

Passing:

asdf\0Music\001\0etc..

seems to work as well. Not really sure how everything is handled internally
0

#3 User is offline   psyko

  • Anti-RIAA Fanatic
  • Icon
  • Group: Moderators
  • Posts: 2,372
  • Joined: 07-August 02
  • Location:/usr/bin/root
  • Interests:Skateboarding, Computers, Drums

Posted 09 March 2005 - 11:57 AM

Sweet man! :D You've done a good job with this plugin! :)
0

#4 User is offline   Daniel

  • Live™ n00b
  • Icon
  • Group: Admins
  • Posts: 4,598
  • Joined: 01-February 02
  • Location:New Zealand

Posted 27 March 2005 - 02:56 PM

With the help of CookieRevised, we managed to get something working in VB6:

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Private Type COPYDATASTRUCT
   dwData As Long
   cbData As Long
   lpData As Long
End Type

Private Const WM_COPYDATA = &H4A

Private Sub Form_Load()
    Call SetMusicInfo("Myself", "Debut", "The Song That Never Ends")
End Sub

' eg: Call SetMusicInfo("artist", "title", "album")
' eg: Call SetMusicInfo("artist", "title", "album", "WMContentID")
' eg: Call SetMusicInfo("artist", "title", "album", , "{1} by {0}")
' eg: Call SetMusicInfo("", "", "", , , False)
Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, Optional ByRef r_sWMContentID As String = vbNullString, Optional ByRef r_sFormat As String = "{0} - {1}", Optional ByRef r_bShow As Boolean = True)

    Dim udtData As COPYDATASTRUCT
    Dim sBuffer As String
    Dim hMSGRUI As Long
    
    'Total length can not be longer then 256 characters!
    'Any longer will simply be ignored by Messenger.
    sBuffer = "\0Music\0" & Abs(r_bShow) & "\0" & r_sFormat & "\0" & r_sArtist & "\0" & r_sTitle & "\0" & r_sAlbum & "\0" & r_sWMContentID & "\0" & vbNullChar
    
    udtData.dwData = &H547
    udtData.lpData = StrPtr(sBuffer)
    udtData.cbData = LenB(sBuffer)
    
    Do
        hMSGRUI = FindWindowEx(0&, hMSGRUI, "MsnMsgrUIManager", vbNullString)
        
        If (hMSGRUI > 0) Then
            Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))
        End If
        
    Loop Until (hMSGRUI = 0)

End Sub


Note: the \0 bits are not actually null bytes, they are really sent like that at procotol level, as you can see in the C++ code it has \\0, which is escaping the slash and it is not recognised as a \0 to create a null byte.

Read all the comments here also: http://forums.msnfan...showtopic=11226

Edit: SetMusicInfo function modded a bit by Cookie, comments and extra function args.
0

#5 User is offline   CookieRevised

  • I'm a new version
  • Icon
  • Group: Valued Members
  • Posts: 71
  • Joined: 17-December 03
  • Location:Belgium

Posted 27 March 2005 - 03:03 PM

shaneh, on Mar 4 2005, 05:41 AM, said:

roughly...

msndata.cbData = (lstrlenW(buffer)*2)+2;
+2 ? That can't be right, is it? Rather add a null character at the end of the string, instead of +2 in the length calculation as you will never known what follows the string/buffer in memory (see VB code). Or does C++ automatically and always add a null character in memory after the string buffer (if so, then I still don't understand why +2 as surely the null character is part of the string then)?

Another note: after experimenting with Daniel, we found out that the total length of the string/buffer can only be a maximum of 256 (wide) characters (=512 bytes) long, not 500 (=1000 bytes) or whatever.

This post has been edited by CookieRevised: 27 March 2005 - 04:47 PM

0

#6 User is offline   Volv

  • I'm back in the 80's!
  • PipPipPipPip
  • Group: Members
  • Posts: 95
  • Joined: 16-November 04

Posted 28 March 2005 - 08:55 AM

I'd just like to report a small typo in Daniels post:

' eg: Call SetMusicInfo("artist", "title", "album")
Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, Optional ByRef r_sWMContentID As String = vbNullString, Optional ByRef r_sFormat As String = "{0} - {1}", Optional ByRef r_bShow As Boolean = True)


You've got 'SetMusicInfo("artist", "title", album") in the example while the sub's parameters are actually artist, album, title (note the different order).

And just to make it easier to fix without checking, its the example which is incorrect :)

This post has been edited by Volv: 28 March 2005 - 09:00 AM

0

#7 User is offline   Doggie

  • I'm Watching You -_-'
  • Icon
  • Group: Admins
  • Posts: 5,325
  • Joined: 04-February 02
  • Gender:Male
  • Location:Australia
  • Interests:Things that are interesting?

Posted 07 April 2005 - 12:52 AM

well i wrote my own for protocol usage:
   Public Function SetCurrentMedia(ByVal sSong As String, ByVal sAlbum As String, ByVal sArtist As String)
        Dim Message As String
        Dim EndResult As String
        'Store the message into a string to get correct length 
        Message = "<Data><PSM></PSM><CurrentMedia>\0Music\01\0{0} - {1}\0" & sSong & "\0" & sArtist & "\0" & sAlbum & "\0\0</CurrentMedia></Data>"
        'Send the EndResult to set the command
        EndResult = "UUX " & TransactionID() & " " & Len(Message) & vbCrLf & Message
        sck.Write(EndResult)
    End Function

As you can see, you can define your own album,music and artist :P
Also to make sure it gets sent, you should get back "UUX transactionid 0"
Enjoy
0

#8 User is offline   psyko

  • Anti-RIAA Fanatic
  • Icon
  • Group: Moderators
  • Posts: 2,372
  • Joined: 07-August 02
  • Location:/usr/bin/root
  • Interests:Skateboarding, Computers, Drums

Posted 07 April 2005 - 01:04 AM

Good sh*t doggie! :)
0

#9 User is offline   BadAngel

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 08-April 05

Posted 08 April 2005 - 10:14 AM

i tried to make this code to work in vb.net (2003) but i was not successfull. can someone with the necessary knowledge convert this code for .net?

thanks
0

#10 User is offline   Doggie

  • I'm Watching You -_-'
  • Icon
  • Group: Admins
  • Posts: 5,325
  • Joined: 04-February 02
  • Gender:Male
  • Location:Australia
  • Interests:Things that are interesting?

Posted 08 April 2005 - 02:10 PM

this is in .net :|
0

#11 User is offline   BadAngel

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 08-April 05

Posted 08 April 2005 - 05:39 PM

i was talking abt the original code doggie. i tried your own code but i couldnt make it work, what is sck.Write ?

as i understand it, i need to send EndResult with the SendMessage function as in the other code..but EndResult is string and not integer as equired by the api.

could you give me detailed instructions on how to make it work?

thanks
0

#12 User is offline   Doggie

  • I'm Watching You -_-'
  • Icon
  • Group: Admins
  • Posts: 5,325
  • Joined: 04-February 02
  • Gender:Male
  • Location:Australia
  • Interests:Things that are interesting?

Posted 08 April 2005 - 11:29 PM

no no no. my function is for protocol use, it wont work with api calls
0

#13 User is offline   BadAngel

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 08-April 05

Posted 09 April 2005 - 03:37 AM

hmm ok... can u help me produce working VB.NET code to do this? the vb6 code uses some pointer stuff that i cannot convert to vb.net (and the upgrade wizard cannot convert them)..

thanks
0

#14 User is offline   BadAngel

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 08-April 05

Posted 09 April 2005 - 05:34 AM

ok i managed to convert it. here goes:

   Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer

    Public Function VarPtr(ByVal o As Object) As Integer
        Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)
        Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32

        GC.Free()
        Return ret
    End Function

    Private Structure COPYDATASTRUCT
        Dim dwData As Integer
        Dim cbData As Integer
        Dim lpData As Integer
    End Structure

    Private Const WM_COPYDATA As Short = &H4AS

    Public Sub SetMusicInfo(ByRef r_sArtist As String, ByRef r_sAlbum As String, ByRef r_sTitle As String, Optional ByRef r_sWMContentID As String = vbNullString, Optional ByRef r_sFormat As String = "{1} - {0}", Optional ByRef r_bShow As Boolean = True)

        Dim udtData As COPYDATASTRUCT
        Dim sBuffer As String
        Dim hMSGRUI As Integer

        'Total length can not be longer then 256 characters!
        'Any longer will simply be ignored by Messenger.
        sBuffer = "\0Music\0" & System.Math.Abs(CInt(r_bShow)) & "\0" & r_sFormat & "\0" & r_sArtist & "\0" & r_sTitle & "\0" & r_sAlbum & "\0" & r_sWMContentID & "\0" & vbNullChar

        udtData.dwData = &H547S
        udtData.lpData = VarPtr(sBuffer)
        udtData.cbData = Len(sBuffer) * 2

        Do
            hMSGRUI = FindWindowEx(0, hMSGRUI, "MsnMsgrUIManager", vbNullString)

            If (hMSGRUI > 0) Then
                Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))
            End If

        Loop Until (hMSGRUI = 0)

    End Sub


to use it:
               'Displays song info
                Call SetMusicInfo("Artist", "Album", "Song")

                'Clear song info
                Call SetMusicInfo("", "", "", , , False)



thanks to the original authors (Look above :P)
0

#15 User is offline   hilbert

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 10-April 05

Posted 10 April 2005 - 03:41 PM

thanks shaneh for the code...great work
But...I have tested it with MSN Messenger 7 (final version) and doesn´t work. Also, the toaster doesn´t work with my MSN. is there any kind of trouble with this MSN version?
thanks
0

#16 User is offline   Kryton

  • One post hero!
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 11-April 05

Post icon  Posted 11 April 2005 - 11:03 PM

This is my first post but down to business anyway.

I disassembled MSN Messenger and looked at the string table. Turns out Music isn't the only identifier you can use, you can also use "Office","Games","Empty" or the known "Music" and display information. These just change the icon that shows from headphones to a chess piece, office logo etc. They also stop the highlighting behaviour that links to the MSN Music Service (shameless promotion M$).

Another small but trivial fact (probably already known) is you can pass an aribtrary amount of parameters and index them in the format string to do some interesting things. Just seperate them with \0's, the WMContentID field doesn't appear to affect anything (though the iTunes code sends iTunes instead? Perhaps WMContentID triggers the auto-linkage? I haven't explored this avenue yet).

I have also ported the code to Delphi and pasted it below.

function CurrentPlay(ARTIST,ALBUM,TITLE:string)
var
  handleMSN:THandle;
  structCopy:TCopyDataStruct;
  stringBuffer:array [0..127] of WideChar;
begin

  // Flush the array.
  FillChar(stringBuffer,SizeOf(stringBuffer),#0);

  // The first Music can be changed to Games, Office, or Empty.
  StringToWideChar('\0Music\0'+'1'+'\0'+'{0} - {1}'+'\0'+ARTIST+'\0'+TITLE+'\0'+ALBUM+'\0'+'WMContentID'+#0,@stringBuffer[0],128);

  // Set up the structure to hold the WM_COPYDATA and set the values.
  FillChar(structCopy,SizeOf(TCopyDataStruct),#0);
  with structCopy do
  begin
    cbData:=SizeOf(stringBuffer);
    dwData:=$547;
    lpData:=@stringBuffer[0];
  end;

  // Iterate through (for poloygamy) the MSN windows sending WM_COPYDATA to each
  handleMSN:=FindWindowEx(0,0,'MsnMsgrUIManager',nil);
  while handleMSN <> 0 do
  begin
    SendMessage(handleMSN,WM_COPYDATA,0,Integer(@structCopy));

    handleMSN:=FindWindowEx(0,handleMSN,'MsnMsgrUIManager',nil);
  end;

end;


Gimme a shout if you have any problems.

- Kryton
0

#17 User is offline   Morpheo17

  • One post hero!
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 28-June 03

Posted 12 April 2005 - 09:51 PM

shaneh, on Mar 4 2005, 05:41 AM, said:

roughly...

COPYDATASTRUCT msndata;
#define MSNMusicString L"\\0Music\\0%d\\0%s\\0%s\\0%s\\0%s\\0%s\\0"
#define MSNFormat L"{0} - {1}"
WCHAR buffer[500];
bool bshow = 1;

wsprintfW(buffer, MSNMusicString, bshow, MSNFormat, L"Artist", L"Title", L"Album", L"WMContentID");

HWND msnui = NULL;
msndata.dwData = 0x547;
msndata.lpData = &buffer;
msndata.cbData = (lstrlenW(buffer)*2)+2;
while (msnui = FindWindowEx(NULL, msnui, "MsnMsgrUIManager", NULL))
{
  SendMessage(msnui, WM_COPYDATA, (WPARAM)hwndParent, (LPARAM)&msndata);
}


I am still determining what else can be passed instead of "Music". You can change the format to be "Listening to {0} by {1} on the ablum {2} with id {3}" etc.

You may be able to pass a {4} string as well, though Im not sure what should be there yet.

/edit: made a typo fix.
View Post



This code not work well.
Error of compilation:
musikPlugin.cpp(137) : error C2664: 'FindWindowExW' : no se puede convertir el parámetro 3 de 'const char [17]' a 'LPCWSTR'


I have fix this error with:
while (msnui = FindWindowEx(NULL, msnui, (LPCWSTR)"MsnMsgrUIManager", NULL))

but not work too :( :(

How i can fix this code???

Thanks saneh

PD: Sorry my english
0

#18 User is offline   hilbert

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 10-April 05

Posted 17 April 2005 - 07:25 PM

@Morpheo17
you can try with _T data type mapping. The code works perfectly, thanks shane
0

#19 User is offline   tomalak

  • I'm getting there
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 11-April 05

Posted 25 April 2005 - 09:22 PM

For anyone interested, the 'API' described here by the very helpful people has been adapted for use as a mIRC DLL: http://www.deep-space-5.org/msnmusic/
0

#20 User is offline   Liiam

  • :pray:
  • Icon
  • Group: Valued Members
  • Posts: 455
  • Joined: 23-March 05

Posted 26 April 2005 - 07:24 AM

its always nice to see msn programming branching out :)
0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users