What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Skype & Live Messenger » Change Now Playing From Visual Basic .NET

Change Now Playing From Visual Basic .NET
Author: Message:
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
O.P. Change Now Playing From Visual Basic .NET
I've tried this code in VS 2003 and 2005, and VB 2008. It doesn't work in any of them.

Source: http://forums.fanatic.net.nz/lofiversion/index.php/t11311.html

code:
Imports System.Runtime.InteropServices

Module mdlMain
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd As Integer, _
        ByVal hWndChild As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    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 Const WM_COPYDATA As Short = &H4AS

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

    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

    Public Sub SetMSNNowPlaying(ByVal sTitle As String, ByVal sArtist As String)
        Dim sOutput As String = "\0Music\01\0" + sTitle + " - " + sArtist + "\0\0\0\0\0" + vbNullChar
        Dim udtData As COPYDATASTRUCT
        Dim iMessengerHWnd As Long = 0

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

        Do
            iMessengerHWnd = FindWindowEx(0, iMessengerHWnd, "MsnMsgrUIManager", vbNullString)
            If iMessengerHWnd > 0 Then
                SendMessage(iMessengerHWnd, WM_COPYDATA, 0, VarPtr(udtData))
            End If
        Loop Until iMessengerHWnd = 0
    End Sub
End Module

Using Debug statements, I can see that the Messenger Window is found, and that the SendMessage function is returning 0 - which I assume means it went okay. But nothing happens to my PSM. Whats up with that?

Also, for further debugging - the sOuput string EXACTLY matches that passed by -dt-'s Now Playing Script, as does the hWnd of the Window. So I would imagine that the cock up is to do with the implementation of VarPtr. Anyone any ideas?
[Image: AndrewsStyle.png]
11-22-2007 02:59 PM
Profile E-Mail PM Web Find Quote Report
SuNcO
Full Member
***

Avatar

Posts: 128
Reputation: 6
45 / Male / Flag
Joined: Jan 2005
RE: Change Now Playing From Visual Basic .NET
On the same forum i see the answer (first i try to convert my own code but then i found it.. so i adapt to make it work)

code:
Public Class Form1

    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
    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 Structure COPYDATASTRUCT
        Dim dwData As Integer
        Dim cbData As Integer
        Dim lpData As Integer
    End Structure

    Private Const WM_COPYDATA As Short = &H4AS

    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 Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PonerMusica(TextBox1.Text)
    End Sub

    Public Sub PonerMusica(ByVal Texto)
        'Public Sub PonerMusica(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}", Optional ByRef r_bShow As Boolean = True)
        Dim udtData As COPYDATASTRUCT
        Dim sBuffer As String
        Dim hMSGRUI As Integer

        'sBuffer = "\0Music\0" & 1 & "\0" & "{0}" & "\0" & Texto & "\0" & "" & "\0" & "" & "\0" & vbNullString & "\0" & vbNullChar
        sBuffer = "\0Music\0" & System.Math.Abs(CInt(True)) & "\0" & "{1} - {0}" & "\0" & Texto & "\0" & "" & "\0" & "" & "\0" & vbNullString & "\0" & vbNullChar

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

        Do
            ' Buscamos la seccion del Msn donde se pone la musica

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

            ' La encontramos ?
            If (hMSGRUI > 0) Then
                ' Esta es la linea que envia el Texto
                Call SendMessage(hMSGRUI, WM_COPYDATA, 0, VarPtr(udtData))
            End If
        Loop Until (hMSGRUI = 0)
    End Sub
End Class


Source: http://forums.fanatic.net.nz/index.php?s=&showtop...w=findpost&p=83457

This post was edited on 11-23-2007 at 04:13 AM by SuNcO.
11-23-2007 04:12 AM
Profile PM Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
Joined: Jan 2003
RE: Change Now Playing From Visual Basic .NET
dt's now playing script is dodgy.

try this:

"WMP\0Music\01\0{0} - {1}\0Song Name\0Artist Name\0Album Name\0{00000000-0000-0000-0000-000000000000}\0"
Spoiler:
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
11-23-2007 06:02 AM
Profile PM Web Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
O.P. RE: Change Now Playing From Visual Basic .NET
Sun: That's the exact same functions, etc, that I had, except it's got the variable names and comments in Spanish.

ShawnZ: Thanks for that... but it doesn't do anything either.

What's the name of the program you can use to monitor if a message is being sent to a process?
[Image: AndrewsStyle.png]
11-23-2007 06:07 PM
Profile E-Mail PM Web Find Quote Report
SuNcO
Full Member
***

Avatar

Posts: 128
Reputation: 6
45 / Male / Flag
Joined: Jan 2005
RE: Change Now Playing From Visual Basic .NET
The code i give you works on VB 2005, i test it with Msn 8.5

The code you put here is for VB6 (VarPtr and LenB not exist on VB 2005)

What error you get ? You copy/paste mine or just see that is "the same" ?

This post was edited on 11-23-2007 at 06:29 PM by SuNcO.
11-23-2007 06:27 PM
Profile PM Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
O.P. RE: Change Now Playing From Visual Basic .NET
There is no error. It's just that nothing happens. And the code in my post is the exact same as yours, with different variable names - it uses Import for example, which is not available in VB6.

The post you linked was the exact same one I quoted, just mines was LoFi. There are two VB codes on that page, one is for VB6, the one I quoted .NET.
[Image: AndrewsStyle.png]
11-23-2007 06:34 PM
Profile E-Mail PM Web Find Quote Report
SuNcO
Full Member
***

Avatar

Posts: 128
Reputation: 6
45 / Male / Flag
Joined: Jan 2005
RE: Change Now Playing From Visual Basic .NET
If after check the code still not working, maybe is because you have not enabled the option "Show what im listen to" on Msn

As i say, works fine here.. copy & paste all please

This post was edited on 11-23-2007 at 07:32 PM by SuNcO.
11-23-2007 07:29 PM
Profile PM Find Quote Report
andrewdodd13
Senior Member
****

Avatar
Oh so retro

Posts: 870
Reputation: 16
34 / Male / Flag
Joined: Jan 2005
O.P. RE: RE: Change Now Playing From Visual Basic .NET
quote:
Originally posted by SuNcO
If after check the code still not working, maybe is because you have not enabled the option "Show what im listen to" on Msn

As i say, works fine here.. copy & paste all please
That wasn't the problem. COPYDATASTRUCTURE somehow was converted to long from Integer when I moved my project from VB 2005 to 2008. Stupid VB.

Thanks for the help.
[Image: AndrewsStyle.png]
11-23-2007 07:52 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On