From: timsuth@... (Tim Sutherland) Date: 2004-12-01T06:17:47+09:00 Subject: Re: Windows SendMessage In article <1101833542.8224.33.camel@comp.rapiddsl.net>, Guillaume Marcais wrote: >Has anyone ever tried to send messages between applications using the >Windows messaging system (SendMessage call). Yes, I have done this. http://www.windows-spy.com/ is a useful tool for seeing what messages are passed under the covers when the user does the "usual thing". >Given my little knowledge >of Windows, I started with Ruby and Win32API (hopefully it is achievable >that way). DL is nicer. (See below!) >I am trying to discuss with the pageant program from PuTTy to get the >keys. I recompiled pageant with debugging enable so I can see the >request coming in. It works with PuTTy. But with my Ruby app mimicking >what PuTTy does to get the keys, it seems that pageant doesn't even get >the message. > >The code is given in the attachement.The stuff about the file mapping >can be ignored. The SendMessage call returns 0 and pageant doesn't >display any debugging information, as if no message whatsoever was ever >received. > >Is there any initialization to be done for Windows to agree to dispatch >my message? No initialisation is needed that is not already done by Ruby. [...] >require 'Win32API' [...] > cds = [AGENT_COPYDATA_ID, mapname.size, mapname].pack("NNp") 'N' means network byte order. Use 'L' for native byte order. Since you are using Windows, you are probably using x86 (little-endian) while network byte order is big-endian. If you use the 'dl' library you don't need to worry about this sort of thing. e.g. can just do (untested) require 'dl/import' require 'dl/struct' module Win32 extend DL::Importable dlload 'user32' CopyData = struct [ 'ULONG *dwData', 'DWORD cbData', 'PVOID lpData' ] WM_COPYDATA = 1234 # whatever it is extern 'BOOL SendMessage(HWND, UINT, WPARAM, LPARAM)' end cds = CopyData.malloc cds.dwData = Win32::AGENT_COPYDATA_ID cds.cbData = mapname.size cds.lpData = mapname Win32::sendMessage(@win, Win32::WM_COPYDATA, nil, cds.to_i) puts("Now isn't that easy :-)")