Jump to content

WM_COPYDATA return


Recommended Posts

3 minutes ago, Danyfirex said:

compare if they have same value

Yes they are the same, i don't know why i didn't thought about that in the first place.

Thanks.

 

4 minutes ago, Danyfirex said:

maybe I can do it in my dreams meanwhile

It's always good to dream! But soon everything will be better! 🍻

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Link to comment
Share on other sites

@Danyfirex, this look awesome, very cool.

The _WM_COPYDATA is used as an event, to trigger the read memory.
Is there a way, that is not too far out of your way, to trigger the memory read without using a GUI for it ?, as a memory write that triggers a memory read, or simple in the main loop read, that is not heavy for AutoIt ?

I know this is not the OP question but, can't help to wonder since is all a memory read/write and the GUI is just for the event handler. No GUI dependency would be like, WOW.

Thanks.

Edited by argumentum
grammar :)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

5 minutes ago, Bilgus said:

You still need a message loop

...the script needs a loop, OnEvent or not. So, a loop is not a big deal.

 

6 minutes ago, Bilgus said:

You could use the internal autoit window

actually no. I can not  GUIRegisterMsg() it.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

nah you need to use SetWindowSubclass

AutoItWinSetTitle(@ScriptName)
$hAutoitInternal = WinGetHandle(@ScriptName)

$hMsgProc = DllCallbackRegister(NewMessage, 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr')
_WinAPI_SetWindowSubclass($hAutoitInternal, DllCallbackGetPtr($hMsgProc), $iMyID)

Func NewMessage($hWnd, $iMsg, $wParam, $lParam, $iId, $pData)
    #forceref $iID, $pData
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

Func _Exit()
    If $hMsgProc Then
        _WinAPI_RemoveWindowSubclass($hAutoitInternal, DllCallbackGetPtr($hMsgProc), $iMyID)
        DllCallbackFree($g_hMsgProc)
    EndIf

 

Edited by Bilgus
Add #forceref $iID, $pData Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
Link to comment
Share on other sites

Quote

...the script needs a loop, OnEvent or not. So, a loop is not a big deal.

When you do your own message loop it has to be pumped in a timely manner so it sometimes becomes a big deal

at least with the subclass you can still have AutoIt take care of the minute 

Link to comment
Share on other sites

2 minutes ago, Bilgus said:

When you do your own message loop it has to be pumped in a timely manner so it sometimes becomes a big deal ...

...all this is way above my pay grade !.
I would have to build some coding experience to comfortably code with sub-classing.
Thanks for the coding class :) 

I'll give a try in one of those moments when I'm bored.
It'll be good to expand my knowing to the 
point that this technique is in my arsenal :D  

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Using COM for IPC and triggering events without a loop but via ObjEvent() could be a good method too.

Edit: Or do something like this in a loop and look for changes / reset the var when read.

 

Edited by KaFu
Link to comment
Share on other sites

looks like a solution to my question :) 
...it does crash running x64 :( 

@trancexx, ..it been about a decade since the code. Can it be fixed ?
..it won't run on v3.3.6.1 or 3.3.8.1 either ( on Win10 ), so maybe there was no solution from the get go, regarding x64.
Not that I "need" to run x64 but your view regarding this is welcomed.

Edit: ..now that I read more about it, this would be an overkill, and misused to fit the purpose of triggering an event. 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 4 years later...
On 5/17/2020 at 12:09 PM, Danyfirex said:

@MrCreatoR I meant something like this:

 

#AutoIt3Wrapper_UseX64=y
#include <WindowsConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>
#include <String.au3>

Global Const $tagCOPYDATASTRUCT = 'ulong_ptr dwData;' & _
        'dword cbData;' & _
        'ptr lpData'


Global $stStr = 0
Global $bExit = False
Global $hGUI

If $CmdLine[0] And $CmdLine[1] = '/Child' Then
    $hGUI = GUICreate('Child')
    GUIRegisterMsg($WM_COPYDATA, '_WM_COPYDATA')
    Do
        Sleep(10)
    Until $bExit
    Exit
EndIf

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /Child')
$hChild = WinWait('[CLASS:AutoIt v3 GUI;TITLE:Child]')
Sleep(500) ; ...relax
$hTimer = TimerInit() ; ... timer
Local $sDataToSend= "A_" & _StringRepeat('Send', Random(10, 100)) & "_Y" 
$sRet = _Send($hChild,$sDataToSend)
$hTimer = Round(TimerDiff($hTimer), 5) ; ..time it took to return
MsgBox(64, 'Return - ' & $hTimer, $sRet)

Func _Send($hWnd,$sDataToSend)
    Local $tPtr = DllStructCreate("ptr Data") ;Pointer for reading vRet Value
    Local $iProcessID = @AutoItPID
    Local $tData = DllStructCreate("Ptr pReturn;long pid;wchar Data[" & (StringLen($sDataToSend) + 1) & "]")
    $tData.pReturn = DllStructGetPtr($tPtr)
    $tData.PID = $iProcessID ;Pid for write memory
    $tData.Data = $sDataToSend ;Data to Send

;~  ConsoleWrite("$tData.pid: " & $tData.PID & @CRLF)
;~  ConsoleWrite("$tData.Data: " & $tData.Data & @CRLF)
    Local $tCopyData = DllStructCreate($tagCOPYDATASTRUCT)
    $tCopyData.cbData = DllStructGetSize($tData)
    $tCopyData.lpData = DllStructGetPtr($tData)
    Local $aRet = DllCall('user32.dll', 'lresult', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($tCopyData))
;~  ConsoleWrite("$tData.pReturn: " & $tData.pReturn & @CRLF)
;~  ConsoleWrite("$tPtr.Data: " & $tPtr.Data & @CRLF)
    Local $tSize = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($tPtr.Data), 'long iSize')
    Local $stStr = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($tPtr.Data + 4), 'wchar sStr[' & $tSize.iSize & ']')

    Return DllStructGetData($stStr, 'sStr')
