From: Wu Nan Date: 2007-12-26T15:17:29+09:00 Subject: Change the MSN Now Playing Text with ruby ------=_Part_7220_16628353.1198649855112 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 #include int main(int argc, char* argv[]) { HWND msnui = NULL; COPYDATASTRUCT msndata; WCHAR * utf16buffer=L"\\0Music\\01\\0{Lalalalalalal}\\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 " 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 ------=_Part_7220_16628353.1198649855112--