# Change the MSN Now Playing Text with ruby

**URL:** <https://www.ruby-forum.com/t/change-the-msn-now-playing-text-with-ruby/124182>\
**Category:** Ruby\
**Created:** [December 26, 2007, 7:18am UTC](https://www.ruby-forum.com/t/change-the-msn-now-playing-text-with-ruby/124182 "2007-12-26T07:18:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wu\_Nan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/898d66/32.png) [@Wu\_Nan](https://www.ruby-forum.com/u/Wu_Nan)\
**Post date:** [December 26, 2007, 7:18am UTC](https://www.ruby-forum.com/t/change-the-msn-now-playing-text-with-ruby/124182/1 "2007-12-26T07:18:18Z")

</div>

Hi,

I just write a ruby program to change the MSN Now Playing Text,  
however it’s not working, could anybody check it for me that why it’s  
not  
working.

I also wrote it in VC, and it works well.

Here is the codes:  
First VC:

#include “stdafx.h”  
#include “windows.h”  
#include \<string.h\>  
#include

int main(int argc, char\* argv[])  
{  
HWND msnui = NULL;  
COPYDATASTRUCT msndata;  
WCHAR \*  
utf16buffer=L"\0Music\01\0{Lalalalalalal}\0\0\0\0\0\<file://0Music//01//0%7BLalalalalalal%7D//0//0//0//0//0\>  
";  
msndata.dwData = 0x547;  
msndata.lpData = (void\*)utf16buffer;  
msndata.cbData = lstrlenW(utf16buffer)\*2+2;  
while (msnui = FindWindowEx(NULL, msnui, “MsnMsgrUIManager”, NULL))  
{  
SendMessage(msnui, WM\_COPYDATA, (WPARAM)NULL,(LPARAM)&msndata);  
}  
return 0;  
}

* * *

Then Ruby:

require ‘Win32API’  
require ‘dl/import’  
require ‘dl/struct’

module Win32  
extend DL::Importable

```
dlload 'user32'

CopyData = struct ["DWORD dwData","DWORD cbData","PVOID lpData",]

WM_COPYDATA = 0x004a

```

#extern “BOOL SendMessage(HWND, UINT, WPARAM, LPARAM)”  
findWindow=Win32API.new(“user32.dll”, “FindWindow”, [‘P’,‘P’], ‘N’)  
Result=findWindow.call(“MsnMsgrUIManager”,0)

str  
="\0Music\01\0{test}\0\0\0\0\0\<file://0Music//01//0%7Btest%7D//0//0//0//0//0\>  
"  
ostr = “\0” \* 256  
multiByteToWideChar =Win32API.new  
(‘kernel32’,‘MultiByteToWideChar’,[‘L’,‘L’,‘P’,‘L’,‘P’,‘L’],‘L’)  
multiByteToWideChar.Call(0,0,str,-1,ostr,128)

#t=(ostr.strip + “\0”).unpack(“S\*”).pack(“U\*”)

cds = CopyData.malloc  
cds.dwData = 0x547  
cds.cbData = 256  
cds.lpData = ostr

SendMessage=Win32API.new(“user32.dll”, “SendMessage”,  
[‘L’,‘L’,‘L’,‘P’],  
‘L’)  
SendMessage.Call(Result, 0x004a, 0, cds.to\_ptr)

end
