Sign in to follow this  
Followers 0

Another Multi Process Helper

44 posts in this topic

Posted (edited)

I didnt want to sacrifice Scite's Syntax highlighting and keep it a bit simpler so thats what came out :D

Ok its not that simple any more.

Revision 30 CoProc.zip

Update Notes:

Revision 24

Fixed Memory Leak in _ProcSuspend() and _ProcResume()

Fixed Example_Download.au3 Links

Revision 25

New Optional Parameter $sRegistryBase for _SuperGlobalGet() and _SuperGlobalSet()

Revision 30

Fixed for To work with current Autoit Version

Added wrapper for DuplicateHandle Api

Function List
	_CoProc([$sFunction],[$vParameter]) Starts another Process and Calls $sFunc, Returns PID
	_SuperGlobalSet($sName,[$vValue],[$sRegistryBase]) Sets or Deletes a Superglobal Variable
	_SuperGlobalGet($sName,[$fOption],[$sRegistryBase]) Returns the Value of a Superglobal Variable
	_ProcSuspend($vProcess) Suspends all Threads in $vProcess (PID or Name)
	_ProcResume($vProcess) Resumes all Threads in $vProcess (PID or Name)
	_ProcessGetWinList($vProcess, $sTitle = Default, $iOption = 0) Enumerates Windows of a Process
	_CoProcReciver([$sFunction = ""]) Register/Unregister Reciver Function
	_CoProcSend($vProcess, $vParameter,[$iTimeout = 500],[$fAbortIfHung = True]) Send Message to Process
	_ConsoleForward($iPid1, [$iPid2], [$iPid3], [$iPidn])
	_ProcessEmptyWorkingSet($vPid = @AutoItPID,[$hDll_psapi],[$hDll_kernel32]) Removes as many pages as possible from the working set of the specified process.
	_DuplicateHandle($dwSourcePid, $hSourceHandle, $dwTargetPid = @AutoItPID, $fCloseSource = False) Returns a Duplicate handle
	_CloseHandle($hAny) Close a Handle

Example_Download.au3 doesent work right no more because the link is dead

Please read this bevore using _ProcSuspend() and _ProcResume().

i did this some time ago and i remeber taking something from someone somwhere.

if you find a piece of code inside, please forgive me.

if you want credit for it or want me to remove it dorp me a line...

Here are some examples:

#include "coproc.au3"

$iPidChild = _CoProc(Default, "_recv") ; Create new Procces, Set _recv() as Reciever function
Sleep(2000) ; Give some time to load new Process
_CoProcSend($iPidChild,"Something...")  ; Send a Message to new process

Func _recv($vParm)
	MsgBox(0,"Recieved",$vParm)
EndFuncoÝ÷ Ø.Ø®²ÄÜ¥'«½êÚºÚ"µÍÔÝ

