Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Information about the use of Callback, OS.SendMessage and friends?
Information about the use of Callback, OS.SendMessage and friends? [message #459570] Thu, 11 August 2005 09:18 Go to next message
Eclipse UserFriend
Originally posted by: tim.wernick.pentos.de

Hello everyone!
Maybe some kind soul out there is able to help me or point me in the
right direction. I need some information about the correct use of
OS.SendMessage and how to read response Messages from the Windows
Message Queue.
I want to send Messages to a native Win32 Application and read the
responses of the application sent back over the message queue and react
according to the messages.
In order to achieve this I searched through the SWT API and found
OS.SendMessage, OS.PeekMessage, OS.GetMessage and the Class Callback. My
understanding so far is, that I have to create a new Callback Object and
pass in the constructor the method which is used to handle the messages
that will be sent back from the native layer of SWT. I suppose I'll have
to use PeekMessage or GetMessage within this method.

Am I right so far? Is there anywhere some in depth information /
examples or tutorial on how to solve a problem like this?

Thanks in advance


Tim
Re: Information about the use of Callback, OS.SendMessage and friends? [message #459576 is a reply to message #459570] Thu, 11 August 2005 13:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Tim Wernick" <tim.wernick@pentos.de> wrote in message
news:ddf54t$s7r$1@news.eclipse.org...
> Hello everyone!
> Maybe some kind soul out there is able to help me or point me in the right
> direction. I need some information about the correct use of OS.SendMessage
> and how to read response Messages from the Windows Message Queue.
> I want to send Messages to a native Win32 Application and read the
> responses of the application sent back over the message queue and react
> according to the messages.
> In order to achieve this I searched through the SWT API and found
> OS.SendMessage, OS.PeekMessage, OS.GetMessage and the Class Callback. My
> understanding so far is, that I have to create a new Callback Object and
> pass in the constructor the method which is used to handle the messages
> that will be sent back from the native layer of SWT. I suppose I'll have
> to use PeekMessage or GetMessage within this method.
>
> Am I right so far? Is there anywhere some in depth information / examples
> or tutorial on how to solve a problem like this?
>
All you need is
a) OS.SendMessage to send the message.
b) Extend Callback to create your own callback object with the new WinProc
method.
c) Use OS.SetWindowLong to subclass the window with the address of your
Callback class. Save the old Callback address.
d) The parameters of the Callback WinProc method have the same signature as
the normal Windows WinProc (int hWnd, int msg, int wParam, int lParam).
So you don't need PeekMessage or GetMessage.
e) When you are done, remember to restore the old Callback address. If you
don't, Bad Things Will Happen.

Caveat: This is OS-specific, so it is discouraged access.
---
Sunil
Re: Information about the use of Callback, OS.SendMessage and friends? [message #459600 is a reply to message #459576] Fri, 12 August 2005 06:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.wernick.pentos.de

Sunil Kamath wrote:
> All you need is
> a) OS.SendMessage to send the message.
> b) Extend Callback to create your own callback object with the new WinProc
> method.
> c) Use OS.SetWindowLong to subclass the window with the address of your
> Callback class. Save the old Callback address.
> d) The parameters of the Callback WinProc method have the same signature as
> the normal Windows WinProc (int hWnd, int msg, int wParam, int lParam).
> So you don't need PeekMessage or GetMessage.
> e) When you are done, remember to restore the old Callback address. If you
> don't, Bad Things Will Happen.
>
> Caveat: This is OS-specific, so it is discouraged access.
> ---
> Sunil
>
>

Hello Sunil,
thank you very much for your quick reply. I will try it this way today.
Cross your fingers for me that I get it running ;-)
It's not a problem that it is OS-specific. One can think of it as a very
special widget only for the windows plattform. The company who is
creating the application I want to communicate with only published the
windows messaging protocol used to access their software. So I'm stuck
with Windows. Sad thing but I can't change it. I would have prefered a
shared lib or dll with the apropriate methods exposed.

regards from munich



