Windows SendMessage

Has anyone ever tried to send messages between applications using the
Windows messaging system (SendMessage call). Given my little knowledge
of Windows, I started with Ruby and Win32API (hopefully it is achievable
that way).

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?

Thanks for your help,
Guillaume.

pageant.rb (3.32 KB)

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 :-)")

In article <1101833542.8224.33.camel@comp.rapiddsl.net>, Guillaume Marcais
wrote:

Given my little knowledge
of Windows, I started with Ruby and Win32API (hopefully it is achievable
that way).

DL is nicer. (See below!)

[...]

If you use the 'dl' library you don't need to worry about this sort of thing.

[...]

Guillaume,

You may be interested in Benjamin Peterson's recent translation of the Ruby/DL
tutorial from Japanese into English: http://raa.ruby-lang.org/project/rdl_en/

I also want to take this opportunity to say "thank you!" to
Takaaki Tateishi for creating Ruby/DL. It is such a fantastic library, my
favourite Ruby 1.8 feature.

···

In article <slrncqpopm.gtd.timsuth@europa.zone>, Tim Sutherland wrote:

--
Two fonts walk into a bar.
The bartender says to them, "Get out! We don't serve your type here."

[...]

   extern 'BOOL SendMessage(HWND, UINT, WPARAM, LPARAM)'

     extern 'LONG SendMessage(HWND, UINT, UINT, LONG)'

Sorry for multiple posts. For document, see also dl.txt in the
Ruby distribution. I once did a presentation on using Ruby/DL
to automate Windows GUI programs, see

http://www.sdkacm.com/static/events/12-March-2004/slides.sxi

(OpenOffice.org format.)

The slides are probably not very useful without the demo
programs / code I was also using, halfway through they start
saying things like
  [demo foo]

  [talk about bar]

but maybe someone will find it useful.

[...]

···

In article <slrncqpopm.gtd.timsuth@europa.zone>, Tim Sutherland wrote:

--
Two fonts walk into a bar.
The bartender says to them, "Get out! We don't serve your type here."

>In article <1101833542.8224.33.camel@comp.rapiddsl.net>, Guillaume Marcais
>wrote:
>>Given my little knowledge
>>of Windows, I started with Ruby and Win32API (hopefully it is achievable
>>that way).
>
>DL is nicer. (See below!)
[...]
>If you use the 'dl' library you don't need to worry about this sort of thing.
[...]

Thanks for the hints, I'll try it ASAP.

Guillaume,

You may be interested in Benjamin Peterson's recent translation of the Ruby/DL
tutorial from Japanese into English: http://raa.ruby-lang.org/project/rdl_en/

I actually encouraged him to go ahead when he asked if anybody was
interested. I am definitly going to read now that it is out.

Guillaume.

···

On Tue, 2004-11-30 at 16:52, Tim Sutherland wrote:

In article <slrncqpopm.gtd.timsuth@europa.zone>, Tim Sutherland wrote:

I also want to take this opportunity to say "thank you!" to
Takaaki Tateishi for creating Ruby/DL. It is such a fantastic library, my
favourite Ruby 1.8 feature.

--
Two fonts walk into a bar.
The bartender says to them, "Get out! We don't serve your type here."

Thanks for your help. It allowed me finish the link to pageant, now
release with Net-SSH :).

Guillaume.

···

On Wed, 2004-12-01 at 04:52, Tim Sutherland wrote:

In article <slrncqpopm.gtd.timsuth@europa.zone>, Tim Sutherland wrote:
[...]
> extern 'BOOL SendMessage(HWND, UINT, WPARAM, LPARAM)'

     extern 'LONG SendMessage(HWND, UINT, UINT, LONG)'

Sorry for multiple posts. For document, see also dl.txt in the
Ruby distribution. I once did a presentation on using Ruby/DL
to automate Windows GUI programs, see

http://www.sdkacm.com/static/events/12-March-2004/slides.sxi

(OpenOffice.org format.)

The slides are probably not very useful without the demo
programs / code I was also using, halfway through they start
saying things like
  [demo foo]

  [talk about bar]

but maybe someone will find it useful.

[...]

--
Two fonts walk into a bar.
The bartender says to them, "Get out! We don't serve your type here."