Loading ...
Sorry, an error occurred while loading the content.

SendMessage

Expand Messages
  • Sam Wetterlin
    I want to be able to run two separate LB programs and be able to send simple messages between them to coordinate their activity. I m over my head here, but
    Message 1 of 6 , Jul 29, 2009
    • 0 Attachment
      I want to be able to run two separate LB programs and be able to send simple messages between them to coordinate their activity. I'm over my head here, but some research suggests that the way to do it is to use the SendMessage API with the WM_COPYDATA parameter. The code examples (in C++) that I found indicate that sending the message is pretty straightforward. However, to process the messages the recipient uses an event handler that is invoked when the message is received. Since LB has only a few explicit event handlers, such as trapclose, that method doesn't seem feasible. Is there a way to install a callback function, or some other mechanism so the recipient knows it got a message and can act on it?

      Or maybe SendMessage is not the way to go and there is an alternative?

      My programs have nothing to do until they receive certain messages, so they can be in a loop to check for messages; they don't have to be "interrupted". Thus, for example, if Program A could "type" data into a text box in Program B (perhaps using another parameter for SendMessage?), Program B can just keep checking to see if text has appeared and then act on it. But I don't know if such typing into another program is possible. Perhaps SendMessageA can be used. There are lots of messages here about using SendMessageA to alter text boxes in your own program, but I need to do it in another program.

      Any clues would be appreciated.

      Sam W.
    • epankoke@comcast.net
      If you want to go the textbox route, try looking up the message constant WM_SETTEXT. I m not sure that this is the best route to go, but it might be the option
      Message 2 of 6 , Jul 29, 2009
      • 0 Attachment
        If you want to go the textbox route, try looking up the message constant WM_SETTEXT. I'm not sure that this is the best route to go, but it might be the option you need if you can't do a callback. I'm not aware of the ability to use callback functions in LB, but that of course doesn't mean they don't exist. The other thing you might want to look into is a simple peer-to-peer winsock thing to communicate between your two programs. I've never done this in LB, but I did set up somethng like that in VB one time, and it worked pretty good. Of course in VB I had the advantage of having the Microsoft Winsock ActiveX control, which made things a lot simpler. Hopefully someone with more LB knowledge will pop in and give you a decent answer to this question.



        ----- Original Message -----
        From: "Sam Wetterlin" <swetterlin@...>
        To: libertybasic@yahoogroups.com
        Sent: Wednesday, July 29, 2009 12:51:06 PM GMT -05:00 US/Canada Eastern
        Subject: [libertybasic] SendMessage






        I want to be able to run two separate LB programs and be able to send simple messages between them to coordinate their activity. I'm over my head here, but some research suggests that the way to do it is to use the SendMessage API with the WM_COPYDATA parameter. The code examples (in C++) that I found indicate that sending the message is pretty straightforward. However, to process the messages the recipient uses an event handler that is invoked when the message is received. Since LB has only a few explicit event handlers, such as trapclose, that method doesn't seem feasible. Is there a way to install a callback function, or some other mechanism so the recipient knows it got a message and can act on it?

        Or maybe SendMessage is not the way to go and there is an alternative?

        My programs have nothing to do until they receive certain messages, so they can be in a loop to check for messages; they don't have to be "interrupted". Thus, for example, if Program A could "type" data into a text box in Program B (perhaps using another parameter for SendMessage?), Program B can just keep checking to see if text has appeared and then act on it. But I don't know if such typing into another program is possible. Perhaps SendMessageA can be used. There are lots of messages here about using SendMessageA to alter text boxes in your own program, but I need to do it in another program.

        Any clues would be appreciated.

        Sam W.




        [Non-text portions of this message have been removed]
      • rod_bird001
        ... Check this thread http://libertybasic.conforums.com/index.cgi?board=tips&action=display&num=1187311744&start=
        Message 3 of 6 , Jul 29, 2009
        • 0 Attachment
          --- In libertybasic@yahoogroups.com, "Sam Wetterlin" <swetterlin@...> wrote:
          >
          > I want to be able to run two separate LB programs and be able to send simple messages between them to coordinate their activity. I'm over my head here, but some research suggests that the way to do it is to use the SendMessage API with the WM_COPYDATA parameter. The code examples (in C++) that I found indicate that sending the message is pretty straightforward. However, to process the messages the recipient uses an event handler that is invoked when the message is received. Since LB has only a few explicit event handlers, such as trapclose, that method doesn't seem feasible. Is there a way to install a callback function, or some other mechanism so the recipient knows it got a message and can act on it?
          >
          > Or maybe SendMessage is not the way to go and there is an alternative?
          >
          > My programs have nothing to do until they receive certain messages, so they can be in a loop to check for messages; they don't have to be "interrupted". Thus, for example, if Program A could "type" data into a text box in Program B (perhaps using another parameter for SendMessage?), Program B can just keep checking to see if text has appeared and then act on it. But I don't know if such typing into another program is possible. Perhaps SendMessageA can be used. There are lots of messages here about using SendMessageA to alter text boxes in your own program, but I need to do it in another program.
          >
          > Any clues would be appreciated.
          >
          > Sam W.
          >
          Check this thread http://libertybasic.conforums.com/index.cgi?board=tips&action=display&num=1187311744&start=
        • Richard Russell
          ... There are many different techniques available for inter-process communication in Windows. See this Microsoft article on the subject:
          Message 4 of 6 , Jul 29, 2009
          • 0 Attachment
            --- In libertybasic@yahoogroups.com, "Sam Wetterlin" wrote:
            > I want to be able to run two separate LB programs and be able to
            > send simple messages between them to coordinate their activity.

            There are many different techniques available for inter-process communication in Windows. See this Microsoft article on the subject:

            http://msdn.microsoft.com/en-us/library/aa365574.aspx

            Some methods will be better suited to Liberty Basic's capabilities, and others less so. Although you could probably make the SendMessage method work (e.g. using WMLIBERTY.DLL to subclass the message handler) you might find it easier to use, for example, shared files to achieve your requirements. Although it may seem wasteful to use a file, when you don't actually need to store the data, the way files are cached in RAM can actually make it a fast and convenient approach.

            > My programs have nothing to do until they receive certain
            > messages, so they can be in a loop to check for messages; they
            > don't have to be "interrupted".

            Using the shared file approach, the 'receiving' program just has to check for the existence of (or perhaps the length of) a file which is written by the 'sending' program. I'm not too sure how LB behaves if you attempt to access a file currently opened by another process, so that could affect the practicality of the method.

            Richard.
          • Stefan Pendl
            ... LB will throw an error, since it does not support file sharing access. You can trap this error, wait some time and retry, to overcome this. A second way is
            Message 5 of 6 , Jul 30, 2009
            • 0 Attachment
              >
              > > My programs have nothing to do until they receive certain
              > > messages, so they can be in a loop to check for messages; they
              > > don't have to be "interrupted".
              >
              > Using the shared file approach, the 'receiving' program just
              > has to check for the existence of (or perhaps the length of)
              > a file which is written by the 'sending' program. I'm not
              > too sure how LB behaves if you attempt to access a file
              > currently opened by another process, so that could affect the
              > practicality of the method.
              >

              LB will throw an error, since it does not support file sharing access.
              You can trap this error, wait some time and retry, to overcome this.
              A second way is to use the API function to open the file and check the return code, so you do not have to trap the error.

              ---
              Stefan Pendl

              Liberty BASIC Assist 4.03 ........ http://www.libertybasic.com/assist.html
              Liberty BASIC 4.04 public beta ... http://www.libertybasic.com/lb404b3setup.exe

              Windows Vista Home Premium 32-bit SP2
              AMD Turion X2 RM-70 2GHz, 4GB RAM
            • Sam Wetterlin
              Thanks for your response, and the responses of others. The thread you cited has an interesting approach, beginning the communication by using the caption of
              Message 6 of 6 , Jul 31, 2009
              • 0 Attachment
                Thanks for your response, and the responses of others. The thread you cited has an interesting approach, beginning the communication by using the caption of the window. And the suggestion to check out WMLIBERTY.dll is also promising.

                Sam W.
                --- In libertybasic@yahoogroups.com, "rod_bird001" <rodbird@...> wrote:
                >
                > --- In libertybasic@yahoogroups.com, "Sam Wetterlin" <swetterlin@> wrote:
                > >
                > > I want to be able to run two separate LB programs and be able to send simple messages between them to coordinate their activity. I'm over my head here, but some research suggests that the way to do it is to use the SendMessage API with the WM_COPYDATA parameter. The code examples (in C++) that I found indicate that sending the message is pretty straightforward. However, to process the messages the recipient uses an event handler that is invoked when the message is received. Since LB has only a few explicit event handlers, such as trapclose, that method doesn't seem feasible. Is there a way to install a callback function, or some other mechanism so the recipient knows it got a message and can act on it?
                > >
                > > Or maybe SendMessage is not the way to go and there is an alternative?
                > >
                > > My programs have nothing to do until they receive certain messages, so they can be in a loop to check for messages; they don't have to be "interrupted". Thus, for example, if Program A could "type" data into a text box in Program B (perhaps using another parameter for SendMessage?), Program B can just keep checking to see if text has appeared and then act on it. But I don't know if such typing into another program is possible. Perhaps SendMessageA can be used. There are lots of messages here about using SendMessageA to alter text boxes in your own program, but I need to do it in another program.
                > >
                > > Any clues would be appreciated.
                > >
                > > Sam W.
                > >
                > Check this thread http://libertybasic.conforums.com/index.cgi?board=tips&action=display&num=1187311744&start=
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.