Jump to content

WM_COPYDATA return


Recommended Posts

4 minutes ago, Nine said:

Who cares what it returns

I care, i want to implement some kind of an "answer" for my AppInteract UDF.

I did it but using the same method by setting the interaction and SendMessage back to the calling process.

 

And also it's just curiosity of how can we pass pointer to our external process and transform that pointer to data.

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

Just now, Nine said:

A pointer to what structure ?

To one that created in WM_COPYDATA.

 

1 minute ago, Nine said:

I am out.

Ok :).

Thanks for trying to help.

 

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

I know I said I am out.   And I am, but I want to inform the community (those who will read this thread).  I tested speed of communication between 2 processes using usual TCP/UDF approach and stream (STDIO).  And I am quite impressed with the result with this exchange of WM_COPYDATA messages.  Very fast and easy to use. I will let you know my final results in example section later this week :)

Link to comment
Share on other sites

According to the documentation, either True or False should be returned in a WM_COPYDATA function. These are the only values you can say for sure are always returned correctly. If you want to have other than these values back from the WM_COPYDATA function with some certainty, it should probably be some kind of IPC technique.

My favorite array IPC technique is the running object table (ROT) technique based on AutoItObject as demonstrated in this thread. The technique can handle multi-dimensional arrays and retains the internal data type of the array elements. It should be possible to implement the technique using ObjCreateInterface() instead of AutoItObject.

Link to comment
Share on other sites

"The receiving application should consider the data read-only. The lParam parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by lParam. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer."

 

Create a second WM_COPYDATA loop handling comm in the opposite direction.

Link to comment
Share on other sites

3 hours ago, LarsJ said:

These are the only values you can say for sure are always returned correctly

As far as i tested, a pointer also can be returned, the issue with translating it back to structure.

 

3 hours ago, LarsJ said:

My favorite array IPC technique is the running object table (ROT) technique based on AutoItObject as demonstrated in this thread.

Thanks will check that.

 

12 minutes ago, KaFu said:

Create a second WM_COPYDATA loop handling comm in the opposite direction.

That's what i did.

 

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

14 minutes ago, MrCreatoR said:
3 hours ago, LarsJ said:

These are the only values you can say for sure are always returned correctly

As far as i tested, a pointer also can be returned, the issue with translating it back to structure.

The best way to do that is to share the beginning of the struct with all potential daya something like StructCreate("DataType dword; Size dword;")

and then a data item StructCreate("DataType dword; Size dword;byte;int;data[42]")

another data item StructCreate("DataType dword; Size dword;byte;int;long;ptr;data[88]")

 

when you receive the ptr on the other side do dllstructcreate("DataType dword; Size dword;", $ptr)

parse the data and create your final struct DllStructCreate("DataType dword; Size dword;byte;int;long;ptr;data[88]", $ptr)

you could even pass the struct definition if you so desired

Edited by Bilgus
Link to comment
Share on other sites

1 minute ago, Bilgus said:

The best way to do that is to share the beginning of the struct

Not sure what you mean by beginning of the structure.

Any attempt to use the pointer from another process leads to a hard crash.

 

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

Oh then maybe I misunderstand what you are trying to do then

I thought you were referring to the data you already got during the wmCD call, I'd totally expect if you use a pointer from another process it'd crash

Link to comment
Share on other sites

Just now, Bilgus said:

expect if you use a pointer from another process it'd crash

Maybe there is some way to get an address by this pointer and use it in ReadProcessMemory?

 

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

WM_COPYDATA structure should be different to make it x64 save, plus I always define it and the pointer as a Global Var, because it's always blocking and distinct (speed-wise optimization again).

 

Global $t_WM_COPYDATA = DllStructCreate("ulong_ptr;dword;ptr")
Global $p_WM_COPYDATA = DllStructGetPtr($t_WM_COPYDATA)

Link to comment
Share on other sites

ReadProcessMem is a train wreck waiting to happen use shared memory or something first

IIUC you should be notifying your app with a different message and having it initiate the wm_copydata not trying to retrieve the struct off the send message call

