Jump to content

Recommended Posts

Posted (edited)

Per MSDN SendMessageCallback

  Quote

Sends the specified message to a window or windows. It calls the window procedure for the specified window and returns immediately if the window belongs to another thread. After the window procedure processes the message, the system calls the specified callback function, passing the result of the message processing and an application-defined value to the callback function.

Expand  
Func __WinAPI_SendMessageCallback($hWnd, $iMsg, $wParam, $lParam, $pCallback, $pData = NULL)
    Local $aResult = DllCall("user32.dll", "int", "SendMessageCallback", _
            "hwnd", $hWnd, _
            "uint", $iMsg, _
            "wparam", $wParam, _
            "lparam", $lParam, _
            "ptr", $pCallback, _
            "ulong_ptr", $pData)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc
  Reveal hidden contents

Note: I haven't decided if its better to send $pdata as a dword or as a uint_ptr or just exclude it all together

Edited by Bilgus
Posted

There is an example above but I can Throw you a working example real quick

 

#include <WinAPIError.au3>

Global $bExit = False
Global $hCallback = DllCallbackRegister(_Callback, 'none', 'hwnd;uint;ulong_ptr;lresult')
Global $pCallback = DllCallbackGetPtr($hCallback)

Func _Callback($hwnd, $iMsg, $pData, $lRes)
    ConsoleWrite("Callback " & $iMsg & " = " & $lRes)
    $bExit = True ;
EndFunc   ;==>_Callback

Func __WinAPI_SendMessageCallback($hwnd, $iMsg, $wParam, $lParam, $pCallback, $pData = Null)
    Local $aResult = DllCall("user32.dll", "int", "SendMessageCallback", _
            "hwnd", $hwnd, _
            "uint", $iMsg, _
            "wparam", $wParam, _
            "lparam", $lParam, _
            "ptr", $pCallback, _
            "dword", $pData)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SendMessageCallback

Global $hwnd = WinGetHandle(AutoItWinGetTitle()) ;Grab hidden autoit window
Global Const $WM_GETICON = 0x007F
Global Const $ICON_SMALL2 = 0x2

If __WinAPI_SendMessageCallback($hwnd, $WM_GETICON, $ICON_SMALL2, 0, $pCallback) <> 0 Then
    Local $iTimeout = 30
    While $bExit = False And $iTimeout > 0
        Sleep(1000)
        $iTimeout -= 1
    WEnd
Else
    ConsoleWrite("Error - " & _WinAPI_GetLastErrorMessage() & @CRLF)
EndIf

DllCallbackFree($hCallback)

Be aware some messages can't be used like this (WM_GetText for instance)

 

Posted

Its doubtful that it can be used for WM_COPYDATA eithr pretty sure that is a synchronous message as well

 

I'm experimenting with getting a callback when my other instance is ready

ie. signaling to the child app that you have data or would like to get data and not locking up your process waiting for it to get ready

I'm not sure how to best make that happen yet on the child side (not locking it up) atm I do all my processing in the message loop and I KNOW that isn't a good idea

 

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...