How to Use SendMessageCallBack API?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: How to Use SendMessageCallBack API?

Hybrid View

  1. #1
    Armando Cardenas Guest

    How to Use SendMessageCallBack API?


    I'm using SendMessage API to send messages between two applications in the
    same machine, but, I need to do this process in an asynchronous way. I'm
    probing replacing sendmessage API with the sendmessagecallback API, but i'cant
    make that sendmessagecallback API send the message. The SendMessage API is
    working well. I know that I should define a callBack Function, I think that
    its Ok, but I dont know why I can't send and recive the message using sendmessageCallBack
    API.
    Can somebody help me?

  2. #2
    Tom Esh Guest

    Re: How to Use SendMessageCallBack API?

    If it helps, here's a declaration and callback proceedure that work:

    Public Declare Function SendMessageCallback Lib "user32" _
    Alias "SendMessageCallbackA" _
    (ByVal hwnd As Long, ByVal Msg As Long, _
    ByVal wParam As Long, lParam As Any, _
    ByVal lpResultCallBack As Long, ByVal dwData As Long) As Long

    Public Sub SendAsyncProc(ByVal hwnd As Long, ByVal uMsg As Long, _
    ByVal dwData As Long, ByVal lResult As Long)

    Debug.Print "hwnd: " & hwnd
    Debug.Print "uMsg: " & uMsg
    Debug.Print "dwData: " & dwData
    Debug.Print "lResult: " & lResult
    End Sub

    'test call - paste clipboard contents to textbox:
    SendMessageCallback Text1.hwnd, WM_PASTE, 0&, ByVal 0&, _
    AddressOf SendAsyncProc, 999&


    On 10 Jul 2000 11:21:19 -0700, "Armando Cardenas"
    <lacf@microsis.com.mx> wrote:
    >
    >I'm using SendMessage API to send messages between two applications in the
    >same machine, but, I need to do this process in an asynchronous way. I'm
    >probing replacing sendmessage API with the sendmessagecallback API, but i'cant
    >make that sendmessagecallback API send the message. The SendMessage API is
    >working well. I know that I should define a callBack Function, I think that
    >its Ok, but I dont know why I can't send and recive the message using sendmessageCallBack
    >API.
    >Can somebody help me?



    -Tom
    (please post replies to the newsgroup)

  3. #3
    Armando Cardenas Guest

    Re: How to Use SendMessageCallBack API?


    Hi Tom, thanks for your help, but your example don't work in my program. I
    paste some of code that I use. I need to send strTemp inside the cdCopyData
    structure to target aplication in an asynchronous way:

    ' Get the hWnd of the target application
    ThWnd = FindWindow(vbNullString, "Target")
    strTemp = "This is the data that will be sent"

    ' Copy the string into a byte array, converting it to ASCII
    Call CopyMemory(byteBuffer(1), ByVal strTemp, Len(strTemp))
    cdCopyData.dwData = 3
    cdCopyData.cbData = Len(strTemp) + 1
    cdCopyData.lpData = VarPtr(byteBuffer(1))

    ' This Line Work Ok...
    i = SendMessage(ThWnd, WM_COPYDATA, Form1.hwnd, cdCopyData)

    'This Line Don't Work .... I NEED THIS LINE!!!
    SendMessageCallback ThWnd, WM_COPYDATA, Form1.hwnd, _
    cdCopyData, AddressOf SendAsyncProc, 999&

    'This line work ok ....
    'test call - paste clipboard contents to textbox in the same form
    SendMessageCallback form.Text1.hwnd, WM_PASTE, 0&, ByVal 0&, _
    AddressOf SendAsyncProc, 999&


  4. #4
    Tom Esh Guest

    Re: How to Use SendMessageCallBack API?

    Yeah, I don't think SendMessageCallback will work with WM_COPYDATA.
    Why not just use SendMessage in a Timer event?

    On 10 Jul 2000 16:05:28 -0700, "Armando Cardenas"
    <lacf@microsis.com.mx> wrote:

    >
    >Hi Tom, thanks for your help, but your example don't work in my program. I
    >paste some of code that I use. I need to send strTemp inside the cdCopyData
    >structure to target aplication in an asynchronous way:
    >
    >' Get the hWnd of the target application
    > ThWnd = FindWindow(vbNullString, "Target")
    > strTemp = "This is the data that will be sent"
    >
    >' Copy the string into a byte array, converting it to ASCII
    > Call CopyMemory(byteBuffer(1), ByVal strTemp, Len(strTemp))
    > cdCopyData.dwData = 3
    > cdCopyData.cbData = Len(strTemp) + 1
    > cdCopyData.lpData = VarPtr(byteBuffer(1))
    >
    >' This Line Work Ok...
    > i = SendMessage(ThWnd, WM_COPYDATA, Form1.hwnd, cdCopyData)
    >
    >'This Line Don't Work .... I NEED THIS LINE!!!
    > SendMessageCallback ThWnd, WM_COPYDATA, Form1.hwnd, _
    > cdCopyData, AddressOf SendAsyncProc, 999&
    >
    >'This line work ok ....
    >'test call - paste clipboard contents to textbox in the same form
    > SendMessageCallback form.Text1.hwnd, WM_PASTE, 0&, ByVal 0&, _
    > AddressOf SendAsyncProc, 999&
    >



    -Tom
    (please post replies to the newsgroup)

  5. #5
    mrfelis Guest

    Re: How to Use SendMessageCallBack API?

    Have you looked into PostMessage?

    --
    ~~~
    C'Ya,
    mrfelis
    mrfelis@yahoo.NOSPAM.com
    just remove the spam
    Armando Cardenas <lacf@microsis.com.mx> wrote in message
    news:396a141f$1@news.devx.com...
    >
    > I'm using SendMessage API to send messages between two applications in the
    > same machine, but, I need to do this process in an asynchronous way. I'm
    > probing replacing sendmessage API with the sendmessagecallback API, but

    i'cant
    > make that sendmessagecallback API send the message. The SendMessage API is
    > working well. I know that I should define a callBack Function, I think

    that
    > its Ok, but I dont know why I can't send and recive the message using

    sendmessageCallBack
    > API.
    > Can somebody help me?




  6. #6
    Tom Esh Guest

    Re: How to Use SendMessageCallBack API?

    The MS docs warn not to use PostMessage for WM_COPYDATA. I suppose it
    makes sense - since it doesn't wait for the message to be processed,
    the data could go out of scope before it's processed (nasty). There is
    no similar warning for SendMessageCallback, but it just doesn't work.

    On Wed, 12 Jul 2000 13:19:33 -0400, "mrfelis"
    <mrfelis@yahoo.NOSPAM.com> wrote:
    >Have you looked into PostMessage?
    >
    >--
    >~~~
    >C'Ya,
    >mrfelis
    >mrfelis@yahoo.NOSPAM.com
    >just remove the spam
    >Armando Cardenas <lacf@microsis.com.mx> wrote in message
    >news:396a141f$1@news.devx.com...
    >>
    >> I'm using SendMessage API to send messages between two applications in the
    >> same machine, but, I need to do this process in an asynchronous way. I'm
    >> probing replacing sendmessage API with the sendmessagecallback API, but

    >i'cant
    >> make that sendmessagecallback API send the message. The SendMessage API is
    >> working well. I know that I should define a callBack Function, I think

    >that
    >> its Ok, but I dont know why I can't send and recive the message using

    >sendmessageCallBack
    >> API.
    >> Can somebody help me?

    >
    >



    -Tom
    (please post replies to the newsgroup)

  7. #7
    Tom Esh Guest

    Re: How to Use SendMessageCallBack API?

    If it helps, here's a declaration and callback proceedure that work:

    Public Declare Function SendMessageCallback Lib "user32" _
    Alias "SendMessageCallbackA" _
    (ByVal hwnd As Long, ByVal Msg As Long, _
    ByVal wParam As Long, lParam As Any, _
    ByVal lpResultCallBack As Long, ByVal dwData As Long) As Long

    Public Sub SendAsyncProc(ByVal hwnd As Long, ByVal uMsg As Long, _
    ByVal dwData As Long, ByVal lResult As Long)

    Debug.Print "hwnd: " & hwnd
    Debug.Print "uMsg: " & uMsg
    Debug.Print "dwData: " & dwData
    Debug.Print "lResult: " & lResult
    End Sub

    'test call - paste clipboard contents to textbox:
    SendMessageCallback Text1.hwnd, WM_PASTE, 0&, ByVal 0&, _
    AddressOf SendAsyncProc, 999&


    On 10 Jul 2000 11:21:19 -0700, "Armando Cardenas"
    <lacf@microsis.com.mx> wrote:
    >
    >I'm using SendMessage API to send messages between two applications in the
    >same machine, but, I need to do this process in an asynchronous way. I'm
    >probing replacing sendmessage API with the sendmessagecallback API, but i'cant
    >make that sendmessagecallback API send the message. The SendMessage API is
    >working well. I know that I should define a callBack Function, I think that
    >its Ok, but I dont know why I can't send and recive the message using sendmessageCallBack
    >API.
    >Can somebody help me?



    -Tom
    (please post replies to the newsgroup)

  8. #8
    Armando Cardenas Guest

    Re: How to Use SendMessageCallBack API?


    Hi Tom, thanks for your help, but your example don't work in my program. I
    paste some of code that I use. I need to send strTemp inside the cdCopyData
    structure to target aplication in an asynchronous way:

    ' Get the hWnd of the target application
    ThWnd = FindWindow(vbNullString, "Target")
    strTemp = "This is the data that will be sent"

    ' Copy the string into a byte array, converting it to ASCII
    Call CopyMemory(byteBuffer(1), ByVal strTemp, Len(strTemp))
    cdCopyData.dwData = 3
    cdCopyData.cbData = Len(strTemp) + 1
    cdCopyData.lpData = VarPtr(byteBuffer(1))

    ' This Line Work Ok...
    i = SendMessage(ThWnd, WM_COPYDATA, Form1.hwnd, cdCopyData)

    'This Line Don't Work .... I NEED THIS LINE!!!
    SendMessageCallback ThWnd, WM_COPYDATA, Form1.hwnd, _
    cdCopyData, AddressOf SendAsyncProc, 999&

    'This line work ok ....
    'test call - paste clipboard contents to textbox in the same form
    SendMessageCallback form.Text1.hwnd, WM_PASTE, 0&, ByVal 0&, _
    AddressOf SendAsyncProc, 999&


  9. #9
    Tom Esh Guest

    Re: How to Use SendMessageCallBack API?

    Yeah, I don't think SendMessageCallback will work with WM_COPYDATA.
    Why not just use SendMessage in a Timer event?

    On 10 Jul 2000 16:05:28 -0700, "Armando Cardenas"
    <lacf@microsis.com.mx> wrote:

    >
    >Hi Tom, thanks for your help, but your example don't work in my program. I
    >paste some of code that I use. I need to send strTemp inside the cdCopyData
    >structure to target aplication in an asynchronous way:
    >
    >' Get the hWnd of the target application
    > ThWnd = FindWindow(vbNullString, "Target")
    > strTemp = "This is the data that will be sent"
    >
    >' Copy the string into a byte array, converting it to ASCII
    > Call CopyMemory(byteBuffer(1), ByVal strTemp, Len(strTemp))
    > cdCopyData.dwData = 3
    > cdCopyData.cbData = Len(strTemp) + 1
    > cdCopyData.lpData = VarPtr(byteBuffer(1))
    >
    >' This Line Work Ok...
    > i = SendMessage(ThWnd, WM_COPYDATA, Form1.hwnd, cdCopyData)
    >
    >'This Line Don't Work .... I NEED THIS LINE!!!
    > SendMessageCallback ThWnd, WM_COPYDATA, Form1.hwnd, _
    > cdCopyData, AddressOf SendAsyncProc, 999&
    >
    >'This line work ok ....
    >'test call - paste clipboard contents to textbox in the same form
    > SendMessageCallback form.Text1.hwnd, WM_PASTE, 0&, ByVal 0&, _
    > AddressOf SendAsyncProc, 999&
    >



    -Tom
    (please post replies to the newsgroup)

  10. #10
    mrfelis Guest

    Re: How to Use SendMessageCallBack API?

    Have you looked into PostMessage?

    --
    ~~~
    C'Ya,
    mrfelis
    mrfelis@yahoo.NOSPAM.com
    just remove the spam
    Armando Cardenas <lacf@microsis.com.mx> wrote in message
    news:396a141f$1@news.devx.com...
    >
    > I'm using SendMessage API to send messages between two applications in the
    > same machine, but, I need to do this process in an asynchronous way. I'm
    > probing replacing sendmessage API with the sendmessagecallback API, but

    i'cant
    > make that sendmessagecallback API send the message. The SendMessage API is
    > working well. I know that I should define a callBack Function, I think

    that
    > its Ok, but I dont know why I can't send and recive the message using

    sendmessageCallBack
    > API.
    > Can somebody help me?




  11. #11
    Tom Esh Guest

    Re: How to Use SendMessageCallBack API?

    The MS docs warn not to use PostMessage for WM_COPYDATA. I suppose it
    makes sense - since it doesn't wait for the message to be processed,
    the data could go out of scope before it's processed (nasty). There is
    no similar warning for SendMessageCallback, but it just doesn't work.

    On Wed, 12 Jul 2000 13:19:33 -0400, "mrfelis"
    <mrfelis@yahoo.NOSPAM.com> wrote:
    >Have you looked into PostMessage?
    >
    >--
    >~~~
    >C'Ya,
    >mrfelis
    >mrfelis@yahoo.NOSPAM.com
    >just remove the spam
    >Armando Cardenas <lacf@microsis.com.mx> wrote in message
    >news:396a141f$1@news.devx.com...
    >>
    >> I'm using SendMessage API to send messages between two applications in the
    >> same machine, but, I need to do this process in an asynchronous way. I'm
    >> probing replacing sendmessage API with the sendmessagecallback API, but

    >i'cant
    >> make that sendmessagecallback API send the message. The SendMessage API is
    >> working well. I know that I should define a callBack Function, I think

    >that
    >> its Ok, but I dont know why I can't send and recive the message using

    >sendmessageCallBack
    >> API.
    >> Can somebody help me?

    >
    >



    -Tom
    (please post replies to the newsgroup)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center