Tim
Re: Information about the use of Callback, OS.SendMessage and friends? [message #460096 is a reply to message #459576] Mon, 22 August 2005 12:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tim.wernick.pentos.de

Hi Sunil, hi everyone!
Sunil thank you very much for the tip with SetWindowLong! I now managed
to send some Messages via HWND_BROADCAST in order to get "attached" to
the other application. I also got the responses to those previously
registered messages so now I have the window handle of the other
application as well.
The Problem now is that follow up messages are not registered messages
because the messages may have different contents. Which means I'm
sending a String (TCHAR) to the "remote" Application Window using the
dedicated OS.SendMessage(int hwnd, int msg, int wparam, TCHAR lparam)
method. For the hwnd Parameter I'm using the Window Handle of the remote
Window. For the msg Parameter I'm using WM_COPYDATA. The wparam
parameter is set to the window handle of the shell and the lparam is a
newly created TCHAR object containing the string I want to send to the
remote window.
Now it seems that the messages are either not received by the remote
application or they are not send by the underlying JNI Layer of SWT. At
least thats what it looks like when I'm spying the window messages.
Is there anything I need to do when sending Strings as messages to
another window?
The next thing I will have to deal with is that the response messages
will also be of type WM_COPYDATA and I currently have no clue how to
deal with them. Is there anywhere some information about this topic how
to do that with SWT?

Greets from munich


Tim
Sunil Kamath wrote:
> "Tim Wernick" <tim.wernick@pentos.de> wrote in message
> news:ddf54t$s7r$1@news.eclipse.org...
>
>>Hello everyone!
>>Maybe some kind soul out there is able to help me or point me in the right
>>direction. I need some information about the correct use of OS.SendMessage
>>and how to read response Messages from the Windows Message Queue.
>>I want to send Messages to a native Win32 Application and read the
>>responses of the application sent back over the message queue and react
>>according to the messages.
>>In order to achieve this I searched through the SWT API and found
>>OS.SendMessage, OS.PeekMessage, OS.GetMessage and the Class Callback. My
>>understanding so far is, that I have to create a new Callback Object and
>>pass in the constructor the method which is used to handle the messages
>>that will be sent back from the native layer of SWT. I suppose I'll have
>>to use PeekMessage or GetMessage within this method.
>>
>>Am I right so far? Is there anywhere some in depth information / examples
>>or tutorial on how to solve a problem like this?
>>
>
> All you need is
> a) OS.SendMessage to send the message.
> b) Extend Callback to create your own callback object with the new WinProc
> method.
> c) Use OS.SetWindowLong to subclass the window with the address of your
> Callback class. Save the old Callback address.
> d) The parameters of the Callback WinProc method have the same signature as
> the normal Windows WinProc (int hWnd, int msg, int wParam, int lParam).
> So you don't need PeekMessage or GetMessage.
> e) When you are done, remember to restore the old Callback address. If you
> don't, Bad Things Will Happen.
>
> Caveat: This is OS-specific, so it is discouraged access.
> ---
> Sunil
>
>
Re: Information about the use of Callback, OS.SendMessage and friends? [message #460170 is a reply to message #460096] Mon, 22 August 2005 13:59 Go to previous message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Tim Wernick" <tim.wernick@pentos.de> wrote in message
news:decfnc$kr8$1@news.eclipse.org...
> Hi Sunil, hi everyone!
> Sunil thank you very much for the tip with SetWindowLong! I now managed to
> send some Messages via HWND_BROADCAST in order to get "attached" to the
> other application. I also got the responses to those previously registered
> messages so now I have the window handle of the other application as well.
> The Problem now is that follow up messages are not registered messages
> because the messages may have different contents. Which means I'm
> sending a String (TCHAR) to the "remote" Application Window using the
> dedicated OS.SendMessage(int hwnd, int msg, int wparam, TCHAR lparam)
> method. For the hwnd Parameter I'm using the Window Handle of the remote
> Window. For the msg Parameter I'm using WM_COPYDATA. The wparam
> parameter is set to the window handle of the shell and the lparam is a
> newly created TCHAR object containing the string I want to send to the
> remote window.
> Now it seems that the messages are either not received by the remote
> application or they are not send by the underlying JNI Layer of SWT. At
> least thats what it looks like when I'm spying the window messages.
> Is there anything I need to do when sending Strings as messages to another
> window?

Not really. It should work as you have coded it. The only alternative I can
suggest is doing it in native code instead of using OS functions.

> The next thing I will have to deal with is that the response messages will
> also be of type WM_COPYDATA and I currently have no clue how to deal with
> them. Is there anywhere some information about this topic how to do that
> with SWT?
>
I handle WM_COPYDATA messages in a native code, convert the data to Java
objects and then return to the Java code.
---
Sunil
Previous Topic:Popupcelleditor
Next Topic:Tree Widget Size
Goto Forum:
  


Current Time: Fri Mar 29 07:53:01 GMT 2024

Powered by FUDForum. Page generated in 0.02894 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top