Announcement

Collapse
No announcement yet.

SendMessage and get it from another application

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SendMessage and get it from another application

    I need to send a message to another already running application and from the second application react to it.
    ===========================================
    send.bas
    STATIC IMSG AS LONG
    dim txt1 as string
    tst1="testing"
    IMSG = RegisterWindowMessage ("MESSAGE_NAME1234") ' get the value we'll be looking for
    SendMessage (%HWND_BROADCAST, IMSG, 1234, strPTR(txt1) )
    ============================================
    get.bas
    '-------------------
    GLOBAL IMSG as long
    '-------------------
    FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
    SELECT CASE wMsg
    cASE IMSG
    LOCAL pp AS string PTR
    LOCAL ppL AS LONG PTR
    ppL = wParam
    pp = lParam
    MsgBox STR$(ppL)
    MsgBox @pp
    ....
    '=========================================
    Result:
    display wParam = 1234 , lParam =""
    string data are not working. pls help and check my program.

    Anyone gone this direction that can help me out?
    Han Loke Su
    Member
    Last edited by Han Loke Su; 29 Oct 2008, 04:41 AM.

  • #2
    The register message may not be handy since it will force you to use one instance of the calling app only.
    We use sendmessage/WM_SETTEXT which is interprocess and you'll be able to pass null-terminated text.
    Problem is that it needs a windowhandle, you'll need a window and thus it's hWnd to call.
    In our situation we pass it by commandline since the calling app executes the 2nd app.

    Be careful with sendmessage from app1 to app2 and then directly use sendmessage from app2 to app1, this will most likely lock up your apps (i had)
    Apps are not synchronised in Windows.. therefore.

    Another alternative is the WM_COPYDATA message.
    Edwin Knoppert
    Member
    Last edited by Edwin Knoppert; 29 Oct 2008, 06:35 AM.
    hellobasic

    Comment


    • #3
      The problem here is, the address of the string idata in lparam (STRPTR(txt1)) is not valid except in the calling application.

      WM_COPYDATA will resolve these address conflicts for you; sendmessage does not.

      Alternately, you need to put that text into something "global" or at least valid across processes so the second (receiving) application can read the text. Maybe a Global Atom can be used; a named memory object is a little more complex but I know that will work for sure. A global memory handle (GLOBALMEM ALLOC in CC5+, Win9+) would also do the job.

      Also, when when you pass the address of the stringdata with STRPTR() it would be seen on the receiving end as an "ASCIIZ PTR", not a "STRING PTR"

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        No, WM_SETTEXT is interprocess.. an exception it is.
        The calling app will copy the local data into a memorymapped 'file'.
        No worries.
        hellobasic

        Comment


        • #5
          WM_SETTEXT works interprocess, but assumes you have a handle to a window/control whose text you are setting.

          I can't tell anymore if we do or don't have a handle, or are using WM_SETTEXT, WM_COPYDATA or a Registered message.

          Well, too many options has got to be better than no options.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            WM_COPYDATA is fine of course but it requires a structure.
            Just a bit of extra coding.
            hellobasic

            Comment


            • #7
              It might be better to find the window handle of the destination application, instead of using broadcast.

              Post #9 here http://www.powerbasic.com/support/pb...ad.php?t=37463 has source code to get the window handle given the application name - I mean the application window title.

              Comment

              Working...
              X