EndFunc   ;==>_Send

Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
    $bExit = True
    Local $vRet = "A_" & _StringRepeat('Return', Random(10, 100)) & "_Y" ; Return
    Local $iLen = (StringLen($vRet) + 1)
    Local $tCopyData = DllStructCreate($tagCOPYDATASTRUCT, $lParam)
    Local $tData = DllStructCreate("Ptr pReturn;long PID;wchar Data[" & ($tCopyData.cbData - (@AutoItX64 ? 12 : 8)) & "]", $tCopyData.lpData)
    $stStr = DllStructCreate('long iSize;wchar sStr[' & $iLen & ']')
    DllStructSetData($stStr, 'iSize', $iLen)
    DllStructSetData($stStr, 'sStr', $vRet)
    Return _WinAPI_WriteProcessMemoryPtr($tData.PID, $tData.pReturn, DllStructGetPtr($stStr))
EndFunc   ;==>_WM_COPYDATA


Func _WinAPI_WriteProcessMemoryPtr($iProcessID, $pPointer, $ptPtr)
    Local $iSYNCHRONIZE = (0x00100000), $iSTANDARD_RIGHTS_REQUIRED = (0x000F0000)
    Local $iPROCESS_ALL_ACCESS = ($iSTANDARD_RIGHTS_REQUIRED + $iSYNCHRONIZE + 0xFFF)
    Local $hProcess, $Struct, $StructPtr, $StructSize, $iWriten

    $hProcess = _WinAPI_OpenProcess($iPROCESS_ALL_ACCESS, False, $iProcessID)
    If @error Then Return SetError(@error, 1, $Struct)

    Local $Struct = DllStructCreate("ptr Data")
    $StructSize = DllStructGetSize($Struct)
    $StructPtr = DllStructGetPtr($Struct)
    $Struct.Data = $ptPtr

    Local $bWrite = _WinAPI_WriteProcessMemory($hProcess, $pPointer, $StructPtr, $StructSize, $iWriten)
    _WinAPI_CloseHandle($hProcess)

    Return SetError(@error, $iWriten, $bWrite)
EndFunc   ;==>_WinAPI_WriteProcessMemoryPtr



Func _WinAPI_ReadProcessMemoryEx($iProcessID, $pPointer, $sStructTag)
    Local $iSYNCHRONIZE = (0x00100000), $iSTANDARD_RIGHTS_REQUIRED = (0x000F0000)
    Local $iPROCESS_ALL_ACCESS = ($iSTANDARD_RIGHTS_REQUIRED + $iSYNCHRONIZE + 0xFFF)
    Local $hProcess, $Struct, $StructPtr, $StructSize, $Read

    $hProcess = _WinAPI_OpenProcess($iPROCESS_ALL_ACCESS, False, $iProcessID)
    If @error Then Return SetError(@error, 1, $Struct)

    $Struct = DllStructCreate($sStructTag)
    $StructSize = DllStructGetSize($Struct)
    $StructPtr = DllStructGetPtr($Struct)

    _WinAPI_ReadProcessMemory($hProcess, $pPointer, $StructPtr, $StructSize, $Read)
    _WinAPI_CloseHandle($hProcess)

    Return SetError(@error, $Read, $Struct)
EndFunc   ;==>_WinAPI_ReadProcessMemoryEx

Saludos

 

Hi,

how can I get the value of $sDataToSend in _WM_COPYDATA?

_WM_COPYDATA only returns the string in $vRet.

I want to make a selection based on the lParam and return a value or string

 

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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