
prazetto
Active Members-
Posts
56 -
Joined
-
Last visited
Everything posted by prazetto
-
Better way to handle many parameters for a function?
prazetto replied to orbs's topic in AutoIt Technical Discussion
Variadic. What's up that? Variable argument? maybe these are what you looking while AutoIt3 still don't support it! . ; variadic trick $a = array('damn!', 45, ptr(80), array(3, 2)) $b = array('yeah...') array_push($a, 'k', 1, 6.7) array_push($a, $b) array_push($a, 5, 6, 7, 'you!') print_r($a) ; php.array.au3 by me (prazetto) that also posted in another thread #include-once ; array ( mixed $arg0, mixed $arg1, mixed $arg2 .. mixed $argN ) : array ; array_push ( $array, mixed $arg0, mixed $arg1, mixed $arg2 .. mixed $argN ) : Number ; array_pop ( $array ) : Number ; array_delete ( $array, $element ) this func support 2D Array ; array_search ( mixed $needle , array $haystack , opt bool $strict = 0) : Number ; ~ array_search ( array $haystack , mixed $needle , opt bool $strict = 0) : Number ; array_exist : alias of in_array() ; array_rand ( array $input , opt int $num_req = 1 ) : mixed ; array_reverse ( array $array , opt bool $preserve_keys = false ): array ; array_sum ( array $array ) : number ; array_shift ( array &$array ) : mixed ; array_unshift ( array &$array , mixed $var [, mixed $... ] ) : int ; array_unique ( array $array [, int $sort_flags = SORT_STRING ] ) : array ; in_array ( mixed $needle , array $haystack , opt bool $strict = 0 ) : bool Func array($a=0,$b=0,$c=0,$d=0,$e=0,$f=0,$g=0,$h=0,$i=0,$j=0,$k=0,$l=0,$m=0,$n=0,$o=0,$p=0,$q=0,$r=0,$s=0,$t=0,$u=0,$v=0,$w=0,$x=0,$y=0,$z=0) Local $chr = 97, $agc = @NumParams Local $arr[$agc] For $lop = 1 To $agc $arr[$lop - 1] = Eval(Chr($chr)) $chr += 1 Next Return $arr EndFunc Func array_push(ByRef $arr, $var, $a=0,$b=0,$c=0,$d=0,$e=0,$f=0,$g=0,$h=0,$i=0,$j=0,$k=0,$l=0,$m=0,$n=0,$o=0,$p=0,$q=0,$r=0,$s=0,$t=0,$u=0,$v=0,$w=0,$x=0,$y=0,$z=0) Local $chr = 97, $agc = @NumParams - 1 If Not IsArray($arr) Then Local $avb[$agc] $arr = $avb $arr[0] = $var For $lop = 1 To $agc -1 $arr[$lop] = Eval(Chr($chr)) $chr += 1 Next Return $agc Else Local $ubn = UBound($arr) ReDim $arr[$ubn + $agc] $arr[$ubn] = $var For $lop = 1 To $agc -1 $arr[$ubn + $lop] = Eval(Chr($chr)) $chr += 1 Next Return $ubn + $agc EndIf EndFunc Func array_pop(ByRef $arr) Local $ret, $ubn = UBound($arr) - 1 If Not IsArray($arr) Then Return SetError(1, 0, 0) $ret = $arr[$ubn] ; array in array destroy If IsArray($arr[$ubn]) Then $arr[$ubn] = 0 If $ubn = 0 Then Local $und $arr = $und Return SetError(0, 1, $ret) EndIf ReDim $arr[$ubn] Return $ret EndFunc Func array_delete(ByRef $arr, $elm) If Not IsArray($arr) Then Return SetError(1, 0, 0) Local $ubn = UBound($arr, 1) - 1 ; Bounds check If $elm < 0 Then $elm = 0 If $elm > $ubn Then $elm = $ubn ; Move items after $elm up by 1 Switch UBound($arr, 0) Case 1 ; array in array destroy If IsArray($arr[$elm]) Then $arr[$elm] = 0 For $i = $elm To $ubn - 1 $arr[$i] = $arr[$i + 1] Next ; return undefined variable default If $ubn = 0 Then Local $und $arr = $und Return 0 EndIf ReDim $arr[$ubn] Case 2 Local $max = UBound($arr, 2) - 1 ; array in 2D array destroy For $j = 0 To $max If IsArray($arr[$elm][$j]) Then $arr[$elm][$j] = 0 Next For $i = $elm To $ubn - 1 For $j = 0 To $max $arr[$i][$j] = $arr[$i + 1][$j] Next Next ; return undefined variable default If $ubn = 0 Then Local $und $arr = $und Return 0 EndIf ReDim $arr[$ubn][$max + 1] Case Else Return SetError(1, 1, 0) EndSwitch Return $ubn EndFunc Func in_array($ndl, ByRef $arr, $stc = 0) If array_search($ndl, $arr, $stc) = -1 Then Return 0 Else Return 1 EndIf EndFunc Func array_exist($ndl, ByRef $arr, $stc = 0) If array_search($ndl, $arr, $stc) = -1 Then Return 0 Else Return 1 EndIf EndFunc ;Func array_search(ByRef Const $ndl, ByRef Const $arr, $stc = 0) Func array_search($ndl, $arr, $stc = 0) Local $agc = UBound($arr) ; overload to allow param type swapping with keep access variable as ByRef If IsArray($ndl) Then Return array_search($arr, $ndl, $stc) If $agc = 0 Then Return -1 $agc -= 1 Switch VarGetType($ndl) Case 'String' For $lop = 0 To $agc If IsString($arr[$lop]) Then If StringCompare($arr[$lop], $ndl, $stc) == 0 Then Return $lop EndIf Next Case 'Bool' If $stc Then For $lop = 0 To $agc If IsBool($arr[$lop]) Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc Switch VarGetType($arr[$lop]) Case 'Int32', 'Int64', 'ptr' If $ndl = True Then If $arr[$lop] <> 0 Then Return $lop Else If $arr[$lop] = 0 Then Return $lop EndIf Case Else If $arr[$lop] = $ndl Then Return $lop EndSwitch Next EndIf Case 'Int32' If $stc Then For $lop = 0 To $agc If VarGetType($arr[$lop]) = 'Int32' Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf Case 'Int64' If $stc Then For $lop = 0 To $agc If VarGetType($arr[$lop]) = 'Int64' Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf Case 'Ptr' ; HWnd also trapped here If $stc Then For $lop = 0 To $agc If IsPtr($arr[$lop]) Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf EndSwitch Return -1 EndFunc Func array_search_instring(ByRef Const $ndl, ByRef Const $arr, $stc = 0) Local $agc = UBound($arr) ; overload to allow param type swapping with keep access variable as ByRef If IsArray($ndl) Then Return array_search_instring($arr, $ndl, $stc) If $agc = 0 Then Return -1 $agc -= 1 Switch VarGetType($ndl) Case 'String' For $lop = 0 To $agc If IsString($arr[$lop]) Then If StringInStr($arr[$lop], $ndl, $stc) <> 0 Then Return $lop EndIf Next Case 'Bool' If $stc Then For $lop = 0 To $agc If IsBool($arr[$lop]) Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc Switch VarGetType($arr[$lop]) Case 'Int32', 'Int64', 'ptr' If $ndl = True Then If $arr[$lop] <> 0 Then Return $lop Else If $arr[$lop] = 0 Then Return $lop EndIf Case Else If $arr[$lop] = $ndl Then Return $lop EndSwitch Next EndIf Case 'Int32' If $stc Then For $lop = 0 To $agc If VarGetType($arr[$lop]) = 'Int32' Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf Case 'Int64' If $stc Then For $lop = 0 To $agc If VarGetType($arr[$lop]) = 'Int64' Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf Case 'Ptr' ; HWnd also trapped here If $stc Then For $lop = 0 To $agc If IsPtr($arr[$lop]) Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf EndSwitch Return -1 EndFunc Func array_search_or($ndl, $arr, $nd2, $stc = 0) Local $agc = UBound($arr) ; overload to allow param type swapping with keep access variable as ByRef If IsArray($ndl) Then Return array_search_or($arr, $ndl, $nd2, $stc) If $agc = 0 Then Return -1 $agc -= 1 Switch VarGetType($ndl) Case 'String' For $lop = 0 To $agc If IsString($arr[$lop]) Then If (StringCompare($arr[$lop], $ndl, $stc) == 0) Or _ (StringCompare($arr[$lop], $nd2, $stc) == 0) Then Return $lop EndIf Next Case 'Bool' If $stc Then For $lop = 0 To $agc If IsBool($arr[$lop]) Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc Switch VarGetType($arr[$lop]) Case 'Int32', 'Int64', 'ptr' If $ndl = True Then If $arr[$lop] <> 0 Then Return $lop Else If $arr[$lop] = 0 Then Return $lop EndIf Case Else If $arr[$lop] = $ndl Then Return $lop EndSwitch Next EndIf Case 'Int32' If $stc Then For $lop = 0 To $agc If VarGetType($arr[$lop]) = 'Int32' Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf Case 'Int64' If $stc Then For $lop = 0 To $agc If VarGetType($arr[$lop]) = 'Int64' Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf Case 'Ptr' ; HWnd also trapped here If $stc Then For $lop = 0 To $agc If IsPtr($arr[$lop]) Then If $arr[$lop] = $ndl Then Return $lop EndIf Next Else For $lop = 0 To $agc If $arr[$lop] = $ndl Then Return $lop Next EndIf EndSwitch Return -1 EndFunc ; @err 1 @ext 1 = param 1 not array or array zero ; 2 = param 2 not an number ; 3 = param 2 are invalid and is negative number ; 4 = param 2 requested exceed max value of array param 1 Func array_rand(ByRef $arr, $req = 1) Local $und, $rnd, $ubn = UBound($arr) If $ubn = 0 Then Return SetError(1, 1, $und) $ubn -= 1 Switch $req Case 0 Return $und Case 1 $rnd = Random(0, $ubn, 1) Return $arr[$rnd] Case Else If Not IsNumber($req) Then Return SetError(1, 2, $und) If $req < 0 Then Return SetError(1, 3, $und) If $req > $ubn Then Return SetError(1, 4, $und) Local $avb[$req] $req -= 1 For $lop = 0 To $req $avb[$lop] = $arr[Random(0, $ubn, 1)] Next Return $avb EndSwitch Return $und EndFunc Func array_reverse(ByRef $arr) Local $und, $ubn = UBound($arr) If $ubn = 0 Then Return SetError(1, 0, $und) Local $avb[$ubn], $cnt $ubn -= 1 $cnt = $ubn For $lop = 0 To $ubn $avb[$cnt] = $arr[$lop] $cnt -= 1 Next Return $avb EndFunc Func array_sum(ByRef $arr) Local $ret, $ubn = UBound($arr) If $ubn = 0 Then Return SetError(1, 0, 0) $ubn -= 1 If IsNumber($arr[0]) Or IsPtr($arr[0]) Then For $lop = 0 To $ubn $ret += $arr[$lop] Next EndIf If IsString($arr[0]) Then For $lop = 0 To $ubn $ret &= $arr[$lop] Next EndIf Return $ret EndFunc Func array_shift(ByRef $arr) Local $ret, $ubn = UBound($arr) If $ubn = 0 Then Return SetError(1, 0, $ret) $ret = $arr[0] array_delete($arr, 0) Return $ret EndFunc Func array_unshift(ByRef $arr, $var, $a=0,$b=0,$c=0,$d=0,$e=0,$f=0,$g=0,$h=0,$i=0,$j=0,$k=0,$l=0,$m=0,$n=0,$o=0,$p=0,$q=0,$r=0,$s=0,$t=0,$u=0,$v=0,$w=0,$x=0,$y=0,$z=0) Local $chr = 97, $agc = @NumParams - 1 If Not IsArray($arr) Then Local $avb[$agc] $arr = $avb $arr[0] = $var For $lop = 1 To $agc -1 $arr[$lop] = Eval(Chr($chr)) $chr += 1 Next Return $agc Else Local $ubn, $add, $cnt $ubn = UBound($arr) $add = $ubn + $agc ReDim $arr[$add] For $lop = $add - 1 To 0 Step -1 $cnt = $lop - $agc $arr[$lop] = $arr[$cnt] ; array in array destroy If IsArray($arr[$cnt]) Then $arr[$cnt] = 0 If ($lop) = $agc Then ExitLoop Next $arr[0] = $var $agc -= 1 For $lop = 1 To $agc $arr[$lop] = Eval(Chr($chr)) $chr += 1 Next Return $add EndIf EndFunc Func array_unique(ByRef $arr, $sfg = 0) Local $ret, $ubn = UBound($arr) If $ubn = 0 Then Return SetError(1, 0, $ret) array_push($ret, $arr[0]) For $lop = 1 To $ubn-1 If array_search($ret, $arr[$lop], 1) = -1 Then array_push($ret, $arr[$lop]) Next Return $ret EndFunc Func array_valid(ByRef $arr, $i = 0) Switch @NumParams Case 1 Return IsArray($arr) Case 2 Return IsArray($arr[$i]) EndSwitch EndFunc Func array_count(ByRef $arr, $i = 0) Switch @NumParams Case 1 Return UBound($arr) Case 2 If UBound($arr) < $i + 1 Then Return 0 Return UBound($arr[$i]) EndSwitch EndFunc Func array_value(ByRef $arr, $i, $j = 0, $k = 0) Switch @NumParams Case 2 If Not IsArray($arr) Or UBound($arr) = 0 Then Return SetError(1, 0, 0) If $i >= UBound($arr) Then Return SetError(1, 0, 0) Return $arr[$i] Case 3 Return array_value($arr[$i], $j) Case 4 Return array_value($arr[$i], $j, $k) EndSwitch EndFunc ;Func array_change(ByRef $arr, ByRef $_, $i, $j = 0, $k = 0) Func array_change(ByRef $arr, $_, $i, $j = 0, $k = 0) Switch @NumParams-1 Case 2 If Not IsArray($arr) Or UBound($arr) = 0 Then Return SetError(1, 0, 0) If $i >= UBound($arr) Then Return SetError(1, 0, 0) $arr[$i] = $_ Case 3 array_change($arr[$i], $_, $j) Case 4 array_change($arr[$i], $_, $j, $k) EndSwitch EndFunc Func array_count2(ByRef $arr, $i, $j = 0, $k = 0) Switch @NumParams Case 2 If Not IsArray($arr) Or UBound($arr) = 0 Then Return SetError(1, 0, 0) If $i >= UBound($arr) Then Return SetError(1, 0, 0) Return UBound($arr) Case 3 Return array_count2($arr[$i], $j) Case 4 Return array_count2($arr[$i], $j, $k) EndSwitch EndFunc Func array_value2(ByRef $arr, $i, $j) Return array_value($arr[$i], $j) EndFunc Func array_search2(ByRef $arr, $i, ByRef $needle) Return array_search($arr[$i], $needle) EndFunc Func array_push2(ByRef $arr, $i, $var) If Not IsArray($arr) Then Local $va_arr[] = [] $arr = $va_arr EndIf If not IsArray($arr) Then ;newlinecode Local $va_arr[] = [] $arr = $va_arr EndIf If UBound($arr) < $i + 1 Then ReDim $arr[$i + 1] Return array_push($arr[$i], $var) EndFunc Func print_r($arr, $padspace='', $recursive=-1) Local $space, $n $space &= $padspace $n = UBound($arr) If IsArray($arr) Then If $recursive <> -1 Then ConsoleWrite($space & '[' & $recursive & '] ' & 'Array [' & $n & ']' & @CR) Else ConsoleWrite($space & 'Array [' & $n & ']' & @CR) EndIf $space &= ' ' EndIf $n -= 1 For $loop = 0 To $n Switch VarGetType($arr[$loop]) Case 'Array' print_r($arr[$loop], $space, $loop) Case 'Object' ConsoleWrite($space & '[' & $loop & '] ' & '[object]' & @CR) Case 'String' If StringInStr($arr[$loop], @CR) Or StringInStr($arr[$loop], @LF) Then Local $str = $arr[$loop] $str = StringReplace($str, @CRLF, @CR) $str = StringReplace($str, @LF, @CR) $str = StringReplace($str, @CR, @CR & $space & ' ') ConsoleWrite($space & '[' & $loop & '] ' & $str & @CR) Else ConsoleWrite($space & '[' & $loop & '] ' & $arr[$loop] & @CR) EndIf Case 'Int32', 'Int64' ConsoleWrite($space & '[' & $loop & '] ' & $arr[$loop] & @CR) Case 'ptr' ConsoleWrite($space & '[' & $loop & '] ' & $arr[$loop] & @CR) Case 'Bool' ConsoleWrite($space & '[' & $loop & '] ' & $arr[$loop] & @CR) Case 'Double' ConsoleWrite($space & '[' & $loop & '] ' & $arr[$loop] & @CR) Case 'Keyword' Switch IsKeyword($arr[$loop]) Case 1 ; Default ConsoleWrite($space & '[' & $loop & '] ' & 'Default : [keyword]' & @CR) Case 2 ; Null ConsoleWrite($space & '[' & $loop & '] ' & 'Null : [keyword]' & @CR) EndSwitch Case 'UserFunction', 'Function' ConsoleWrite($space & '[' & $loop & '] ' & StringLower(FuncName($arr[$loop])) & ' --> {function}' & @CR) Case Else ConsoleWrite($space & '[' & $loop & '] ' & $arr[$loop] & @CR) EndSwitch Next EndFunc Func array_setimax_value() EndFunc Func high(ByRef $arr) Local $ret $ret = UBound($arr) If $ret > 0 Then Return $ret -1 Else Return -1 EndIf EndFunc Func array_value_high(ByRef $arr, $stage=0) Local $nil, $r, $n = UBound($arr) If Not IsArray($arr) Or $n = 0 then Return SetError(1, 0, $nil) $n -= 1 $r = $n + $stage If $r < 0 then Return SetError(1, 1, $nil) If $n < $r then Return SetError(1, 2, $nil) Return $arr[$r] EndFunc Func array_value_high_add(ByRef $arr, $val, $stage=0) Local $nil, $r, $n = UBound($arr) If Not IsArray($arr) Or $n = 0 then Return SetError(1, 0, 0) $n -= 1 $r = $n + $stage If $r < 0 then Return SetError(1, 1, 0) If $n < $r then Return SetError(1, 2, 0) $arr[$r] += $val EndFunc . Output: . Array [12] [0] damn! [1] 45 [2] 0x00000050 [3] Array [2] [0] 3 [1] 2 [4] k [5] 1 [6] 6.7 [7] Array [1] [0] yeah... [8] 5 [9] 6 [10] 7 [11] you! -
One for the developers: variable name length
prazetto replied to qwert's topic in AutoIt Technical Discussion
Another important thing is reuse variable if doesn't needed anymore on next sequence. Variable given name such as $_, $__, $___, $____, $_____ and etc. Unreadable aren't it Func dontlook_a() Local $_ = 'long text...' & _ 'long text...' & _ 'long text...' & _ 'long text...' & _ 'long text...' ; do something else with $_ EndFunc Func dontlook_b() Local $_ $_ = 'long text...' $_ &= 'long text...' $_ &= 'long text...' $_ &= 'long text...' $_ &= 'long text...' ; do something else with $_ EndFunc -
@jchd Maybe I tell you something to convince you. Are you by any chance kidding me? An then you telling me 'is very unfair in that it forces the native function to zig-zag with a completely useless structure.' No, how about if I register 'PStringLowerMidNativeW' with DLLCallBackRegister and pointer that I got from DllCalbackkGetPtr I passes to an dll library or for hooking an library do you think AutoIt3 byref are working unless its specified that requester to do so with passing variant pointer compatible to AutoIt3 data type. The name that you so called 'completely useless structure' is heart of every WideCharString (Unicode UTF16) and the param $P in PStringLowerMidNativeW and PStringLowerMidWinApiW are param datatype is pwidecharstring (Delphi/Pascal) and wchar_t* or lpwstr (in CC++) . How dare you change $P to ByRef $str, aren't the prototype become different and is AutoIt3 variant. And the prefix name for function is P should at least tell you what's is meaning behind it. #Also how can few ms difference matter in a function that obviously will not be used in tight loops? Whatcha that is just an example and also I think its not required to gave an example as complex such as control component of gui written in AutoIt3. The speed is an matter for me with make sure every function that I usage inside it are the fastest one, that's is all. #ANSI functions are useless with native AutoIt strings. Yes, I agree. repeated word that I point to czardas is 'If its AutoIt3 string then we all know to usage Native AutoIt3 function are the best way but when its are another then its also another case.' As for caching an variable on non performance test block and passing AutoIt3 string as byref in performance test block you are more unfair toward me jchd Now PStringLowerMidNativeW and PStringLowerMidWinApiW have different prototype. So what is the point to compare now!?
-
@guinness As developer you are playing unfair, thats your script is not fair and square. My performance test showing in another different result. Uh, no is complete reverse of your script. @czardas Its not so different because the two are do same thing. Just where is suit you place it on implementing in your script. If its AutoIt3 string then we all know to usage Native AutoIt3 function are the best way but when its are another then its also another case. . Global $p_CharLowerBuffW = GetAddr('user32.dll', 'CharLowerBuffW') ; Lets assume and think in your head we already have these string in memory that created ; by another library. However in this test we artificially generate lpwstr by AutoIt3. $twstr = DllStructCreate('wchar str[61]') $twstr.str = "BBBBBCCCCCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBCCCCCC" $pwstr = DllStructGetPtr($twstr) PStringLowerMidNativeW($pwstr, 10, 50, 60) ConsoleWrite($twstr.str & @CRLF) $twstr = DllStructCreate('wchar str[61]') $twstr.str = "BBBBBCCCCCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBCCCCCC" $pwstr = DllStructGetPtr($twstr) PStringLowerMidWinapiW($pwstr, 10, 50, 60) ConsoleWrite($twstr.str & @CRLF) Global $twstrarray[9999999] Global $lpstrarray[9999999] ; create 1600 job to be lowercased on the middle of string ; for first 800 shall take care by native and last 800 shall take care by winapi For $loop = 0 To 1600 $twstrarray[$loop] = DllStructCreate('wchar str[61]') $twstrarray[$loop].str = "BBBBBCCCCCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBCCCCCC" $lpstrarray[$loop] = DllStructGetPtr($twstrarray[$loop]) Next Local $hTimer = 0 $hTimer = TimerInit() For $loop = 0 To 799 ; 800 first job take care by native PStringLowerMidNativeW($lpstrarray[$loop], 10, 50, 60) Next $timediff1 = TimerDiff($hTimer) ConsoleWrite('PStringLowerMidNativeW --> ' & $timediff1 & @CRLF) $hTimer = TimerInit() For $loop = 799 To 1600 ; 800 last job take care by winapi PStringLowerMidWinapiW($lpstrarray[$loop], 10, 50, 60) Next $timediff2 = TimerDiff($hTimer) ConsoleWrite('PStringLowerMidWinapiW --> ' & $timediff2 & @CRLF) StatisticPerf('PStringLowerMidNativeW', 'PStringLowerMidWinapiW', $timediff1, $timediff2) ; Both PStringLowerMidNativeW and PStringLowerMidWinapiW doesn't included ; with memory range check or null_ptr check expression for error, assume ; it all are valid cause this test perormace. Func PStringLowerMidNativeW($P, $start, $end, $len) Local $twstr, $str $twstr = DllStructCreate('wchar [' & $len & ']', $P) $str = DllStructGetData($twstr, 1) $str = StringLeft($str, $start) & StringLower(StringMid($str, $start+1, $end-$start)) & StringRight($str, $len - $end) DllStructSetData($twstr, 1, $str) EndFunc ; remeber we play with wide string, 1 wchar_t is 2 byte in memory Func PStringLowerMidWinapiW($P, $start, $end, $len) DllCallAddress("dword", $p_CharLowerBuffW, "ptr", $P+($start*2), "dword", $end-$start) EndFunc Func GetAddr($lib, $symbol) Local $user32 = DllCall('kernel32.dll', 'ptr', 'GetModuleHandleA', 'str', $lib) Local $addr = DllCall('kernel32.dll', 'ptr', 'GetProcAddress', 'ptr', $user32[0], 'str', $symbol) Return $addr[0] EndFunc Func StatisticPerf($name1, $name2, $time1, $time2) Local $procentage, $comma, $procediff If $time1 > $time2 Then $procentage = ((($time1-$time2) / $time1) * 100) $comma = StringInStr($procentage, '.') If $comma > 0 Then $procentage = StringLeft($procentage, $comma+ 2) EndIf $procediff = '±' & $procentage & '%' $procentage = '±' & $procentage + 100 & '%' ConsoleWrite('! The ' & $name2 & ' ' & $procentage & ' is faster than ' & $name1 & ' with difference ' & $procediff & @CRLF) ConsoleWrite('! The ' & $name2 & ' completing job in ' & $time2 & ' mS' & @CRLF) ConsoleWrite('! The ' & $name1 & ' completing job in ' & $time1 & ' mS' & @CRLF) ConsoleWrite('! The difference beween two are ' & $time1-$time2 & ' mS' & @CRLF) EndIf If $time2 > $time1 Then $procentage = ((($time2-$time1) / $time2) * 100) $comma = StringInStr($procentage, '.') If $comma > 0 Then $procentage = StringLeft($procentage, $comma+ 2) EndIf $procediff = '±' & $procentage & '%' $procentage = '±' & $procentage + 100 & '%' ConsoleWrite('! The ' & $name1 & ' ' & $procentage & ' is faster than ' & $name2 & ' with difference ' & $procediff & @CRLF) ConsoleWrite('! The ' & $name1 & ' completing job in ' & $time1 & ' mS' & @CRLF) ConsoleWrite('! The ' & $name2 & ' completing job in ' & $time2 & ' mS' & @CRLF) ConsoleWrite('! The difference beween two are ' & $time2-$time1 & ' mS' & @CRLF) EndIf EndFunc . This are output which I tested with AutoIt3 v3.3.10.2 in Microsoft Windows XP Professional x64 Edition Version 2003 Service Pack 2 Intel® Core2 Duo CPU E7500 @ 2.93 GHz, 3.74 GB of RAM . >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Administrator\Desktop\yyy.au3" BBBBBCCCCCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBBBBBCCCCCC BBBBBCCCCCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaBBBBBCCCCCC PStringLowerMidNativeW --> 17.9764865325605 PStringLowerMidWinapiW --> 10.5822212751449 ! The PStringLowerMidWinapiW ±141.13% is faster than PStringLowerMidNativeW with difference ±41.13% ! The PStringLowerMidWinapiW completing job in 10.5822212751449 mS ! The PStringLowerMidNativeW completing job in 17.9764865325605 mS ! The difference beween two are 7.39426525741561 mS >Exit code: 0 Time: 0.336 .
-
@Manadar What are you saying is exactly right, and for sure you are know about this than another user. Then allow me to describe to other. DLLCall("libraryname.dll".. is slower than Global $mlibraryname = DllOpen("libraryname.dll") DLLCall($mlibraryname... is slower than DLLCallAddress(..., ptr_function ... The fastest one is DLLCallAddress! Why? DLLCall("libraryname.dll".. always increment & decrement reference to library and call GetProcAddress then calling the address pointer. DLLCall($mlibraryname.. always call GetProcAddress then calling the address pointer. DLLCallAddress(..., ptr_function ... directly call the address pointer. DLLCallAddress skip all unnecessary step. That's why now I'm decided to use DLLCallAddress as wrapper of library function. However be careful check for null pointer if you not sure if the function are exported by library or you typed wrongly the symbol name. This DLLCallAddress function are one of greatest addition feature on AutoIt3. As for native function of AutoIt3 is hard to beat its speed in simple expression of string manipulation. But when its complex its can be beaten by another like calling an library or shellcode or machinecode. But that defeat the point to writting script on AutoIt3 in the first place if in the end you also write it in another language. By the way AutoIt3 is always be greatest scripting language on windows in my heart.
-
I talk and I have example. There are which is suit the case and also which is doesn't suit the case. For an example manipulation string where that string to be manipulated are reside on buffer or pointer to string then what are you doing maybe is can be right. By eliminating DllStructGetData and DllStructSetData. When your manipulation like upercassing or lowercasing on all of it or in the middle of string then stringmid, string prepend and append expression can be eliminated. Usage it on windowproc is the recommended way or the another recommend are when you build an text editor one level up from scratch by general with usage tons of function manipulation borrowed from some library. By that reason then why not, and if your reason doesn't meet my criteria then I tell you maybe now is not the time you playing with these. Wait for and you see the another time the one that I gave you maybe useful. This are part of my unpublished UDF. Sample how to usage are script on below, yes scroll down until very bottom. The output text are tested with AutoIt3 v3.3.10.2. . ;===== RTLCODE == RTLCODE == RTLCODE == RTLCODE == RTLCODE == RTLCODE == RTLCODE == RTLCODE == RTLCODE ===== ;================================================= Corefx.RTL.au3 ========================================== Global Const _ $__intptr = (@AutoItX64) ? ('Int64') : ('Int32'), _ $__invptr = (@AutoItX64) ? ('Int32') : ('Int64'), _ $__kernel = __rtl_module1('kernel32.dll'), _ $__fnaddr = __rtl_fnaddr(), _ $__krngma = __rtl_krngma(), _ $__ntdll = __rtl_module('ntdll.dll'), _ $__strlen = __rtl_strlen(), _ $__wcslen = __rtl_wcslen(), _ $__user = __rtl_module('user32.dll') Global _ $__pragma Func __pragma_link($_) If IsFunc($_) Then $_ = FuncName($_) If IsPtr($_) Then If $_ <> 0 Then $__pragma = $_ Return EndIf Return SetError(1, 0, 0) EndIf Switch $_ Case 'ntdll' $__pragma = $__ntdll Case 'kernel32' $__pragma = $__kernel Case 'user32' $__pragma = $__user Case Else Local $v = 'MOD_' & $_ $__pragma = eval($v) EndSwitch EndFunc Func __rtl_module1($_) Local $r = DllCall('kernel32.dll', 'ptr', 'GetModuleHandleA', 'str', $_) Return $r[0] EndFunc func __rtl_module($_) Local $r = DllCallAddress('ptr', $__krngma, 'str', $_) Return $r[0] endfunc func __rtl_krngma() Local $r = DllCallAddress('ptr', $__fnaddr, 'ptr', $__kernel, 'str', 'GetModuleHandleA') Return $r[0] endfunc Func __rtl_fnaddr() Local $r = DllCall('kernel32.dll', 'ptr', 'GetProcAddress', 'ptr', $__kernel, 'str', 'GetProcAddress') If @error Or $r[0] = 0 Then Return SetError(1, 0, 0) Return $r[0] EndFunc Func __name__($_, $F = 33) Local $r = DllCallAddress('ptr', $__fnaddr, 'ptr', $__pragma, 'str', $_) ;~ If $r[0] = 0 Then ;~ If IsFunc($F) Then $F = $F() ;~ If $_cor_dbg_osver <> 0 Then ;~ If $_cor_dbg_osver >= $F Then ;~ ConsoleWrite("! __pragma_link . __name__('" & $_ & "')" & ' ' & $_cor_dbg_osver & ' ' & $F & @CR) ;~ EndIf ;~ EndIf ;~ EndIf Return $r[0] EndFunc Func __rtl_acoracs(ByRef $v, ByRef $x, ByRef $_) Switch VarGetType($_) Case 'ptr' $v = 'ptr' $x = $v Case $__intptr If $_ >= 0 And $_ <= 255 Then $v = 'byte' Else $v = 'ptr' EndIf $x = $v Case $__invptr If $_ >= 0 And $_ <= 255 Then $v = 'byte' $x = $v Else If $__invptr = 'int64' Then $v = 'ptr' $_ = int64toptr($_) Else Return SetError(1, 0, 0) EndIf EndIf Case 'String' If StringLen($_) = 1 Then $v = 'byte' $_ = Asc($_) Else $v = 'str' EndIf $x = $v Case 'DLLStruct' $v = 'ptr' $x = 'struct*' EndSwitch EndFunc Func __rtl_wcorwcs(ByRef $v, ByRef $x, ByRef $_) Switch VarGetType($_) Case 'ptr' $v = 'ptr' $x = $v Case $__intptr If $_ >= 0 And $_ <= 255 Then $v = 'byte' Else $v = 'ptr' EndIf $x = $v Case $__invptr If $_ >= 0 And $_ <= 255 Then $v = 'word' $x = $v Else If $__invptr = 'int64' Then $v = 'ptr' $_ = int64toptr($_) Else Return SetError(1, 0, 0) EndIf EndIf Case 'String' If StringLen($_) = 1 Then $v = 'word' $_ = AscW($_) Else $v = 'wstr' EndIf $x = $v Case 'DLLStruct' $v = 'ptr' $x = 'struct*' EndSwitch EndFunc Func rtl_strlen($_) Local $r = DllCallAddress('uint_ptr:cdecl', $__strlen, _a_($_), $_) Return $r[0] EndFunc Func rtl_wcslen($_) Local $r = DllCallAddress('uint_ptr:cdecl', $__wcslen, _w_($_), $_) Return $r[0] EndFunc func __rtl_strlen() Local $r = DllCallAddress('ptr', $__fnaddr, 'ptr', $__ntdll, 'str', 'strlen') Return $r[0] endfunc func __rtl_wcslen() Local $r = DllCallAddress('ptr', $__fnaddr, 'ptr', $__ntdll, 'str', 'wcslen') Return $r[0] endfunc Func user32() Return $__user EndFunc Func int64toptr($i64) Local $t64, $t32, $l32, $h32 $t64 = DllStructCreate('int64') DllStructSetData($t64,1, $i64) $t32 = DllStructCreate('ptr;int', DllStructGetPtr($t64)) $h32 = DllStructGetData($t32,2) Return ($h32 = -1 Or $h32 = 0)?(DllStructGetData($t32,1)):(Ptr(0)) EndFunc ; AnsiChar-String pass type func _a_(byref Const $lpString) switch vargettype($lpString) case 'Ptr', $__intptr, $__invptr return 'ptr' case 'String' return 'str' case 'DLLStruct' return 'struct*' endswitch endfunc ; WideChar-String pass type func _w_(byref Const $lpString) switch vargettype($lpString) case 'Ptr', $__intptr, $__invptr return 'ptr' case 'String' return 'wstr' case 'DLLStruct' return 'struct*' endswitch endfunc Func addrof($_) Return DllStructGetPtr($_) EndFunc ;===== UDFCODE == UDFCODE == UDFCODE == UDFCODE == UDFCODE == UDFCODE == UDFCODE == UDFCODE == UDFCODE ===== ;======================= WinUser.WinUI.WindowsUserInterface.Resources.Strings.au3 ========================== __pragma_link ( user32 ) Global Const _ $ptr_user32_CharLowerA = __name__('CharLowerA'), _ $ptr_user32_CharLowerW = __name__('CharLowerW'), _ $ptr_user32_CharUpperA = __name__('CharUpperA'), _ $ptr_user32_CharUpperW = __name__('CharUpperW'), _ $ptr_user32_CharLowerBuffA = __name__('CharLowerBuffA'), _ $ptr_user32_CharLowerBuffW = __name__('CharLowerBuffW'), _ $ptr_user32_CharUpperBuffA = __name__('CharUpperBuffA'), _ $ptr_user32_CharUpperBuffW = __name__('CharUpperBuffW') Func WinAPI_CharLowerA($lpsz) Local $v, $x __rtl_acoracs($v, $x, $lpsz) If @error Then Return SetError(1, 0, '') Local $r = DllCallAddress($v, $ptr_user32_CharLowerA, $x, $lpsz) If @error Then Return SetError(1, 0, 0) Return (IsNumber($r[0]))?(Chr($r[0])):($r[0]) EndFunc Func WinAPI_CharLowerW($lpsz) Local $v, $x __rtl_wcorwcs($v, $x, $lpsz) If @error Then Return SetError(1, 0, '') Local $r = DllCallAddress($v, $ptr_user32_CharLowerW, $x, $lpsz) If @error Then Return SetError(1, 0, 0) Return (IsNumber($r[0]))?(ChrW($r[0])):($r[0]) EndFunc Func WinAPI_CharUpperA($lpsz) Local $v, $x __rtl_acoracs($v, $x, $lpsz) If @error Then Return SetError(1, 0, '') Local $r = DllCallAddress($v, $ptr_user32_CharUpperA, $x, $lpsz) If @error Then Return SetError(1, 0, 0) Return (IsNumber($r[0]))?(Chr($r[0])):($r[0]) EndFunc Func WinAPI_CharUpperW($lpsz) Local $v, $x __rtl_wcorwcs($v, $x, $lpsz) If @error Then Return SetError(1, 0, '') Local $r = DllCallAddress($v, $ptr_user32_CharUpperA, $x, $lpsz) If @error Then Return SetError(1, 0, '') Return (IsNumber($r[0]))?(ChrW($r[0])):($r[0]) EndFunc Func WinAPI_CharLowerBuffA($lpsz, $cchLength) Local $r = DllCallAddress('dword', $ptr_user32_CharLowerBuffA, _a_($lpsz), $lpsz, 'dword', $cchLength) If @error Then Return SetError(1, 0, 0) Return $r[0] EndFunc Func WinAPI_CharLowerBuffW($lpsz, $cchLength = -1) Local $r = DllCallAddress('dword', $ptr_user32_CharLowerBuffW, _w_($lpsz), $lpsz, 'dword', $cchLength) If @error Then Return SetError(1, 0, 0) Return $r[0] EndFunc Func WinAPI_CharUpperBuffA($lpsz, $cchLength) Local $r = DllCallAddress('dword', $ptr_user32_CharUpperBuffA, _a_($lpsz), $lpsz, 'dword', $cchLength) If @error Then Return SetError(1, 0, 0) Return $r[0] EndFunc Func WinAPI_CharUpperBuffW($lpsz, $cchLength) Local $r = DllCallAddress('dword', $ptr_user32_CharUpperBuffW, _w_($lpsz), $lpsz, 'dword', $cchLength) If @error Then Return SetError(1, 0, 0) Return $r[0] EndFunc ;===== USERCODE == USERCODE == USERCODE == USERCODE == USERCODE == USERCODE == USERCODE == USERCODE ===== ; AnsiChar <delphi>, char <C/C++> ConsoleWrite('WinAPI_CharLowerA -> ' & WinAPI_CharLowerA('A') & @CRLF) ConsoleWrite('WinAPI_CharUpperA -> ' & WinAPI_CharUpperA('a') & @CRLF) ConsoleWrite('WinAPI_CharLowerA -> ' & WinAPI_CharLowerA(asc('A')) & @CRLF) ConsoleWrite('WinAPI_CharUpperA -> ' & WinAPI_CharUpperA(asc('a')) & @CRLF) ; AnsiCharString <delphi>, lpstr, char* <C/C++> ; LowerCase AnsiString $sttest = DllStructCreate('char ourstr[60]') $sttest.ourstr = 'LOWERCASE' WinAPI_CharLowerA($sttest) ConsoleWrite('WinAPI_CharLowerA -> ' & $sttest.ourstr & @CRLF) ; UpperCase AnsiString $sttest = DllStructCreate('char ourstr[60]') $sttest.ourstr = 'uppercase' WinAPI_CharUpperA($sttest) ConsoleWrite('WinAPI_CharUpperA -> ' & $sttest.ourstr & @CRLF) ; All LowerCase $sttest = DllStructCreate('char ourstr[60]') $sttest.ourstr = 'THE QUICK BROWN FOX JUMP OVER LAZY DOG.' WinAPI_CharLowerBuffA($sttest, rtl_strlen($sttest)) ConsoleWrite('WinAPI_CharLowerBuffA -> ' & $sttest.ourstr & @CRLF) ; Partial LowerCase $sttest = DllStructCreate('char ourstr[60]') $sttest.ourstr = 'THE QUICK BROWN FOX JUMP OVER LAZY DOG.' WinAPI_CharLowerBuffA(addrof($sttest) + 6, rtl_strlen($sttest)-12) ConsoleWrite('WinAPI_CharLowerBuffA -> ' & $sttest.ourstr & @CRLF) ; All UpperCase $sttest = DllStructCreate('char ourstr[60]') $sttest.ourstr = 'The quick brown fox jump over lazy dog.' WinAPI_CharUpperBuffA($sttest, rtl_strlen($sttest)) ConsoleWrite('WinAPI_CharUpperBuffA -> ' & $sttest.ourstr & @CRLF) ; Partial UpperCase $sttest = DllStructCreate('char ourstr[60]') $sttest.ourstr = 'The quick brown fox jump over lazy dog.' WinAPI_CharUpperBuffA(addrof($sttest) + 6, rtl_strlen($sttest)-12) ConsoleWrite('WinAPI_CharUpperBuffA -> ' & $sttest.ourstr & @CRLF) ; WideChar <delphi>, wchar_t <C/C++> ConsoleWrite('WinAPI_CharLowerW -> ' & WinAPI_CharLowerW('W') & @CRLF) ConsoleWrite('WinAPI_CharUpperW -> ' & WinAPI_CharUpperW('w') & @CRLF) ConsoleWrite('WinAPI_CharLowerW -> ' & WinAPI_CharLowerW(ascw('W')) & @CRLF) ConsoleWrite('WinAPI_CharUpperW -> ' & WinAPI_CharUpperW(ascw('w')) & @CRLF) ; WideCharString <delphi>, lpwstr, wchar_t* <C/C++> ; LowerCase WideString $sttest = DllStructCreate('wchar ourstr[60]') $sttest.ourstr = 'LOWERCASE' WinAPI_CharLowerW($sttest) ConsoleWrite('WinAPI_CharLowerW -> ' & $sttest.ourstr & @CRLF) ; UpperCase WideString $sttest = DllStructCreate('wchar ourstr[60]') $sttest.ourstr = 'uppercase' WinAPI_CharUpperW($sttest) ConsoleWrite('WinAPI_CharUpperW -> ' & $sttest.ourstr & @CRLF) ; All LowerCase $sttest = DllStructCreate('wchar ourstr[60]') $sttest.ourstr = 'THE QUICK BROWN FOX JUMP OVER LAZY DOG.' WinAPI_CharLowerBuffW($sttest, rtl_wcslen($sttest)) ConsoleWrite('WinAPI_CharLowerBuffW -> ' & $sttest.ourstr & @CRLF) ; Partial LowerCase $sttest = DllStructCreate('wchar ourstr[60]') $sttest.ourstr = 'THE QUICK BROWN FOX JUMP OVER LAZY DOG.' WinAPI_CharLowerBuffW(addrof($sttest) + 6, rtl_wcslen($sttest)-12) ConsoleWrite('WinAPI_CharLowerBuffW -> ' & $sttest.ourstr & @CRLF) ; All UpperCase $sttest = DllStructCreate('wchar ourstr[60]') $sttest.ourstr = 'The quick brown fox jump over lazy dog.' WinAPI_CharUpperBuffW($sttest, rtl_wcslen($sttest)) ConsoleWrite('WinAPI_CharUpperBuffW -> ' & $sttest.ourstr & @CRLF) ; Partial UpperCase $sttest = DllStructCreate('wchar ourstr[60]') $sttest.ourstr = 'The quick brown fox jump over lazy dog.' WinAPI_CharUpperBuffW(addrof($sttest) + 6, rtl_wcslen($sttest)-12) ConsoleWrite('WinAPI_CharUpperBuffW -> ' & $sttest.ourstr & @CRLF) . Output: . >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "F:\CoreFXP\Sample.String\this.au3" WinAPI_CharLowerA -> a WinAPI_CharUpperA -> A WinAPI_CharLowerA -> a WinAPI_CharUpperA -> A WinAPI_CharLowerA -> lowercase WinAPI_CharUpperA -> UPPERCASE WinAPI_CharLowerBuffA -> the quick brown fox jump over lazy dog. WinAPI_CharLowerBuffA -> THE QUick brown fox jump over lazY DOG. WinAPI_CharUpperBuffA -> THE QUICK BROWN FOX JUMP OVER LAZY DOG. WinAPI_CharUpperBuffA -> The quICK BROWN FOX JUMP OVER LAZy dog. WinAPI_CharLowerW -> w WinAPI_CharUpperW -> W WinAPI_CharLowerW -> w WinAPI_CharUpperW -> W WinAPI_CharLowerW -> lowercase WinAPI_CharUpperW -> Uppercase WinAPI_CharLowerBuffW -> the quick brown fox jump over lazy dog. WinAPI_CharLowerBuffW -> THE quick brown fox jump over LAZY DOG. WinAPI_CharUpperBuffW -> THE QUICK BROWN FOX JUMP OVER LAZY DOG. WinAPI_CharUpperBuffW -> The QUICK BROWN FOX JUMP OVER lazy dog. >Exit code: 0 Time: 0.141
-
pending delete post
-
- scilexer
- scilexer x32
-
(and 1 more)
Tagged with:
-
Hi Ward, There is AP_Decompress machine code in every this Machine Code Algorithm Collection UDF to decompress that right called after base64 decoding every machine code embedded in UDF script. Mind you share the compressor itself. Or by the way what is algorithm name?
-
@jchd Thanks for the answer about the power of n and 2. The link you pointed out are very helpfull for me. Even the title of post are 'Latest Beta', but yes this are what I seek. Now I can continue my project. New update: After reading those page back to 21, page 22 (pointed one) and next page 23. At least it seem for me are temporary understand. After try to understand then I try to translate and test. The output size are match with DllStruct... family. Yes. Finally: ; assume member size Local $size[] = [2, 2, 4, 8, 1, 2] ; assume align 8, start at offset 0 Local $nAlign = 8, _ ; value are align option : 1, 2, 4, 8, 16 $iOffset = 0, _ $nTemp = 0, _ $nLargestSize = 8 ; there max(size[]) = 8 For $loop = 0 To UBound($size)-1 $iDataTypeSize = $size[$loop] ; Does this offset need padding first for correct alignment? If $iDataTypeSize < $nAlign Then $nTemp = Mod($iOffset, $iDataTypeSize) If $nTemp Then $nTemp = $iDataTypeSize - $nTemp Else $nTemp = Mod($iOffset, $nAlign) If $nTemp Then $nTemp = $nAlign - $nTemp EndIf $iOffset += $nTemp ; Update offset with padding ConsoleWrite('offset: #' & $loop & ' @ 0x' & Ptr($iOffset) & ' size: ' & $size[$loop] & @CR) $iOffset += $iDataTypeSize Next ConsoleWrite('offset: fn @ 0x' & Ptr($iOffset) & ' @pad :' & $iOffset & @CR) If ($nLargestSize < $nAlign) Then $nTemp = Mod($iOffset, $nLargestSize) If ($nTemp) Then $nTemp = $nLargestSize - $nTemp Else $nTemp = Mod($iOffset, $nAlign) If ($nTemp) Then $nTemp = $nAlign - $nTemp EndIf $iOffset = $iOffset + $nTemp; // Update offset with padding ConsoleWrite('offset: fn @ 0x' & Ptr($iOffset) & ' fin. :' & $iOffset & @CR & @CR) ConsoleWrite('Compare with Native function' & @CR) Local $mystruct = DllStructCreate('align ' & $nAlign & '; word; word; dword; int64; byte; word;') ConsoleWrite('DllStruct* Family : ' & DllStructGetSize($mystruct) & @CR) For $loop = 1 To 6 ConsoleWrite('offset: #' & $loop-1 & ' @ ' & DllStructGetPtr($mystruct, $loop) - DllStructGetPtr($mystruct, 1) & @CR ) Next ; jon: ;~ Individual member padding: ;~ // Does this offset need padding first for correct alignment? ;~ if (iDataTypeSize < nAlign) ;~ { ;~ nTemp = iOffset % iDataTypeSize; ;~ if(nTemp) ;~ nTemp = iDataTypeSize - nTemp; ;~ } ;~ else ;~ { ;~ nTemp = iOffset % nAlign; ;~ if(nTemp) ;~ nTemp = nAlign - nTemp; ;~ } ;~ iOffset += nTemp; // Update offset with padding ;~ End of structure padding: ;~ // Ensure the end of the structure is padded based on the size of the largest member ;~ if (nLargestSize < nAlign) ;~ { ;~ nTemp = iOffset % nLargestSize; ;~ if(nTemp) ;~ nTemp = nLargestSize - nTemp; ;~ } ;~ else ;~ { ;~ nTemp = iOffset % nAlign; ;~ if(nTemp) ;~ nTemp = nAlign - nTemp; ;~ } ;~ iOffset = iOffset + nTemp; // Update offset with padding ; jchd: ;~ Individual member: ;~ // Does this offset need padding first for correct alignment of next member whose size is iDataTypeSize? ;~ nTemp = min(iDataTypeSize, nAlign); ;~ iOffset += (nTemp - (iOffset % nTemp)) % nTemp; // Update offset with padding ;~ Struct tail: ;~ // Ensure the end of the structure is padded based on the size of the smallest of (largest member or pack size) ;~ nTemp = min(nLargestSize, nAlign); ;~ iOffsetIn = iOffset + (nTemp - (iOffset % nTemp)) % nTemp; // Update offset with padding Output: offset: #0 @ 0x0x00000000 size: 2 offset: #1 @ 0x0x00000002 size: 2 offset: #2 @ 0x0x00000004 size: 4 offset: #3 @ 0x0x00000008 size: 8 offset: #4 @ 0x0x00000010 size: 1 offset: #5 @ 0x0x00000012 size: 2 offset: fn @ 0x0x00000014 @pad :20 offset: fn @ 0x0x00000018 fin. :24 Compare with Native function DllStruct* Family : 24 offset: #0 @ 0x00000000 offset: #1 @ 0x00000002 offset: #2 @ 0x00000004 offset: #3 @ 0x00000008 offset: #4 @ 0x00000010 offset: #5 @ 0x00000012 See the twenty four number! Try change $nAlign, in my test. All align option 1, 2, 4, 8, 16 are match with native DllStruct... family.
- 2 replies
-
- algorithm
- translation
-
(and 2 more)
Tagged with:
-
For some obvious reason, Sucessfully to translate an #computing padding algorithm, and outputting same value with example of an explanation Lets take a breath, wiki say: The following formulas provide the number of padding bytes required to align the start of a data structure (where mod is the modulo operator): # pseudo-code, see actual code below padding = (align - (offset mod align)) mod align new offset = offset + padding = offset + (align - (offset mod align)) mod align For example, the padding to add to offset 0x59d for a structure aligned to every 4 bytes is 3. The structure will then start at 0x5a0, which is a multiple of 4. Note that when offset already is a multiple of align, the second modulo in (align - (offset mod align)) mod align is required to get a padding of 0. Then I write AutoIt3 script. ConsoleWrite(@CR & '+ Computing padding' & @CR) Local $align, $offset, $padding, $new_offset $align = 4 $offset = 0x59d $padding = Mod($align - Mod($offset, $align), $align) $new_offset = $offset + $padding + Mod($offset + ($align - Mod($offset, $align)), $align) ConsoleWrite('padding: ' & $padding & ' new offset: 0x' & StringLower(Hex($new_offset, 4)) & @CR) And the output is match with example in explanation. + Computing padding padding: 3 new offset: 0x05a0 The question #01 are is that are correct translation? changing second line on second (=) (see below) with plus sign (+) in AutoIt3 (see above) ? new offset = offset + padding = offset + (align - (offset mod align)) mod align . Again lets take a breath, wiki say: If the alignment is a power of two, the modulo operation can be reduced to a bitwise boolean AND operation. The following formulas provide the new offset (where & is a bitwise AND and ~ a bitwise NOT): padding = align - (offset & (align - 1)) = (-offset) & (align - 1) new offset = (offset + align - 1) & ~(align - 1) Then I write AutoIt3 script. ConsoleWrite(@CR & '+ align 2 - Power of Two' & @CR) Local $align, $offset, $padding, $new_offset $align = 2 $offset = 0x59d $padding = $align - (BitAND($offset, ($align - 1))) + BitAND((-$offset), ($align - 1)) $new_offset = BitAND(($offset + $align - 1), BitNOT($align - 1)) ConsoleWrite('padding: ' & $padding & ' new offset: 0x' & StringLower(Hex($new_offset, 4)) & @CR) And the output is. + align 2 - Power of Two padding: 2 new offset: 0x059e The question #02. First line and second (=) I replace with plus (+) sign, again is that correct? The question #03. What is meaning from the word of 'The Power of Two'? Are 2 is The Power of Two? Are 4, 8, 16 is The Power of Two? Which are the number are is The Power of Two and which is not? Can someone give me an confirmation if translation that pseudo-code to AutoIt3 are correct.? Can someone give me an explanation what is so called 'The Power of Two'.? Please answer even if you think this are childish question, because I'm not from Brittain nor from American.
- 2 replies
-
- algorithm
- translation
-
(and 2 more)
Tagged with:
-
How dose the compiler work
prazetto replied to MachinistProgrammer's topic in AutoIt Technical Discussion
<snip> I can't explain it or got banned. The forbidden one man. I'm not devs, but at least I can see what them do in highline. There the tools I say only Hex Editor and Resource Editor, but the other maybe I fear to write here. <snip> -
Removal of PlugIn, I don't care that much like someone elsehere. I'm never use it in my live! But I think the other feature like Volatile Func for synchronous COM event, I wish that feature shall be here as not an Experimental Feature, I fear that will be removed in near future. Cause that what I expect to so called feature long-long.......... ago in this AutoIt3 scripting language. >COM Events Handling | Flow of the Process Even I don't go to Feature Request. Maybe, someone else request it, or Jon by accidentally want to add Volatile feature.
-
How dose the compiler work
prazetto replied to MachinistProgrammer's topic in AutoIt Technical Discussion
<snip> -
Clean PC Source available in spoiler below 'Codice Sorgente' text, in that page. but download link: dead. Its still useful because at least the source are here while you able replace image file with what you have.
-
WildcardMatch an Fast Filename Pattern Match (UDF) Machine Code Version (x32 and x64) Repeat the word from an C/C++ Writer { Introduction Simple wild card matching with ? and * is something that we use in our every day work just when opening a command prompt and using DIR and DEL. But how can this be done correctly in your program? OK, you can use regular expressions, and I recommend this when you already use a bunch of Boost, tr1 or STL stuff in your code. But sometimes, I like it easy and simple without tons of library code in the background. And because I saw a lot of wrong and in complex queries "wrong/failing" code, I just offer this small algorithm here. Background This wildcard matching function works just the same way as you expect and know it from the CMD.EXE DIR command. Using the Code The function just takes the string to check as a first argument and the mask with or without any wildcard characters as a second argument. It returns true if the strings match and false if not. It isn't spectacular. The characters ? and * are treated as wildcards. A ? character matches exactly one character and doesn't match an empty string. A * character matches any sequence of characters and an empty string too. Other characters are compared caseless. I use CharUpper and convert them to uppercase to perform this task. Feel free to use your own favorite way. Because * matches any character sequence and an empty string WildcardMatch(_T(""),_T("*")) returns true. } by Martin Richter, 28 Apr 2011 on codeproject.com AutoIt3 WildcardMatch No, I'm not doing any translation the C/C++ WildcardMatch to our favorite scripting language: AutoIt V3. Instead modificate thats source to be: - Ansi and Wide text version of WildcardMatch. - Portable and meet the condition to be used on Shell Code or Machine Code (That what Ward, trancexx and other called it!). And then write an UDF. UDF Name : CoreFx.Wildcard.au3 Functions : CoreFx_WildcardMatchExA($string, $patern) CoreFx_WildcardMatchExW($string, $patern) Includes : CoreFx.DynamicCode.au3 General.Imports.au3 WinAPI.Kernel32.au3 Platform : x32 and x64 bit Sample : $test.au3 . Download In Single ZIP (File Size: 5 KB. All required file are included). CoreFx.Wildcard.zip Sample $test.au3 Outputs: Ansi Test Empty string 1 CoreFx_WildcardMatchExA("", "*") Return 1 Empty string 2 CoreFx_WildcardMatchExA("", "") Return 1 Simple 1 CoreFx_WildcardMatchExA("MyName.doc", "*.DOC") Return 1 Simple 2 CoreFx_WildcardMatchExA("MyName.docx", "*.DOC") Return 0 Complex 1 CoreFx_WildcardMatchExA("MyNamName.docx", "My*Name.*x") Return 1 Complex 2 CoreFx_WildcardMatchExA("MyNamName.docx", "My*Name.*oc") Return 0 A CoreFx_WildcardMatchExA("filename.txt", "*.txt") Return 1 B CoreFx_WildcardMatchExA("filename.txt", "*.tx?") Return 1 C CoreFx_WildcardMatchExA("filename.txt", "file*name.txt") Return 1 D CoreFx_WildcardMatchExA("filename.txt", "fil*ame.txt") Return 1 E CoreFx_WildcardMatchExA("filename.txt", "f*l*a*e.*x?") Return 1 Wide Test Empty string 1 CoreFx_WildcardMatchExW("", "*") Return 1 Empty string 2 CoreFx_WildcardMatchExW("", "") Return 1 Simple 1 CoreFx_WildcardMatchExW("MyName.doc", "*.DOC") Return 1 Simple 2 CoreFx_WildcardMatchExW("MyName.docx", "*.DOC") Return 0 Complex 1 CoreFx_WildcardMatchExW("MyNamName.docx", "My*Name.*x") Return 1 Complex 2 CoreFx_WildcardMatchExW("MyNamName.docx", "My*Name.*oc") Return 0 A CoreFx_WildcardMatchExW("filename.txt", "*.txt") Return 1 B CoreFx_WildcardMatchExW("filename.txt", "*.tx?") Return 1 C CoreFx_WildcardMatchExW("filename.txt", "file*name.txt") Return 1 D CoreFx_WildcardMatchExW("filename.txt", "fil*ame.txt") Return 1 E CoreFx_WildcardMatchExW("filename.txt", "f*l*a*e.*x?") Return 1 . Source A Simple Wildcard Matching Function (Martin Richter [MVP C++]) Wikipedia Wildcard Character . For modified version of WildcardMatch (C++ source). If you need it, just pm me!
-
- Wildcard
- file pattern
- (and 5 more)
-
Add an another example
-
Hi All expert, newbie and lost person , Come here! I want to ask something. Which is easy scripting language type in your opinion. #01: - case sensitive for type name - case sensitive for variable name #02: - case sensitive for type name - case insensitive for variable name #03: - no case sensitive (case insensitive) at all for type name and variable name and also function name. Because currently the code I use for type name, variable name and function name using one list table. So I need you opinion to consider change list table to have one for each one. Well for myself I'm more like number #03 than other but that only my opinion and don't know the other people. Aren't obviously if I wrote what i like when this not only for me. Thanks.
-
Move project to Google Code
-
Such a great work! For those people who experiment with FreeImage UDF function are the best view the image at window form instead save to file and view on Image Viewer. That pain in the ass. http://freeimage.sourceforge.net/faq.html View with this method! Your Template. #include <WinAPI.au3> #include <FreeImage.au3> #include <Windows.au3> $DLL_GDI32 = DllOpen('Gdi32.dll') _FreeImage_LoadDLL() $pDIB = _FreeImage_Load($FIF_JPEG, 'normal.jpg',$JPEG_DEFAULT) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 623, 442, -1, -1) $Pic1 = GUICtrlCreatePic("", 8, 8, 217, 41) GUISetState(@SW_SHOW) $hDC = _WinAPI_GetDC(GUICtrlGetHandle($Pic1)) $l = _WinGDI_SetStretchBltMode($hDC, $COLORONCOLOR) $n = _WinGDI_StretchDIBits($hDC, 0, 0, 217, 41, _ 0, 0, _FreeImage_GetWidth($pDIB), _FreeImage_GetHeight($pDIB), _ _FreeImage_GetBits($pDIB), _FreeImage_GetInfo($pDIB), $DIB_RGB_COLORS, $SRCCOPY); _FreeImage_Unload($pDIB) Do $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Until False Func _WinGDI_SetStretchBltMode($hDC, $StretchMode) Local $ret $ret = DllCall($DLL_GDI32, 'int', 'SetStretchBltMode', 'handle', $hDC, 'int', $StretchMode) If @error Or $ret[0] Then Return SetError(1, @extended, 0) Return $ret[0] EndFunc Func _WinGDI_StretchDIBits($hdc, $XDest, $YDest, $DestWidth, $DestHeight, $XSrc, $YSrc, $SrcWidth, $SrcHeight, $Bits, $BitsInfo, $Usage, $Rop) Local $ret $ret = DllCall($DLL_GDI32, 'int', 'StretchDIBits', 'handle', $hDC, 'int', $XDest, 'int', $YDest, 'int', $DestWidth, 'int', $DestHeight, 'int', $XSrc, 'int', $YSrc, 'int', $SrcWidth, 'int', $SrcHeight, 'ptr', $Bits, 'ptr', $BitsInfo, 'uint', $Usage, 'dword', $Rop) If @error Or $ret[0] Then Return SetError(1, @extended, 0) Return $ret[0] EndFunc Windows.au3 #include-once ; DIB color table identifiers Global Const $DIB_RGB_COLORS = 0 ; color table in RGBTriples Global Const $DIB_PAL_COLORS = 1 ; color table in palette indices ; StretchBlt modes Global Const $BLACKONWHITE = 1 Global Const $WHITEONBLACK = 2 Global Const $COLORONCOLOR = 3 ; New StretchBlt modes Global Const $STRETCH_ANDSCANS = 1 Global Const $STRETCH_ORSCANS = 2 Global Const $STRETCH_DELETESCANS = 3 For those who download FreeImage UDF and always failed! Yes its true ProgAndy download Site's doesn't support Accept-Ranges: bytes instead of Accept-Ranges: */* So I'm using my site as leecher and save on that. Here mirror: http://seagea.com/dload/freeimage.zip Here are the leecher script on php for people who interested. <?php $url = 'http://progandy.de/downloads/finish/3-autoit-udfs/7-freeimage-library/0.html'; $path = 'freeimage.zip'; $fp = fopen($path, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); ?> Search at Sam Google for FreeImage x64 and I found here. FreeImage.dll x64 bit version FreeImageX64.zip - code.google.com FreeImageX64.zip - sambeauvois.be Article FreeImage and x64 yes You can
-
@wakilon x-plus.dll are not important. That only to demonstrate ability SkinMagic loading skin from resource. Ok. I explain like this. I'm creating resource skin like this. x-plus.bat @echo off brcc32.exe x-plus.rc -fox-plus.res x-plus.rc xplus SKIN "x-plus.smf" x-plus.smf In same directory And run x-plus.bat The created file will be x-plus.res Then get blank dll, open in Resource Hacker Menu Action -> Add new Resource -> Select x-plus.res -> Save Oh. I'm using Borland Resource Compiler. You can usage any version of brcc32.exe. You will get this on your computer when installing Borland C++, Delphi 7 or Embarcadero XE2.
-
Skin UDF Change your AutoIt3 Form skin. No less no more. Download SkinMagic.dll SkinMagic Files (582 Kb) SkinMagic UDF Please choose server where you will download: SkinMagic.zip (707 Kb) - code.google.com (included with SkinMagic.dll) SkinMagic.zip (126 Kb) - autoitscript.com Skin Editor SkinMagic C/C++Toolkit Skin Collection AlphaOS DarkArea LighBlue Ocean BlueHorn Click on Image to download skin. Go To Developer Site http://www.appspeed.com if you want to read C++ version of this, read here Use the SkinMagic Toolkit to Skin your Application UDF.SkinMagic.zip
-
- 39 replies
-
- Virtual File
- Virtual Registry
-
(and 1 more)
Tagged with: