The application started years ago when I discovered some trouble with the autoit3 compile concepts - to buildin all includes totally, no selective of only used functions and constants and that is just what this tool do - read in depth what is used and not, no limits how deep it goes 'reused functions from other .udf in these includes' . Another thing is that some peoble has concerns that scripts can be read after the 'wrap into an execute' well this tool makes script almost non readable - check out this script your self...
One has to remember with these third level interpretted languages as 'autoit3' that they has to read in every character one by one, build constant variable lists and function lists before any action take place and Au3PreProcess can speed up the execute process and squize the application weight for some 500 Kb in some conditions as the final script only holds the used constans and functions...
The application is a beta version as only the PreProcess action is written and functional and I would like to get responce or ideers for implimentations but planned is to be able to write a Makefile to easy do a directly recompile, do a testing execute process and to do a directly compile pass to 'CompileIt.exe with or without intuition...
There is no way the application can cobe for directly created function calls with the function 'Call' and I do thing that it could be a problem with plug-ins' but I don't know jet here...
Copy the script below to a directory and use the Process gadget - this will do a PreProcessed Clone from the Process options in the local path with a '_Pre' attached...
Please report trouble but beaware that autoit3 is a 'typeless language' and not every Process options is wice in every conditions as ';' is a parametre for comments but could also be written into a string and then the string would be half and faulty...
Global Const $GUI_CHECKED= 1
Global Const $LVS_EX_GRIDLINES= 0x00000001
Global Const $LVS_EX_CHECKBOXES= 0x00000004
Global Const $LV_ERR=-1
Global Const $LVIF_STATE=0x8
Global Const $LVIS_STATEIMAGEMASK=0xF000
Global Const $LVM_SETITEMSTATE=($LVM_FIRST+43)
Global Const $MEM_MAP="uint;uint;ptr"
Global Const $MEM_MAP_HPROC=1
Global Const $MEM_MAP_ISIZE=2
Global Const $MEM_MAP_PMEM=3
Global Const $MEM_COMMIT=0x00001000
Global Const $MEM_RESERVE=0x00002000
Global Const $MEM_SHARED=0x08000000
Global Const $PAGE_READWRITE=0x00000004
Global Const $PROCESS_VM_OPERATION=0x00000008
Global Const $PROCESS_VM_READ=0x00000010
Global Const $PROCESS_VM_WRITE=0x00000020
HotKeySet("^q",'Exits');trap Q to quit
Global Const $Prefs='HKEY_CURRENT_USER\software\Au3PreProcess\Prefs'; preferences entry
Global Const $title='Au3Preprocess',$Rev='1.8'; title
Global $dm1,$Main,$Edit,$ListC,$ConstC,$FuncC,$PreproC,$RemCommBC,$RemCommTC,$RemBlankC,$RemTabsC,$RemLinesC,$RemOpeC,$RemPreC,$DoCompC,$DoCheckC,$LabelC,$WriteC,$ReloadC,$RemoveC,$DoTestC,$CompileC; Global main controls
Global Const $Au3Path=RegRead('HKLM\Software\AutoIt v3\AutoIt','InstallDir'); get AutoIt3 path
Global $RemCommB,$RemCommT,$RemBlank,$RemTabs,$RemLines,$RemOpe,$DoComp,$DoCheck; buttons variables to preferences
Global $ProTM,$RunTM,$ComTM,$TopTM,$AboTM,$ExiTM; Tray menus item variables
Global $includelist,$functionlist,$UsedFunctionslist; internal database variables with a blank character as sepperator
Global $Chars; The main script to check-to speedup process we hold it
Global Const $cc=Chr(0x3B),$ch=$cc&' ======================================================================='&@CRLF
GLobal $filein,$fileout,$inpath
ReadPrefs($Prefs); read in the preferences
MainWin(); open main intuition
While 1
$msg=GUIGetMsg(1)
Select
Case $msg[1]=0x00000000; Non initiated ticks handle
Case $msg[1]=$Main; Main window handle
Select
Case $msg[0]=-3; Quit main window handle
Exits()
Case $msg[0]=$RemCommBC
$RemCommB=GUICtrlRead($RemCommBC)
Case $msg[0]=$RemCommTC
$RemCommT=GUICtrlRead($RemCommTC)
Case $msg[0]=$RemBlankC
$RemBlank=GUICtrlRead($RemBlankC)
Case $msg[0]=$RemTabsC
$RemTabs=GUICtrlRead($RemTabsC)
Case $msg[0]=$RemLinesC
$RemLines=GUICtrlRead($RemLinesC)
Case $msg[0]=$RemOpeC
$RemOpe=GUICtrlRead($RemOpeC)
Case $msg[0]=$DoCompC
$DoComp=GUICtrlRead($DoCompC)
Case $msg[0]=$DoCheckC
$DoCheck=GUICtrlRead($DoCheckC)
Case $msg[0]=$PreproC
ExecutePreProcess()
Case $msg[0]=$DoTestC
GUICtrlSetData($LabelC,'Not inteplementated jet-Use Process...')
Case $msg[0]=$WriteC
GUICtrlSetData($LabelC,'Not inteplementated jet-Use Process...')
EndSelect
EndSelect
Wend
Exits()
Func ExecutePreProcess()
If $Filein='' Or StringRight($Filein,1)='\' Then
$f=FileLoad('Load in a file to PreProcess...',$inPath,'Scripts (*.aut;*.au3)')
If $f='' Then
MsgBox(48,'ERROR...','Okay Project Cancel')
Return
Else
If FileExists($f) Then
$Filein=$f
Else
MsgBox(48,'ERROR...','ERROR-Project file failed')
Return
Endif
EndIf
EndIf
GUICtrlSendMsg($ListC,0x1009,0,0)
GUICtrlSendMsg($FuncC,0x1009,0,0)
GUICtrlSendMsg($ConstC,0x1009,0,0)
$fileout=StringReplace($filein,'.','_Pre.')
GetIncludeList($Filein); Init the variable $includelist containing used #includes
GetSubIncludes(); Check all subincludes for includes and insert these into the listview display
MakeFuncAvailableList()
MakeDeepCheckForNewFunctions()
SampleMainAndSubFunctionsTemporary()
CheckTemporaryScriptForGlobalConstants()
WritePreprocessedScriptAndCleanUp($fileout)
Dim $includelist='',$functionlist='',$UsedFunctionslist='',$inpath=StringMid($filein,1,StringInStr($filein,'\',0,-1)),$filein=''
EndFunc
Func WritePreprocessedScriptAndCleanUp($file)
Dim $in=@ScriptDir&'\Temp\TmpScript.txt',$header=$ch&$cc&' '&$title&' '&$Rev&' Preprocessed-Date '&@MDAY&':'&@MON&':'&@YEAR&' Time '&@HOUR&':'&@MIN&@CRLF&$ch
$IDI=FileOpen($in,2)
$ID=FileOpen(@ScriptDir&'\Temp\TmpConstants.txt',0)
$chars=$header&FileRead($ID)&$chars
FileClose($ID)
FileWrite($IDI,$chars)
FileClose($IDI)
$IDO=FileOpen($file,2)
$IDI=FileOpen($in,0)
While 1
$Line=FileReadLine($IDI)
If @error Then Exitloop
$wd=StringInStr($line,$cc)
if $RemCommB=1 AND $wd=1 Then; remove comment blocks
$line='?'
ElseIf $RemCommT=1 AND $wd>1 Then; remove traling comments
$Line=StringMid($line,1,$wd-1)
EndIf
if StringInStr($line,'#include ')=1 Then; Remove Includes
If StringLeft($line,1)='#' Then
$line='?'
EndIf
Elseif $RemLines=1 AND StringLen(StringStripWS($Line,8))=0 Then; remove empty lines
$line='?'
Elseif $RemBlank=1 Then
$line=StringStripWS($Line,7)
EndIf
if $RemTabs=1 Then; remove tab characters
$line=StringReplace($Line,'','')
EndIf
If $line<>'?' then FileWriteLine($IDO,$Line)
WEnd
FileClose($IDI)
FileClose($IDO)
If $RemOpe=1 Then; remove blank characters around operators
$IDI=FileOpen($file,0)
$chars=FileRead($IDI)
FileClose($IDI)
$chars=StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(StringReplace(Strin
gReplace(StringReplace($chars,'=','='),'+','+'),'-','-'),'>','>'),'<','<'),'*','*'),'<>','<>'),'&','&')
$IDO=FileOpen($file,2)
FileWrite($IDO,StringReplace(StringReplace(StringReplace(StringReplace(StringReplace($chars,'>=','>='),'<=','<='),',',','),'+=','+='),'-=','-='))
FileClose($IDI)
EndIf
If $DoCheck=1 Then
$IDI=FileOpen($file,0)
$chars=FileRead($IDI)
FileClose($IDI)
If StringInStr($chars,'Case $msg[1]=0x00000000')=0 Or StringInStr($chars,'Case $msg[1]=0')=0 then _say('no ticks catch function')
If StringInStr($chars,' Call(')>0 then _say('ERROR-Posible trouble with user-defined function durring the "CALL" function')
If StringInStr($chars,'PluginOpen(')>0 then _say('ERROR-Posible trouble with plugin as this feature is not preprocessed')
EndIf
CleanUp()
EndFunc
Func CheckTemporaryScriptForGlobalConstants()
Dim $tmp=@ScriptDir&'\Temp\Constants.txt',$in=@ScriptDir&'\Temp\TmpScript.txt',$out=@ScriptDir&'\Temp\TmpConstants.txt',$lines[9999]
$ID=FileOpen($tmp,0)
$IDI=FileOpen($in,0)
$chars=FileRead($IDI)
$IDO=FileOpen($out,10)
dim $a=1,$t=''
While 1
$Line=FileReadLine($ID)
If @error Then Exitloop
$wd=_GetWord($Line,3)
If StringLeft($wd,1)='$' Then
$a+=1
$lines[$a]=$line
If StringInStr($chars,$wd) Then
FileWriteLine($IDO,$Line)
GUICtrlCreateListViewItem($wd,$ConstC)
$t=$t&$wd
EndIf
EndIf
WEnd
$lines[0]=$a
FileClose($ID)
FileClose($IDI)
FileClose($IDO)
$IDO=FileOpen($out,0)
$tmpconst=FileRead($IDO)
FileClose($IDO)
$a=0
Do
$a+=1
$wd=_GetWord($Lines[$a],3)
If StringInStr($tmpconst,$wd)>0 AND StringInStr($t,$wd)=0 Then
$tmpconst=$lines[$a]&@CRLF&$tmpconst
$t=$t&$wd
$a=0
GUICtrlCreateListViewItem($wd,$ConstC)
EndIf
Until $a=$lines[0]
$IDO=FileOpen($out,2)
FileWrite($IDO,$tmpconst)
FileClose($IDO)
EndFunc
Func SampleMainAndSubFunctionsTemporary()
Dim $tmp=@ScriptDir&'\Temp\TmpFunctions.txt',$out=@ScriptDir&'\Temp\TmpScript.txt'
$IDI=FileOpen($tmp,0)
$IDO=FileOpen($out,10)
$Funcs=FileRead($IDI)
FileWrite($IDO,$chars)
FileWriteLine($IDO,@CRLF&$ch&'; Preprocessed included functions...'&@CRLF&$ch)
FileWrite($IDO,$Funcs)
FileClose($IDI)
FileClose($IDO)
EndFunc
Func MakeDeepCheckForNewFunctions()
$tmp=@ScriptDir&'\Temp\TmpFunctions.txt'
If Fileexists($tmp) Then FileDelete($tmp)
Do
$tmpfunctionlist=_CountWords($UsedFunctionslist)
GetMainScriptUsedFunctions($Filein)
CheckForFuncInFunctions()
Until _CountWords($UsedFunctionslist)=$tmpfunctionlist
EndFunc
Func CheckForFuncInFunctions()
Dim $tmp=@ScriptDir&'\Temp\TmpFunctions.txt'
$ID=FileOpen($tmp,0)
While 1
$Line=FileReadLine($ID)
If @error Then Exitloop
$wd=StringInStr($Line,' _'); check for blank character before
If $wd=0 Then
$wd=StringInStr($Line,'_'); check for Tab character before
ElseIf $wd=0 Then
$wd=StringInStr($Line,'=_'); check for non blank character before
EndIf
If $wd>4 then
$wd=_Getword(StringReplace(StringMid($line,$wd),'(',' '),1); get first word with change the ( character to blank character-then the function call is first word
If StringInStr($UsedFunctionslist,$wd)=0 Then; check for dubblets in database and if not pressent include into temporary database and file-tmpfunctions.txt
$UsedFunctionslist=$UsedFunctionslist&' '&$wd
GUICtrlCreateListViewItem($wd,$FuncC)
$IDO=FileOpen($tmp,9)
$IDI=FileOpen(@ScriptDir&'\Temp\'&$wd&'.au3',0)
$Funcs=FileRead($IDI)
FileWrite($IDO,$Funcs)
FileClose($IDI)
FileClose($IDO)
Endif
EndIf
WEnd
FileClose($ID)
EndFunc
Func GetMainScriptUsedFunctions($File)
Dim $tmp=@ScriptDir&'\Temp\TmpFunctions.txt'
$ID=FileOpen($File,0)
IF $ID=-1 THEN Return
$chars=FileRead($ID)
FileClose($ID)
$NumOfFunctions=_CountWords($functionlist)
For $a=1 To $NumOfFunctions
$wd=_GetWord($functionlist,$a)
If StringInStr($chars,$wd)>0 Then
If StringInStr($UsedFunctionslist,$wd)=0 Then
$UsedFunctionslist=$UsedFunctionslist&' '&$wd
GUICtrlCreateListViewItem($wd,$FuncC)
$IDI=FileOpen(@ScriptDir&'\Temp\'&$wd&'.au3',0)
$IDO=FileOpen($tmp,9)
$Funcs=FileRead($IDI)
FileWrite($IDO,$Funcs)
FileClose($IDI)
FileClose($IDO)
EndIf
EndIf
Next
EndFunc
Func MakeFuncAvailableList()
Dim $NumIncludes=_CountWords($includelist),$sw=0
For $a=1 To $NumIncludes
$wd=_GetWord($includelist,$a)
$ID=FileOpen($Au3Path&'\Include\'&$wd,0)
While 1
$Line=FileReadLine($ID)
If @error Then Exitloop
If StringLower(StringLeft($Line,5))='func ' Then
$tmp=_Getword(StringReplace($Line,'(',' '),2)
$IDO=FileOpen(@ScriptDir&'\Temp\'&$tmp&'.au3',10)
FileWriteLine($IDO,$Line)
$functionlist=$functionlist&' '&$tmp
$sw=1
Elseif $sw=1 Then
FileWriteLine($IDO,$Line)
If StringLower(StringLeft($Line,7))='endfunc' Then
$sw=1
FileClose($IDO)
EndIf
EndIf
WEnd
FileClose($ID)
Next
EndFunc
Func GetIncludeList($File)
If StringInStr($File,'.au3')=0 then Return; check for filetype
$ID=FileOpen($File,0)
IF $ID=-1 THEN Return
GUICtrlSetData($LabelC,'Checking for include lines-Please wait...')
For $a=1 To 50
$Line=FileReadLine($ID)
If @error Then Exitloop
$pos=StringInStr($line,'#include')
If $pos>0 then
If StringInStr(StringLeft($Line,$Pos),$cc)=0 AND StringInStr($line,'-once')=0 Then
$tmp=StringReplace(StringReplace(StringReplace(StringReplace($line,"'",' '),'"',' '),'<',' '),'>',' ')
$tmp=_Getword(StringMid($tmp,$Pos+9),1)
If StringInStr($includelist,$tmp)=0 Then
$includelist=$includelist&' '&$tmp
EndIf
EndIf
EndIf
Next
FileClose($ID)
GUICtrlSetData($LabelC,'Done...')
Return
EndFunc
Func GetSubIncludes()
dim $NumIncludes=_CountWords($includelist),$a=0,$wd,$tmp=@ScriptDir&'\Temp\Constants.txt'
If Fileexists($tmp) Then FileDelete($tmp)
Do; Get all used includes also in sub scripts
$a+=1
$wd=_GetWord($includelist,$a)
GetIncludeList($Au3Path&'\Include\'&$wd)
$NumIncludes=_CountWords($includelist)
GUICtrlCreateListViewItem($wd,$listC); display all in the listview
_GUICtrlListViewSetCheckState($listC,$a-1,1); check them all
$ID=FileOpen($Au3Path&'\Include\'&$wd,0)
$IDO=FileOpen($tmp,9)
While 1
$Line=FileReadLine($ID)
If @error OR StringLower(StringLeft($Line,5))='func ' Then Exitloop
If StringInStr($line,'Global ')>0 then
FileWriteLine($IDO,$Line)
EndIf
WEnd
FileClose($ID)
FileClose($IDO)
Until $a=$NumIncludes
EndFunc
Func MainWin()
$Main=GuiCreate($title&' '&$Rev,620,305 ,$dm1[1],$dm1[2])
;GUISetIcon(@ScriptDir&"\Data\Default.ico",'',$Main)
$ListC=GUICtrlCreateListView('Checked Includes',0,0,150,280,-1,BitOr($LVS_EX_CHECKBOXES,$LVS_EX_GRIDLINES))
$FuncC=GUICtrlCreateListView('Builin Functions',150,0,150,280,-1,$LVS_EX_GRIDLINES)
$ConstC=GUICtrlCreateListView('Included Global Constants',300,0,150,280,-1,$LVS_EX_GRIDLINES)
GUICtrlCreateGroup('Special PreProcess Actions',460,5,152,178)
$RemCommBC=GUICtrlCreateCheckbox('Remove comment blocks',467,20,-1,-1)
$RemCommTC=GUICtrlCreateCheckbox('Remove trail comments',467,40,-1,-1)
$RemBlankC=GUICtrlCreateCheckbox('Remove multi blank chars',467,60,-1,-1)
$RemTabsC=GUICtrlCreateCheckbox('Remove Tab chars',467,80,-1,-1)
$RemLinesC=GUICtrlCreateCheckbox('Remove empty Lines',467,100,-1,-1)
$RemOpeC=GUICtrlCreateCheckbox('Remove around operators',467,120,-1,-1)
$DoCompC=GUICtrlCreateCheckbox('Auto Compile',467,160,-1,-1)
$LabelC=GUICtrlCreateInput('',0,284,620,20)
GUICtrlCreateGroup('MakeFile',460,185,72,94)
$WriteC=GUICtrlCreateButton('Write',465,205,60,20)
$ReloadC=GUICtrlCreateButton('ReLoad',465,230,60,20)
$RemoveC=GUICtrlCreateButton('Remove',465,255,60,20)
GUICtrlCreateGroup('Action',540,185,72,94)
$PreproC=GUICtrlCreateButton('Process',545,205,60,20)
$DoTestC=GUICtrlCreateButton('Run test',545,230,60,20)
$CompileC=GUICtrlCreateButton('Compile',545,255,60,20)
GUICtrlSendMsg($listC,0x101E,0,146)
GUICtrlSendMsg($ConstC,0x101E,0,146)
GUICtrlSendMsg($FuncC,0x101E,0,146)
GUICtrlSendMsg($ListC,0x14,0,2)
If $RemCommB=1 Then GuiCtrlSetState($RemCommBC,$GUI_CHECKED)
If $RemCommT=1 Then GuiCtrlSetState($RemCommTC,$GUI_CHECKED)
If $RemBlank=1 Then GuiCtrlSetState($RemBlankC,$GUI_CHECKED)
If $RemTabs=1 Then GuiCtrlSetState($RemTabsC,$GUI_CHECKED)
If $RemLines=1 Then GuiCtrlSetState($RemLinesC,$GUI_CHECKED)
If $RemOpe=1 Then GuiCtrlSetState($RemOpeC,$GUI_CHECKED)
If $DoComp=1 Then GuiCtrlSetState($DoCompC ,$GUI_CHECKED)
If $DoCheck=1 Then GuiCtrlSetState($DoCheckC ,$GUI_CHECKED)
GuiSetState()
TraySetIcon(@ScriptDir&"\Data\Default.ico",0)
TraySetToolTip('Au3PreProcess 1.8-The AutoIt3 script PreProcessor')
EndFunc
Func ReadPrefs($Prefs)
$var=RegRead($Prefs,"1")
If @error Then $var='182 234';Main: x y
$dm1=StringSplit($var," ")
$RemCommB=RegRead($Prefs,'RemCommB')
If @error Then $RemCommB='4'
$RemCommT=RegRead($Prefs,'RemCommT')
If @error Then $RemCommT='4'
$RemBlank=RegRead($Prefs,'RemBlank')
If @error Then $RemBlank='4'
$RemTabs=RegRead($Prefs,'RemTabs')
If @error Then $RemTabs='4'
$RemLines=RegRead($Prefs,'RemLines')
If @error Then $RemLines='4'
$RemOpe=RegRead($Prefs,'RemOperators')
If @error Then $RemOpe='4'
$RemPre=RegRead($Prefs,'RemPreprocess')
If @error Then $RemPre='4'
$DoComp=RegRead($Prefs,'DoCompile')
If @error Then $DoComp='4'
$DoCheck=RegRead($Prefs,'CheckSpecial')
If @error Then $DoCheck='4'
$inpath=RegRead($Prefs,'InFilePath')
If @error then $inpath=$Au3Path
EndFunc
Func WritePrefs($Prefs)
$tmp=WinGetPos($Main)
If $tmp[0]>0 Then
RegWrite($Prefs,'1','REG_SZ',$tmp[0]&' '&$tmp[1])
If @error Then MsgBox(48,"ERROR...","Save preferences failed")
RegWrite($Prefs,'RemCommB','REG_SZ',$RemCommB)
RegWrite($Prefs,'RemCommT','REG_SZ',$RemCommT)
RegWrite($Prefs,'RemBlank','REG_SZ',$RemBlank)
RegWrite($Prefs,'RemTabs','REG_SZ',$RemTabs)
RegWrite($Prefs,'RemLines','REG_SZ',$RemLines)
RegWrite($Prefs,'RemOperators','REG_SZ',$RemOpe)
RegWrite($Prefs,'CheckSpecial','REG_SZ',$DoCheck)
RegWrite($Prefs,'DoCompile','REG_SZ',$DoComp)
RegWrite($Prefs,'InFilePath','REG_SZ',$inpath)
EndIf
EndFunc
Func Exits()
WritePrefs($Prefs)
CleanUp()
Exit
EndFunc
Func CleanUp()
local $d=@ScriptDir&'\Temp'
If FileExists($d) Then
IF DirRemove($d,1) Then
GUICtrlSetData($LabelC,'Temporary files removed and Preprocessed file created...')
Else
GUICtrlSetData($LabelC,'ERROR-Failed to remove temporary files but the preprocessed file created...')
EndIf
EndIf
EndFunc
Func FileLoad($mess,$Path,$suff)
$var=FileOpenDialog($mess,$Path,$Suff,5)
If @error Then Return ''
Return StringReplace($var,"|",@CRLF)
EndFunc
Func _GUICtrlListViewSetCheckState($h_listview,$i_index,$i_check=1)
Local $struct="int;int;int;int;int;ptr;int;int;int;int;int;ptr",$ret
Local $p=DllStructCreate($struct)
If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)
DllStructSetData($p,1,$LVIF_STATE)
DllStructSetData($p,2,$i_index)
If ($i_check) Then
DllStructSetData($p,4,0x2000)
Else
DllStructSetData($p,4,0x1000)
EndIf
DllStructSetData($p,5,$LVIS_STATEIMAGEMASK)
If IsHWnd($h_listview) Then
Local $pIndex=DllStructGetPtr($p)
Local $iSize=DllStructGetSize($p)
Local $rMemMap
Local $pMemory=_MemInit ($h_listview,$iSize+4096,$rMemMap)
If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)
_MemWrite ($rMemMap,$pIndex)
If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)
$ret=_SendMessage ($h_listview,$LVM_SETITEMSTATE,$i_index,$pMemory)
If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)
_MemFree ($rMemMap)
If @error Then Return SetError($LV_ERR,$LV_ERR,$LV_ERR)
Else
$ret=GUICtrlSendMsg($h_listview,$LVM_SETITEMSTATE,$i_index,DllStructGetPtr($p))
EndIf
Return $ret
EndFunc;==>_GUICtrlListViewSetCheckState
Func _GetWord($st,$no)
If NOT IsString($st) OR NOT IsInt($no) OR $no<1 Then
SetError(1)
Return ''
EndIf
$st=StringReplace(StringReplace(StringReplace($st,'',' '),' ',' '),' ',' ')
$len=StringLen($st)
FOR $a=1 TO $len
$b=StringMid($st,$a,1)
If $b<>' ' Then Exitloop
Next
$st=StringMid($st,$a)
$st=StringSplit($st,' ')
If $no>$st[0] Then return ''
Return $st[$no]
EndFunc
Func _CountWords($st)
If NOT IsString($st) Then
SetError(1)
Return ''
EndIf
$st=StringReplace(StringReplace(StringReplace($st,'',' '),' ',' '),' ',' ')
$len=StringLen($st)
FOR $a=1 TO $len
$b=StringMid($st,$a,1)
If $b<>' ' Then Exitloop
Next
For $b=$len TO 1 Step -1
$c=StringMid($st,$b,1)
If $c<>' ' Then Exitloop
Next
$st=StringSplit(StringMid($st,$a,$b-$a+1),' ')
Return $st[0]
EndFunc
Func _Say($st)
ConsoleWrite($st&@CR)
EndFunc
Func _MemInit($hWnd,$iSize,ByRef $rMemMap,$pAddress=0)
Local $iAccess,$iAllocation
Local $pMemory,$hProcess
Local $iProcessID
_GetWindowThreadProcessId($hWnd,$iProcessID)
$iAccess=BitOR($PROCESS_VM_OPERATION,$PROCESS_VM_READ,$PROCESS_VM_WRITE)
$hProcess=_OpenProcess($iAccess,False,$iProcessID)
Switch @OSVersion
Case "WIN_ME","WIN_98","WIN_95"
$iAllocation=BitOR($MEM_RESERVE,$MEM_COMMIT,$MEM_SHARED)
$pMemory=_VirtualAlloc($pAddress,$iSize,$iAllocation,$PAGE_READWRITE)
Case Else
$iAllocation=BitOR($MEM_RESERVE,$MEM_COMMIT)
$pMemory=_VirtualAllocEx($hProcess,$pAddress,$iSize,$iAllocation,$PAGE_READWRITE)
EndSwitch
If @error Then Return SetError(-1,-1,0)
$rMemMap=DllStructCreate($MEM_MAP)
DllStructSetData($rMemMap,$MEM_MAP_HPROC,$hProcess)
DllStructSetData($rMemMap,$MEM_MAP_ISIZE,$iSize)
DllStructSetData($rMemMap,$MEM_MAP_PMEM,$pMemory)
Return $pMemory
EndFunc;==>_MemInit
Func _SendMessage($h_hWnd,$i_msg,$wParam=0,$lParam=0,$i_r=0,$s_t1="int",$s_t2="int")
Local $a_ret=DllCall("user32.dll","long","SendMessage","hwnd",$h_hWnd,"int",$i_msg,$s_t1,$wParam,$s_t2,$lParam)
If @error Then Return SetError(@error,@extended,"")
If $i_r>=0 And $i_r<=4 Then Return $a_ret[$i_r]
Return $a_ret
EndFunc;==>_SendMessage
Func _GetWindowThreadProcessId($hWnd,ByRef $iProcessID)
Local $rProcessID,$aResult
$rProcessID=DllStructCreate("int")
$aResult=DllCall("User32.dll","int","GetWindowThreadProcessId","hwnd",$hWnd,"ptr",DllStructGetPtr($rProcessID))
If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)
$iProcessID=DllStructGetData($rProcessID,1)
Return $aResult[0]
EndFunc;==>_GetWindowThreadProcessId
Func _OpenProcess($iAccess,$bInherit,$iProcessID)
Local $aResult=DllCall("Kernel32.Dll","int","OpenProcess","int",$iAccess,"int",$bInherit,"int",$iProcessID)
If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)
Return $aResult[0]
EndFunc;==>_OpenProcess
Func _VirtualAlloc($pAddress,$iSize,$iAllocation,$iProtect)
Local $aResult=DllCall("Kernel32.dll","ptr","VirtualAlloc","ptr",$pAddress,"int",$iSize,"int",$iAllocation,"int",$iProtect)
If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)
Return $aResult[0]
EndFunc;==>_VirtualAlloc
Func _VirtualAllocEx($hProcess,$pAddress,$iSize,$iAllocation,$iProtect)
Local $aResult=DllCall("Kernel32.dll","ptr","VirtualAllocEx","int",$hProcess,"ptr",$pAddress,"int",$iSize,"int",$iAllocation,"int",$iProtect)
If @error Or Not IsArray($aResult) Then Return SetError(-1,-1,0)
Return $aResult[0]
EndFunc;==>_VirtualAllocEx
Happy new year
kjactive
Edited by jpm, 30 December 2006 - 10:08 PM.