HÑÜ[ØÙÜÙÂÚ[ÛYH	][ÝÐÛÔØË]LÉ][ÝÂÈH	ÌÎNÝ[]ØØ[ÜÝL	ÌÎNÈ[È[Ý[Þ
ÒSÑVJÔBÈÈÛÛXÝÈHÙÈXZ[ØÙÜÂ^TÙ]ÛÛ
	][ÝÓXZ[ØÙÜÈ	][ÝÈ	[È]]Ò]Q
BÌÍÚÛØÚÙ]HÔÝ[	][ÝÉ][ÝËL
BÚ[HBIÌÍÚXØÙHÔXØÙ
	ÌÍÚÛØÚÙ]
BRY	ÌÍÚXØÙ	ÝÈ[BWÐÛÔØÈ
	][Ý×Ó]ÐÛÛXÝ[Û][ÝË	ÌÍÚXØÙ
BBNÈÈYYÈÛÜÙHHÛØÚÙ]H]ÂBNÈØÙÜÈÚ[È]Q[YTÛY
L
BÑ[ÈÛÜÙØÙÜÂ[ÈÓ]ÐÛÛXÝ[Û	ÌÍÚXØÙ
BIÌÍÚXØÙHÑXØ]R[H
	ÌÍÙÚWÐÛÔØÔ[ÈÈÝYYHÛÔØÂBBIÌÍÚXØÙÂNÈH[HÈXØ]BBBP]]Ò]QÈÈÝ[YBBUYJHÈÛÜÙHHÛØÚÙ][H[ØÙÜÂRYÜ[^]U^TÙ]ÛÛ
	][ÝÕÛÜÙØÙÜÈ	][ÝÈ	[È]]Ò]Q
BSØØ[	ÌÍÜÐYUÔÙ[
	ÌÍÚXØÙ	][ÝÖ[ÝÛÛXÝYÈY	][ÝÈ	[È]]Ò]Q	[ÈÔBUÔÙ[
	ÌÍÚXØÙ	][ÝÒ[H[	][ÝÈ	[ÈÔBUÚ[HBBIÌÍÜÐY	[ÏHÔXÝ	ÌÍÚXØÙMBBRYÜ[^]BRYÝ[Ó[	ÌÍÜÐYH	ÝÈ[Ý[Ò[Ý	ÌÍÜÐYÔH[BBRYÝ[Ò[Ý	ÌÍÜÐY	][ÝÙ^]	][ÝÊHHH[^]BBRYÝ[Ò[Ý	ÌÍÜÐY	][ÝÓÙÐÞ	][ÝÊHHH[BBBSÙÐÞ
]]Ò]QÝ[ÓZY
	ÌÍÜÐY
ÊJBBBQ[YBBRYÝ[Ò[Ý	ÌÍÜÐY	][ÝÚ[	][ÝÊHHH[BBBUÔÙ[
	ÌÍÚXØÙ	][ÝÐÛÛ[X[Î][ÝÈ	[ÈÔBBBBUÔÙ[
	ÌÍÚXØÙ	][ÝÒ[HÈ[É][ÝÈ	[ÈÔBBBBUÔÙ[
	ÌÍÚXØÙ	][ÝÓÙÐÞ	ÓÙÉÝÈHH]I][ÝÈ	[ÈÔBBBBUÔÙ[
	ÌÍÚXØÙ	][ÝÑ^]H]Z]	][ÝÈ	[ÈÔBBBQ[YBBIÌÍÜÐYH	][ÝÉ][ÝÂBQ[YUÑ[[[ÈÏOIÝ×Ó]ÐÛÛXÝ[Û
Edited by piccaso

Share this post


Link to post
Share on other sites



Posted

It works really well picasso. I like your method of doing this.

Share this post


Link to post
Share on other sites

Posted (edited)

It works really well picasso. I like your method of doing this.

yeah nice job picasso Edited by WTS

Share this post


Link to post
Share on other sites

Posted

Assign("gi_CoProcParent", Number(EnvGet("CoProcParent")), 2)

Is BAD! lol.

Also i remember a glitch where BinaryString did not convert it to hex if it did not contain NON alphanumeric characters. Dont know if it is fixed or an error on my part. I usually just fixed it by adding a Chr(0) at the front and then stripping the first 2 bytes :D

Share this post


Link to post
Share on other sites

Posted

@RazerM,WTS

Thanks :">

Assign("gi_CoProcParent", Number(EnvGet("CoProcParent")), 2)

Is BAD! lol.

Why?

Also i remember a glitch where BinaryString did not convert it to hex if it did not contain NON alphanumeric characters. Dont know if it is fixed or an error on my part. I usually just fixed it by adding a Chr(0) at the front and then stripping the first 2 bytes :D

MsgBox(0,"",BinaryString("0x" & Hex(BinaryString("Hello"))))

works fine, but you made me nervous :wacko:

Share this post


Link to post
Share on other sites

Posted

Also i remember a glitch where BinaryString did not convert it to hex if it did not contain NON alphanumeric characters.

That's only if you are using String(BinaryString("Text")) to convert to hex. I had that same problem in another program but I fixed it using Hex(BinaryString("Text")).

Share this post


Link to post
Share on other sites

Posted (edited)

after keeping the changes secret for some months i finaly managed to update it ;)

... i'm getting old, i had to read my own function headers to understand my code.

so let this be a lesson to all you non documenting function authors out there :lmao:

Edited by piccaso

Share this post


Link to post
Share on other sites

Posted

after keeping the changes secret for some months i finaly managed to update it ;)

... i'm getting old, i had to read my own function headers to understand my code.

so let this be a lesson to all you non documenting function authors out there :lmao:

I'm going to play with these over the weekend, but the work looks really good ... thanks :evil:

Share this post


Link to post
Share on other sites

Posted

I'm going to play with these over the weekend, but the work looks really good ... thanks :lmao:

your welcome, Thanks ;)

let me know what you think of it...

Updated first post, added changelog too...

Share this post


Link to post
Share on other sites

Posted (edited)

i really like the changes piccaso. I have used your UDF's quite a few times but I always change these to functions:

Func _SuperGlobalSet($sName, $vValue = "", $regkey = "HKEY_CURRENT_USER\Software\AutoIt v3\CoProc")
 Local $vTmp
 If $vValue = "" Then
  RegDelete($regkey, $sName)
  If @error Then Return SetError(2, 0, False) ; Registry Problem
 Else
  $vValue = StringTrimLeft(Hex(BinaryString(Chr(0) & $vValue)), 2)
  If @error Then
   Return SetError(1, 0, False) ; Wrong variable type
  Else
   RegWrite($regkey, $sName, "REG_BINARY", $vValue)
   If @error Then Return SetError(2, 0, False) ; Registry Problem
  EndIf
 EndIf
 Return True
EndFunc   ;==>_SuperGlobalSet

Func _SuperGlobalGet($sName, $fOption = False, $regkey = "HKEY_CURRENT_USER\Software\AutoIt v3\CoProc")
 Local $vTmp
 $vTmp = RegRead($regkey, $sName)
 If @error Then Return SetError(1, 0, "") ; Registry Problem
 If $fOption Then
  _SuperGlobalSet($sName)
  If @error Then SetError(2)
 EndIf
 Return BinaryString("0x" & $vTmp)
EndFunc   ;==>_SuperGlobalGet
The only thing I have changed is a paramater so I can choose my own registry key. This is because in a compiled exe I want it to write to its own registry key. Edited by RazerM

Share this post


Link to post
Share on other sites

Posted

my idea was to use the global variable $gs_SuperGlobalRegistryBase to point to a costum location but i will make it compatible to your version (if you dont mind) so both methods will work.

nice idea ;)

Share this post


Link to post
Share on other sites

Posted

No problem. Thanks.

Share this post


Link to post
Share on other sites

Posted (edited)

This UDF is very nice, except for one problem: If you have 2 scripts running communicating witch each other and the active window is a third app, the communication doesn't work at all.

Edited by 59FIFTY

Share this post


Link to post
Share on other sites

Posted

Sorry 59FIFTY, i didn't get notified by the forum...

could you be more specific?

because it works for me...

Updated to work with the current autoit version.

And i added an example on how to use a socket in another process.

i wonder why nobody ever posed a way to use sockets that way, after all that multithread whining :)

Share this post


Link to post
Share on other sites

Posted

... i'm getting old, i had to read my own function headers to understand my code.

For someone who's getting old, you sure make some kickass scripts

Excellent job :)

Share this post


Link to post
Share on other sites

Posted

can you supply us with some more info regarding how to use coproc with parameterS (more than 1!!!) ?!

Share this post


Link to post
Share on other sites

Posted

can you supply us with some more info regarding how to use coproc with parameterS (more than 1!!!) ?!

Hi Armand,

please look at the attachement "CoProc.zip" in the first post.

@picasso

Thanks for this amazing UDF, i take it to my favorites.

Multiprozessing looks like more professional with your functions.

Share this post


Link to post
Share on other sites

Posted

@ReCoder

wow... that helped alot (NOT...)

but thanks anyhow...

Share this post


Link to post
Share on other sites

Posted

Thank you very much Picasso I have been using your suspend/resume in a project of mine the updates are appreciated. I have learned much from study of your work thank you.

Share this post


Link to post
Share on other sites

Posted (edited)

I think that need update for current version , when try to use it says that are useddeprecated var types calling dll....

Edit

I did it by myself , replase long_ptr with long

Edited by N4rk0

Share this post


Link to post
Share on other sites

Posted

Anyone able to use this with 3.2.10.0, im have alot trouble getting it to work now. I replaced long_ptr also but it wont copy any handles anyways.

Share this post


Link to post
Share on other sites

Posted

replace 'long_ptr' with 'long*' and it will work again

Share this post


Link to post
Share on other sites

Posted

Anyone able to use this with 3.2.10.0, im have alot trouble getting it to work now. I replaced long_ptr also but it wont copy any handles anyways.

Me too. I replaced long_ptr (2 replacement), but it doesn't work

Share this post


Link to post
Share on other sites

Posted

The Example_tcpserver doesn't work.

I can't write in registry (for se super variable) if I am not admin. :D

Share this post


Link to post
Share on other sites

Posted (edited)

The Example_tcpserver doesn't work because the handle is not a socket handle error 10038, maybe the duplicate handle doesn't work.

The handle is always 1768, when the handle in main process change everytme.

On my computer it doesn't work but on virtual machine works. Why????

Edited by Fabry

Share this post


Link to post
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
Sign in to follow this  
Followers 0