Link to comment
Share on other sites

  • 3 weeks later...

Finally i found a way:

 

#include <WindowsConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>

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]')

$sRet = _Send($hChild)
MsgBox(64, 'Return', $sRet)

Func _Send($hWnd)
    Local $stData = DllStructCreate('ulong_ptr;dword;ptr')
    Local $aRet = DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($stData))
    Local $stStr = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($aRet[0]), 'wchar sStr[1024]')
    
    Return DllStructGetData($stStr, 'sStr')
EndFunc

Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
    $bExit = True
    $vRet = 'Test'
    
    $iLen = (StringLen($vRet) * 2) + 3
    $stStr = DllStructCreate('wchar sStr[' & $iLen & ']')
    DllStructSetData($stStr, 'sStr', $vRet)
    
    Return DllStructGetPtr($stStr)
EndFunc

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

 

Just one small(?) limitation: i should set structure manually ('wchar sStr[1024]') without really knowing the size of the data returned.

 

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

You can do something like this to remove that limitation.

 

#include <WindowsConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>
#include <String.au3>

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]')

$sRet = _Send($hChild)
MsgBox(64, 'Return', $sRet)

Func _Send($hWnd)
    Local $stData = DllStructCreate('ulong_ptr;dword;ptr')
    Local $aRet = DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($stData))
    Local $tSize = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($aRet[0]), 'long iSize')
    Local $stStr = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($aRet[0] + 4), 'wchar sStr[' & $tSize.iSize & ']')

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

Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
    $bExit = True
    $vRet = "A_" & _StringRepeat('Test', Random(1, 1000)) & "_Y"
    $iLen = (StringLen($vRet) + 1)
    $stStr = DllStructCreate('long iSize;wchar sStr[' & $iLen & ']')
    DllStructSetData($stStr, 'iSize', $iLen)
    DllStructSetData($stStr, 'sStr', $vRet)
    Return DllStructGetPtr($stStr)
EndFunc   ;==>_WM_COPYDATA

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

Link to comment
Share on other sites

Link to comment
Share on other sites

3 hours ago, Danyfirex said:

You can do something like this to remove that limitation.

Wow, i didn't thought about that one!

Thanks.

 

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

7 hours ago, Danyfirex said:

You can do something like this ....

So I wanted to time the IPC and added a timer
 

Spoiler
#include <WindowsConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>
#include <String.au3>

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
$sRet = _Send($hChild)
$hTimer = Round(TimerDiff($hTimer), 5) ; ..time it took to return
MsgBox(64, 'Return - ' & $hTimer, $sRet)

Func _Send($hWnd)
    Local $stData = DllStructCreate('ulong_ptr;dword;ptr')
    Local $aRet = DllCall('user32.dll', 'ptr', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($stData))
    Local $tSize = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($aRet[0]), 'long iSize')
    Local $stStr = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($aRet[0] + 4), 'wchar sStr[' & $tSize.iSize & ']')

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

Func _WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
    $bExit = True
    $vRet = "A_" & _StringRepeat('Test', Random(10, 100)) & "_Y" ; ..changed to try to avoid failure
    $iLen = (StringLen($vRet) + 1)
    $stStr = DllStructCreate('long iSize;wchar sStr[' & $iLen & ']')
    DllStructSetData($stStr, 'iSize', $iLen)
    DllStructSetData($stStr, 'sStr', $vRet)
    Return DllStructGetPtr($stStr)
EndFunc   ;==>_WM_COPYDATA

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

 

and came to see that it fails every so often :( 

I takes from 1 to 10 ms. to return ( unless it fails ), and that is quite good but the lack of reliability is a problem.
Is this ready to use code, or just an example for a more complete script ?

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

28 minutes ago, Bilgus said:

_WinAPI_SendMessageTimeout

nope, I see 

Local $tSize = _WinAPI_ReadProcessMemoryEx(WinGetProcess($hWnd), Ptr($aRet[0]), 'long iSize')
    ConsoleWrite(@TAB & $tSize.iSize & @CRLF) ; 19005632 <-- on this size, obviously wrong, fails

so it's related to that.

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

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...