[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Windows SendMessage

Guillaume Marcais

11/30/2004 4:52:00 PM

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.

5 Answers

timsuth

11/30/2004 9:17:00 PM

0

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

timsuth

11/30/2004 9:49:00 PM

0

In article <slrncqpopm.gtd.timsuth@europa.zone>, Tim Sutherland wrote:
>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/proje...

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."

Guillaume Marcais

11/30/2004 10:21:00 PM

0

On Tue, 2004-11-30 at 16:52, Tim Sutherland wrote:
> In article <slrncqpopm.gtd.timsuth@europa.zone>, Tim Sutherland wrote:
> >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/proje...

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.

> 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."
>




timsuth

12/1/2004 9:51:00 AM

0

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/...

(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."

Guillaume Marcais

12/2/2004 6:20:00 PM

0

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/...
>
> (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."
>