Bilgus Posted April 21, 2020 Posted April 21, 2020 (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 Global $hCallback = DllCallbackRegister(_Callback, 'none', 'hwnd;uint;ulong_ptr;lresult') Global $pCallback = DllCallbackGetPtr($hCallback) Func _Callback($hwnd, $iMsg, $pData, $lRes) ConsoleWrite("Callback " & $iMsg & " = " & $lRes) EndFunc __WinAPI_SendMessageCallback($hWnd, $iMsg, $wParam, $lParam, $pCallback) DllCallbackFree($hCallback) 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 April 22, 2020 by Bilgus
argumentum Posted April 21, 2020 Posted April 21, 2020 so we could use this to fake a DLL or be an IPC or ... would you post a working example Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Bilgus Posted April 21, 2020 Author Posted April 21, 2020 There is an example above but I can Throw you a working example real quick expandcollapse popup#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) argumentum 1
Bilgus Posted April 21, 2020 Author Posted April 21, 2020 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now