MsgBox Posted July 27, 2011 Share Posted July 27, 2011 CString.au3http://www.2shared.com/file/VwaryO_f/cstring.htmlThis header file defines several functions to manipulate C strings and arrays.http://www.cplusplus.com/reference/clibrary/cstring/expandcollapse popup#Include <Memory.au3> Global $CSTRING_UNICODE = True , $NULL_PTR = Ptr(0) ;CStrings.au3 ;This header file defines several functions to manipulate C strings and arrays. ;http://www.cplusplus.com/reference/clibrary/cstring/ Func memchr($MemStrVar,$Char,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memchr/ ;http://msdn.microsoft.com/en-us/library/aa246466%28VS.60%29.aspx ;Locate character in block of memory ;Searches within the first num bytes of the block of memory pointed by ptr for the first ;occurrence of value (interpreted as an unsigned char), and returns a pointer to it. Local $MemPtr , $WNum = 1 , $RtStr = "" , $StrTest = False Switch $CSTRING_UNICODE Case True if IsString($Char) Then $Char = AscW($Char) $WNum = 2 $Num *= 2 Case Else if IsString($Char) Then $Char = Asc($Char) EndSwitch Select Case IsString($MemStrVar) $MemPtr = GetStrBuffer($MemStrVar) $StrTest = True Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect if ($Num = 0) Then $Num = (strlen($MemPtr) * $WNum) $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memchr","ptr",$MemPtr,"int",$Char,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTest) Then MemPtrFree($MemPtr) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($MemRt[0] And $StrTest) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemPtr,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func memcmp($MemStrVar1,$MemStrVar2,$Num = 0) ;http://www.cplusplus.com/reference/clibrary/cstring/memcmp/ ;http://msdn.microsoft.com/en-us/library/aa246467%28VS.60%29.aspx ;Compare two blocks of memory ;Compares the first num bytes of the block of memory pointed by ptr1 to the ;first num bytes pointed by ptr2, returning zero if they all match or a value ;different from zero representing which is greater if they do not. Local $CharTypeA = "" , $CharTypeB = "" , $WNum = 1 Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $WNum = 2 $Num *= 2 Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect EndSwitch if ($Num = 0) Then $Num = (strlen($MemStrVar2) * $WNum) $RtError = DllCall("msvcrt.dll","int:cdecl","memcmp", _ $CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2,"int",$Num) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func memcpy($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memcpy/ ;http://msdn.microsoft.com/en-us/library/aa246468%28VS.60%29.aspx ;Copy block of memory ;Copies the values of num bytes from the location pointed by source directly ;to the memory block pointed by destination. Local $CharTypeA = "" , $Wsize = 1 Local $StrTestA = False , $StrTestB = False , $RtStr Switch $CSTRING_UNICODE Case True $Wsize = 2 $Num *= 2 Case Else EndSwitch if ($Num = 0) Then $Num = (strlen($Source) * $Wsize) Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestA = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestB = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memcpy","ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Destination) if ($StrTestB) Then MemPtrFree($Source) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestB) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestA) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func memmove($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memmove/ ;http://msdn.microsoft.com/en-us/library/aa246469%28v=VS.60%29.aspx ;Move block of memory ;Copies the values of num bytes from the location pointed by source to the ;memory block pointed by destination. Copying takes place as if an intermediate ;buffer were used, allowing the destination and source to overlap. Local $CharTypeA = "" , $Wsize = 1 Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $Wsize = 2 $Num *= 2 Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect EndSwitch if ($Num = 0) Then $Num = (strlen($Source) * $Wsize) $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memmove","ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func memset($MemPtr,$Char = 0,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/memset/ ;http://msdn.microsoft.com/en-us/library/aa246471%28v=VS.60%29.aspx ;Fill block of memory ;Sets the first num bytes of the block of memory pointed by ptr to the ;specified value (interpreted as an unsigned char). if Not IsPtr($MemPtr) Then Return SetError(1,0,0) if IsString($Char) Then $Char = Asc($Char) if ($Num = 0) Then $Num = strlen($MemPtr) $MemRt = DllCall("msvcrt.dll","ptr:cdecl","memset","ptr",$MemPtr,"int",$Char,"int",$Num) if @error Then Return SetError(2,0,0) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndFunc Func strcat($Destination,$Source,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strcat/ ;http://msdn.microsoft.com/en-us/library/aa272954%28VS.60%29.aspx ;Concatenate strings ;Appends a copy of the source string to the destination string. The terminating ;null character in destination is overwritten by the first character of source, and ;a new null-character is appended at the end of the new string formed by the ;concatenation of both in destination. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscat" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcat" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strchr($MemStrVar,$Char,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strchr/ ;http://msdn.microsoft.com/en-us/library/aa272957%28VS.60%29.aspx ;Locate first occurrence of character in string ;Returns a pointer to the first occurrence of character in the C string str. ;The terminating null-character is considered part of the C string. ;Therefore, it can also be located to retrieve a pointer to the end of a string. Local $MemPtr , $FuncA = "" , $StrTestA = False , $RtStr = "" Switch $CSTRING_UNICODE Case True if IsString($Char) Then $Char = AscW($Char) $FuncA = "wcschr" Case Else if IsString($Char) Then $Char = Asc($Char) $FuncA = "strchr" EndSwitch Select Case IsString($MemStrVar) $MemPtr = GetStrBuffer($MemStrVar) $StrTestA = True Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemPtr,"int",$Char) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($MemPtr) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($MemRt[0] And $StrTestA) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemPtr,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strcmp($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strcmp/ ;http://msdn.microsoft.com/en-us/library/aa272960%28VS.60%29.aspx ;Compare two strings ;Compares the C string str1 to the C string str2. ;This function starts comparing the first character of each string. ;If they are equal to each other, it continues with the following ;pairs until the characters differ or until a terminating null-character ;is reached. Local $FuncA = "" , $CharTypeA = "" , $CharTypeB = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscmp" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcmp" EndSwitch $RtError = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func strcoll($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strcoll/ ;http://msdn.microsoft.com/en-us/library/aa272961%28VS.60%29.aspx ;Compare two strings using locale ;Compares the C string str1 to the C string str2, both interpreted ;appropiately according to the LC_COLLATE category of the current locale. ;This function starts comparing the first character of each string. If they ;are equal to each other continues with the following pair until the characters ;differ or until a null-character signaling the end of a string is reached. Local $FuncA = "" , $CharTypeA = "" , $CharTypeB = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscoll" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcoll" EndSwitch $RtError = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func strcpy($Destination,$Source,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strcpy/ ;http://msdn.microsoft.com/en-us/library/aa272966%28VS.60%29.aspx ;Copy string ;Copies the C string pointed by source into the array pointed by destination, ;including the terminating null character. ;To avoid overflows, the size of the array pointed by destination shall be ;long enough to contain the same C string as source (including the terminating ;null character), and should not overlap in memory with source. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscpy" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcpy" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strcspn($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strcspn/ ;http://msdn.microsoft.com/en-us/library/aa272969%28VS.60%29.aspx ;Get span until character in string ;Scans str1 for the first occurrence of any of the characters that are ;part of str2, returning the number of characters of str1 read before ;this first occurrence. ;The search includes the terminating null-characters, so the function will ;return the length of str1 if none of the characters of str2 are found in str1. Local $FuncA = "" , $CharTypeA = "" , $CharTypeB = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcscspn" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strcspn" EndSwitch $RtPosition = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtPosition[0]) EndFunc Func strncat($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strncat/ ;http://msdn.microsoft.com/en-us/library/aa272986 ;Append characters from string ;Appends the first num characters of source to destination, plus a terminating ;null-character. If the length of the C string in source is less than num, only ;the content up to the terminating null-character is copied. Local $CharTypeA = "" , $FuncA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsncat" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strncat" EndSwitch if ($Num = 0) Then $Num = (strlen($Source)) $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strncmp($MemStrVar1,$MemStrVar2,$Num = 0) ;http://www.cplusplus.com/reference/clibrary/cstring/strncmp/ ;http://msdn.microsoft.com/en-us/library/aa272987%28VS.60%29.aspx ;Compare characters of two strings ;Compares up to num characters of the C string str1 to those of the C string str2. ;This function starts comparing the first character of each string. If they are equal ;to each other, it continues with the following pairs until the characters differ, ;until a terminating null-character is reached, or until num characters match in both ;strings, whichever happens first. Local $CharTypeA = "" , $CharTypeB = "" , $FuncA = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsncmp" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strncmp" EndSwitch if ($Num = 0) Then $Num = (strlen($MemStrVar2)) $RtError = DllCall("msvcrt.dll","int:cdecl",$FuncA, _ $CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2,"int",$Num) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtError[0]) EndFunc Func strncpy($Destination,$Source,$Num = 0,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strncpy/ ;http://msdn.microsoft.com/en-us/library/aa272990%28VS.60%29.aspx ;Copy characters from string ;Copies the first num characters of source to destination. If the end of the source C ;string (which is signaled by a null-character) is found before num characters have ;been copied, destination is padded with zeros until a total of num characters have ;been written to it. ;No null-character is implicitly appended to the end of destination, so destination ;will only be null-terminated if the length of the C string in source is less than num. Local $CharTypeA = "" , $FuncA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsncpy" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source,strlen($Source)) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,$Num + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strncpy" EndSwitch if ($Num = 0) Then $Num = strlen($Source) $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strpbrk($Destination,$Source,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strpbrk/ ;http://msdn.microsoft.com/en-us/library/aa272993%28VS.60%29.aspx ;Locate character in string ;Returns a pointer to the first occurrence in str1 of any of the characters ;that are part of str2, or a null pointer if there are no matches. ;The search does not include the terminating null-characters. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcspbrk" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strpbrk" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($Source) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$Destination,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strrchr($MemStrVar,$Char,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strrchr/ ;http://msdn.microsoft.com/en-us/library/aa272996%28VS.60%29.aspx ;Locate last occurrence of character in string ;Returns a pointer to the last occurrence of character in the C string str. ;The terminating null-character is considered part of the C string. Therefore, ;it can also be located to retrieve a pointer to the end of a string. Local $MemPtr , $WNum = 1 , $RtStr = "" Local $FuncA = "" , $StrTest = False Switch $CSTRING_UNICODE Case True if IsString($Char) Then $Char = AscW($Char) $FuncA = "wcsrchr" Case Else if IsString($Char) Then $Char = Asc($Char) $FuncA = "strrchr" EndSwitch Select Case IsString($MemStrVar) $MemPtr = GetStrBuffer($MemStrVar) $StrTest = True Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemPtr,"int",$Char) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTest) Then MemPtrFree($MemRt[0]) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($MemRt[0] And $StrTest) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemPtr,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strspn($MemStrVar1,$MemStrVar2) ;http://www.cplusplus.com/reference/clibrary/cstring/strspn/ ;http://msdn.microsoft.com/en-us/library/aa273001%28VS.60%29.aspx ;Get span of character set in string ;Returns the length of the initial portion of str1 which consists only of ;characters that are part of str2. Local $CharTypeA = "" , $CharTypeB = "" , $FuncA = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar1) $CharTypeA = "wstr" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "wstr" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsspn" Case Else Select Case IsString($MemStrVar1) $CharTypeA = "str" Case IsPtr($MemStrVar1) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar2) $CharTypeB = "str" Case IsPtr($MemStrVar2) $CharTypeB = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "strspn" EndSwitch $RtLength = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar1,$CharTypeB,$MemStrVar2) if @error Then Return SetError(2,0,0) Return SetError(0,0,$RtLength[0]) EndFunc Func strstr($MemStrVar1,$MemStrVar2,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strstr/ ;http://msdn.microsoft.com/en-us/library/aa273008%28VS.60%29.aspx ;Locate substring ;Returns a pointer to the first occurrence of str2 in str1, or a null ;pointer if str2 is not part of str1. ;The matching process does not include the terminating null-characters. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsstr" Case Else Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strstr" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemStrVar1,"ptr",$MemStrVar2) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($StrTestB) Then MemPtrFree($MemStrVar1) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemStrVar1,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strtok($MemStrVar1,$MemStrVar2,$ReturnStr = False) ;http://www.cplusplus.com/reference/clibrary/cstring/strtok/ ;http://msdn.microsoft.com/en-us/library/aa273013%28VS.60%29.aspx ;Split string into tokens ;A sequence of calls to this function split str into tokens, which are ;sequences of contiguous characters separated by any of the characters ;that are part of delimiters. Local $FuncA = "" , $CharTypeA = "" Local $StrTestA = False , $StrTestB = False , $RtStr = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcstok" Case Else Select Case IsString($MemStrVar2) $MemStrVar2 = GetStrBuffer($MemStrVar2) $StrTestA = True Case IsPtr($MemStrVar2) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($MemStrVar1) $MemStrVar1 = GetStrBuffer($MemStrVar1) $StrTestB = True Case IsPtr($MemStrVar1) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strtok" EndSwitch $MemRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemStrVar1,"ptr",$MemStrVar2) if @error Then Return SetError(2,0,0) Switch $ReturnStr Case True $RtStr = GetBufferStr($MemRt[0]) if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($StrTestB) Then MemPtrFree($MemStrVar1) Return SetError(Not $MemRt[0],0,$RtStr) Case Else if ($StrTestA) Then MemPtrFree($MemStrVar2) if ($MemRt[0] And $StrTestB) Then Assign(String("#@cstringLib" & $MemRt[0]),$MemStrVar1,2) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndSwitch EndFunc Func strxfrm($Destination,$Source,$Num = 0) ;http://www.cplusplus.com/reference/clibrary/cstring/strxfrm/ ;http://msdn.microsoft.com/en-us/library/aa273019 ;Transform string using locale ;Transforms the C string pointed by source according to the current locale ;and copies the first num characters of the transformed string to destination, ;returning its length. ;Alternativelly, the function can be used to only retrieve the length, by ;specifying a null pointer for destination and zero for num. Local $CharTypeA = "" , $FuncA = "" Local $StrTestA = False , $StrTestB = False Switch $CSTRING_UNICODE Case True Select Case IsString($Source) $Source = GetStrBuffer($Source) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "wcsxfrm" Case Else Select Case IsString($Source) $Source = GetStrBuffer($Source,strlen($Source)) $StrTestA = True Case IsPtr($Source) Case Else Return SetError(3,0,0) EndSelect Select Case IsString($Destination) $Destination = GetStrBuffer($Destination,strlen($Source) + strlen($Destination)) $StrTestB = True Case IsPtr($Destination) Case Else Return SetError(3,0,0) EndSelect $FuncA = "strxfrm" EndSwitch $MemRt = DllCall("msvcrt.dll","int:cdecl",$FuncA,"ptr",$Destination,"ptr",$Source,"int",$Num) if @error Then Return SetError(2,0,0) if ($StrTestA) Then MemPtrFree($Source) if ($StrTestB) Then MemPtrFree($Destination) Return SetError(Not $MemRt[0],0,$MemRt[0]) EndFunc Func puts($MemStrVar) Local $CharTypeA = "" , $FuncA = "" Switch $CSTRING_UNICODE Case True Select Case IsString($MemStrVar) $CharTypeA = "wstr" Case IsPtr($MemStrVar) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "_putws" Case Else Select Case IsString($MemStrVar) $CharTypeA = "str" Case IsPtr($MemStrVar) $CharTypeA = "ptr" Case Else Return SetError(3,0,0) EndSelect $FuncA = "puts" EndSwitch $EOF = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$MemStrVar) if @error Then Return SetError(2,0,0) Sleep(100) Return SetError(Not $EOF[0],0,$EOF[0]) EndFunc Func printf($Format,$Type1 = "",$Param1 = "",$Type2 = "",$Param2 = "",$Type3 = "",$Param3 = "", _ $Type4 = "",$Param4 = "",$Type5 = "",$Param5 = "",$Type6 = "",$Param6 = "",$Type7 = "", _ $Param7 = "" ,$Type8 = "",$Param8 = "",$Type9 = "",$Param9 = "",$Type10 = "",$Param10 = "") Local $Sring = 'DllCall("msvcrt.dll","int:cdecl","printf","str",Eval("Format")' , $Type = "" For $i = 1 To 10 $Type = Eval("Type" & $i) if $Type == "" Then ExitLoop $Sring &= ',Eval("Type' & $i & '"),Eval("Param' & $i & '")' Next $Sring &= ")" $RT = Execute($Sring) if @error Then Return SetError(2,0,0) Sleep(100) Return SetError($RT[0] < 0,0,$RT[0]) EndFunc Func GetStrBuffer($CString,$MemSize = 0) Local $MemPtr = 0, $FuncA = "", $CharTypeA = "" , $Wsize = 1 if Not IsString($CString) Then Return SetError(3,0,0) Switch $CSTRING_UNICODE Case True $CharTypeA = "wstr" $FuncA = "wcsncpy" $Wsize = 2 Case Else $CharTypeA = "str" $FuncA = "strncpy" EndSwitch if ($MemSize = 0) Then $MemSize = strlen($CString) $hMemory = _MemGlobalAlloc (($MemSize * $Wsize) + $Wsize,$GHND) $MemPtr = _MemGlobalLock ($hMemory) $MemPtrRt = DllCall("msvcrt.dll","ptr:cdecl",$FuncA,"ptr",$MemPtr,$CharTypeA,$CString,"int",$MemSize) if @error Then Return SetError(2,0,0) Return SetError(Not $MemPtrRt[0],0,$MemPtrRt[0]) EndFunc Func GetBufferStr($MemStrVar,$MemSize = 0) Local $MemPtr = 0, $FuncA = "", $CharTypeA = "" , $DMemPtr Switch $CSTRING_UNICODE Case True $CharTypeA = "wstr:cdecl" $FuncA = "wcsncpy" Case Else $CharTypeA = "str:cdecl" $FuncA = "strncpy" EndSwitch Select Case IsPtr($MemStrVar) $MemPtr = $MemStrVar Case Else Return SetError(3,0,0) EndSelect if ($MemSize = 0) Then $MemSize = strlen($MemPtr) $DMemPtr = GetStrBuffer("",$MemSize) $StrRt = DllCall("msvcrt.dll",$CharTypeA,$FuncA,"ptr",$DMemPtr,"ptr",$MemPtr,"int",$MemSize) if @error Then Return SetError(2,0,0) MemPtrFree($DMemPtr) Return SetError(Not $StrRt[0],0,$StrRt[0]) EndFunc Func MemPtrFree($MemPtr) Local $iMemPtr = 0 , $FreeRt = 1 $iMemPtr = Eval(String("#@cstringLib" & $MemPtr)) if Not (@error) Then Assign(String("#@cstringLib" & $MemPtr),"", 2) if ($iMemPtr) Then $MemPtr = $iMemPtr $hMemory = DllCall("Kernel32.dll","HANDLE","GlobalHandle","ptr",$MemPtr) if @error Then Return SetError(2,0,False) if ($hMemory[0]) Then $FreeRt = _MemGlobalFree($hMemory[0]) Return SetError($FreeRt <> 0,0,$FreeRt = 0) EndFunc Func strlen($MemStrVar) Local $CString = "" , $FuncA = "" , $FuncB = "" , $CharTypeA = "" Switch $CSTRING_UNICODE Case True $CharTypeA = "wstr" $FuncA = "wcslen" $FuncB = "wcscpy" Case Else $CharTypeA = "str" $FuncA = "strlen" $FuncB = "strcpy" EndSwitch Select Case IsString($MemStrVar) $CString = $MemStrVar Case IsPtr($MemStrVar) $CString = DllCall("msvcrt.dll",$CharTypeA & ":cdecl",$FuncB,$CharTypeA,"","ptr",$MemStrVar) if @error Then Return SetError(3,0,0) $CString = $CString[0] Case Else Return SetError(1,0,0) EndSelect $LenRt = DllCall("msvcrt.dll","int:cdecl",$FuncA,$CharTypeA,$CString) if @error Then Return SetError(2,0,0) Return SetError(0,0,$LenRt[0]) EndFuncExamplesmemchrcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str = "Example string" $pch = memchr($str,'p',strlen($str)) if ($pch) Then printf (@CRLF & "'p' found at position %d" & @CR,"int",strlen($str) - strlen($pch) + 1) printf ("GetBufferStr($pch) ==> %s" & @CRLF,"str",GetBufferStr($pch)) Else printf ("'p' not found" & @CRLF) EndIf MemPtrFree($pch) $CSTRING_UNICODE = False $str = "Example string" $pch = memchr($str,'p',strlen($str)) if ($pch) Then printf (@CRLF & "'p' found at position %d" & @CR,"int",strlen($str) - strlen($pch) + 1) printf ("GetBufferStr($pch) ==> %s" & @CRLF,"str",GetBufferStr($pch)) Else printf ("'p' not found" & @CRLF) EndIf MemPtrFree($pch)memcmpcplusplusmicrosoftexpandcollapse popup#Include <cstring.au3> $CSTRING_UNICODE = False $Str1 = "Sentence1" $Str2 = "Sentence1" $N = memcmp($Str1,$Str2) if ($N > 0) Then printf ("'%s' is greater than '%s'." & @CRLF ,"str",$Str1,"str",$Str2) ElseIf ($N < 0) Then printf ("'%s' is less than '%s'." & @CRLF,"str",$Str1,"str",$Str2) Else printf ("'%s' is the same as '%s'." & @CRLF,"str",$Str1,"str",$Str2) EndIf $CSTRING_UNICODE = True $Str1 = "Sentence2" $Str2 = "Sentence3" $Struct1 = DllStructCreate("wchar[" & strlen($Str1) + 2 & "]") DllStructSetData($Struct1,1,$Str1) $Ptr1 = DllStructGetPtr($Struct1) $Struct2 = DllStructCreate("wchar[" & strlen($Str2) + 2 & "]") DllStructSetData($Struct2,1,$Str2) $Ptr2 = DllStructGetPtr($Struct2) $N = memcmp($Ptr1,$Ptr2) if ($N > 0) Then printf ("'%s' is greater than '%s'." & @CRLF ,"str",$Str1,"str",$Str2) ElseIf ($N < 0) Then printf ("'%s' is less than '%s'." & @CRLF,"str",$Str1,"str",$Str2) Else printf ("'%s' is the same as '%s'." & @CRLF,"str",$Str1,"str",$Str2) EndIf $CSTRING_UNICODE = False $Str1 = "Sentence3" $Str2 = "Sentence2" $Struct1 = DllStructCreate("char[" & strlen($Str1) + 1 & "]") $Ptr1 = DllStructGetPtr($Struct1) memcpy($Ptr1,$Str1) $N = memcmp($Ptr1,$Str2) if ($N > 0) Then printf ("'%s' is greater than '%s'." & @CRLF ,"str",$Str1,"str",$Str2) ElseIf ($N < 0) Then printf ("'%s' is less than '%s'." & @CRLF,"str",$Str1,"str",$Str2) Else printf ("'%s' is the same as '%s'." & @CRLF,"str",$Str1,"str",$Str2) EndIfmemcpycplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("wchar[40]") $str3 = DllStructGetPtr($Struct3) memcpy($str2,$str1,strlen($str1)+1) memcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3)) MemPtrFree($str2) $CSTRING_UNICODE = False $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("char[40]") $str3 = DllStructGetPtr($Struct3) memcpy($str2,$str1,strlen($str1)+1) memcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3)) MemPtrFree($str2)memmovecplusplusmicrosoft#Include <cstring.au3> Dim $SizeOfChar = 1 , $SizeOfWchar = 2 $CSTRING_UNICODE = True $str = memcpy("","memmove can be very useful......") memmove($str+(20 * $SizeOfWchar),$str+(15 * $SizeOfWchar),11); printf(@CRLF) puts($str) printf(@CRLF) MemPtrFree($str) $CSTRING_UNICODE = False $str = memcpy("","memmove can be very useful......") memmove($str+(20 * $SizeOfChar),$str+(15 * $SizeOfChar),11); printf(@CRLF) puts($str) printf(@CRLF) MemPtrFree($str)memsetcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = False ; Only $istr = "almost every programmer should know memset!" $iStruct = DllStructCreate("char[43]") $iPtr = DllStructGetPtr($iStruct) memcpy($iPtr,$istr) memset($iPtr,'-',6) printf(@CRLF) puts($iPtr) printf(@CRLF)strcatcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $Struct = DllStructCreate("wchar[80]") $iStr = DllStructGetPtr($Struct) memcpy($iStr,"these ") strcat($iStr,"strings ") strcat($iStr,"are ") strcat($iStr,"concatenated.") printf(@CR) puts($iStr) printf(@CR) $CSTRING_UNICODE = False $iStr = GetStrBuffer("",80) memcpy($iStr,"these ") strcat($iStr,"strings ") strcat($iStr,"are ") strcat($iStr,"concatenated.") puts($iStr) printf(@CR) MemPtrFree($iStr)strchrcplusplusmicrosoft#Include <cstring.au3> Local $SizeOfChar = 1 , $SizeOfWchar = 2 $CSTRING_UNICODE = True $str = "This is a sample string"; printf ('Looking for the "s" character in \"%s\"...' & @CR,"str",$str); $pch = strchr($str,'s'); Dim $Tempch = $pch while ($pch <> 0) printf ("found at %d" & @CR,"int",strlen($str) - strlen($pch) + 1); $pch=strchr($pch+($SizeOfWchar),'s'); WEnd printf(@CRLF) MemPtrFree($Tempch) $CSTRING_UNICODE = False $str = "This is a sample string"; printf ('Looking for the "s" character in \"%s\"...' & @CR,"str",$str); $pch = strchr($str,'s'); Dim $Tempch = $pch while ($pch <> 0) printf ("found at %d" & @CR,"int",strlen($str) - strlen($pch) + 1); $pch=strchr($pch+($SizeOfChar),'s'); WEnd MemPtrFree($Tempch)strcmpcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcmp($szKey,$szInput) = 0) puts("Correct answer!" & @CR); $CSTRING_UNICODE = False Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcmp($szKey,$szInput) = 0) puts("Correct answer!" & @CR);strcollcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcoll($szKey,$szInput) = 0) puts("Correct answer!" & @CR); $CSTRING_UNICODE = False Dim $szKey = "apple" , $szInput = "" do printf (@CR & "Guess my favourite fruit? "); $szInput = InputBox("Question", "Guess my favourite fruit?", "Planet favourite", "", _ -1, -1, 0, 0) Until(strcoll($szKey,$szInput) = 0) puts("Correct answer!" & @CR);strcpycplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("wchar[40]") $str3 = DllStructGetPtr($Struct3) strcpy($str2,$str1,strlen($str1)+1) strcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3)) $CSTRING_UNICODE = False $str1 ="Sample string" $str2 = GetStrBuffer("",40) $Struct3 = DllStructCreate("char[40]") $str3 = DllStructGetPtr($Struct3) strcpy($str2,$str1,strlen($str1)+1) strcpy($str3,"copy successful",16) printf( @CR & "str1: %s" & @CR & "str2: %s" & @CR & "str3: %s" & @CRLF , _ "str",$str1,"str",GetBufferStr($str2),"str",GetBufferStr($str3))strcspncplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str = "fcba73" $keys = "1234567890" Dim $i $i = strcspn($str,$keys) printf(@CR) printf ("The first number in str is at position %d.","int",$i+1) printf(@CRLF) $CSTRING_UNICODE = False $str = "fcba73" $keys = "1234567890" Dim $i $i = strcspn($str,$keys) printf(@CR) printf ("The first number in str is at position %d.","int",$i+1) printf(@CRLF)strncatcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str1 = GetStrBuffer("",20) $Struct2 = DllStructCreate("wchar[20]") $str2 = DllStructGetPtr($Struct2) strcpy ($str1,"To be ") strcpy ($str2,"or not to be") strncat ($str1,$str2,6) printf(@CR) puts ($str1) printf(@CRLF) MemPtrFree($str1) $CSTRING_UNICODE = False $str1 = GetStrBuffer("",20) $Struct2 = DllStructCreate("char[20]") $str2 = DllStructGetPtr($Struct2) strcpy ($str1,"To be ") strcpy ($str2,"or not to be") strncat ($str1,$str2,6) printf(@CR) puts ($str1) printf(@CRLF) MemPtrFree($str1)strcpycplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $Struct = DllStructCreate("wchar[5];wchar[5];wchar[5]") strcpy(DllStructGetPtr($Struct,1),"R2D2") strcpy(DllStructGetPtr($Struct,2),"C3PO") strcpy(DllStructGetPtr($Struct,3),"R2A6") puts ("Looking for R2 astromech droids...") For $n = 1 To 3 if (strncmp(DllStructGetPtr($Struct,$n),"R2xx",2) == 0) Then printf ("found %s" & @CR ,"str",GetBufferStr(DllStructGetPtr($Struct,$n))) EndIf Next $CSTRING_UNICODE = False $Struct = DllStructCreate("char[5];char[5];char[5]") strcpy(DllStructGetPtr($Struct,1),"R2D2") strcpy(DllStructGetPtr($Struct,2),"C3PO") strcpy(DllStructGetPtr($Struct,3),"R2A6") puts ("Looking for R2 astromech droids...") For $n = 1 To 3 if (strncmp(DllStructGetPtr($Struct,$n),"R2xx",2) == 0) Then printf ("found %s" & @CR ,"str",GetBufferStr(DllStructGetPtr($Struct,$n))) EndIf Nextstrncpycplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $Struct2 = DllStructCreate("wchar[6]") $str2 = DllStructGetPtr($Struct2) strncpy($str2,"To be or not to be",5) puts($str2) $CSTRING_UNICODE = False $Struct2 = DllStructCreate("char[6]") $str2 = DllStructGetPtr($Struct2) strncpy($str2,"To be or not to be",5) puts($str2)strpbrkcplusplusmicrosoft#Include <cstring.au3> Dim $SizeOfWchar = 2 , $SizeOfChar = 1 $CSTRING_UNICODE = True $str = GetStrBuffer("This is a sample string") $key = GetStrBuffer("aeiou") printf("Vowels in '%s': ","str","This is a sample string"); $pch = strpbrk($str,$key) while ($pch <> 0) printf("%s " ,"str",GetBufferStr($pch,1)) $pch = strpbrk($pch + (1 * $SizeOfWchar),$key) WEnd printf(@CR) MemPtrFree($str) MemPtrFree($key) $CSTRING_UNICODE = False $str = GetStrBuffer("This is a sample string") $key = GetStrBuffer("aeiou") printf("Vowels in '%s': ","str","This is a sample string"); $pch = strpbrk($str,$key) while ($pch <> 0) printf("%s " ,"str",GetBufferStr($pch,1)) $pch = strpbrk($pch + (1 * $SizeOfChar),$key) WEnd printf(@CR) MemPtrFree($str) MemPtrFree($key)strrchrcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str = "This is a sample string" $pch=strrchr($str,'s') printf ("Last occurence of 's' found at %d " & @CRLF,"int",strlen($str) - strlen($pch) + 1) MemPtrFree($pch) $CSTRING_UNICODE = False $str = "This is a sample string" $pch=strrchr($str,'s') printf ("Last occurence of 's' found at %d " & @CRLF,"int",strlen($str) - strlen($pch) + 1) MemPtrFree($pch)strspncplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True Dim $i $strtext = "129th" $cset = "1234567890" $i = strspn($strtext,$cset) printf (@CR & "The length of initial number is %d." & @CRLF,"int",$i) $CSTRING_UNICODE = False Dim $i $strtext = "129th" $cset = "1234567890" $i = strspn($strtext,$cset) printf ("The length of initial number is %d." & @CR,"int",$i)strstrcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str = GetStrBuffer("This is a simple string") $pch = strstr($str,"simple") strncpy ($pch,"sample",6) puts ($str) MemPtrFree($str) $CSTRING_UNICODE = False $str = GetStrBuffer("This is a simple string") $pch = strstr($str,"simple") strncpy ($pch,"sample",6) puts ($str) MemPtrFree($str)strtokcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $str = GetStrBuffer("- This, a sample string.") printf ("Splitting string '%s' into tokens:" & @CR ,"str",GetBufferStr($str)); $pch = strtok($str," ,.-") while ($pch <> 0) printf ("%s" & @CR,"str",GetBufferStr($pch)) $pch = strtok($NULL_PTR, " ,.-"); WEnd MemPtrFree($str) $CSTRING_UNICODE = False $str = GetStrBuffer("- This, a sample string.") printf ("Splitting string '%s' into tokens:" & @CR ,"str",GetBufferStr($str)); $pch = strtok($str," ,.-") while ($pch <> 0) printf ("%s" & @CR,"str",GetBufferStr($pch)) $pch = strtok($NULL_PTR, " ,.-"); WEnd MemPtrFree($str)strxfrmcplusplusmicrosoft#Include <cstring.au3> $CSTRING_UNICODE = True $String = "sample string" $length = strxfrm($NULL_PTR,$String, 0 ) printf (@CR & "the length Of $String is %d" & @CRLF,"int",$length) $CSTRING_UNICODE = False $String = "sample string" $length = strxfrm($NULL_PTR,$String, 0 ) printf (@CR & "the length Of $String is %d" & @CRLF,"int",$length) Bilgus 1 Link to comment Share on other sites More sharing options...
Shaggi Posted July 27, 2011 Share Posted July 27, 2011 Cute haha Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
MsgBox Posted August 5, 2011 Author Share Posted August 5, 2011 Cute haha Thanks Link to comment Share on other sites More sharing options...
martin Posted August 5, 2011 Share Posted August 5, 2011 What are they for? Can they be be used for some advantage over the existing AutoIt string handling methods? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Andreik Posted August 5, 2011 Share Posted August 5, 2011 ^I don't think it's any pragmatic approach for AutoIt. Simply I don't see any advantages. Maybe I am wrong but really I don't see. Link to comment Share on other sites More sharing options...
MsgBox Posted August 6, 2011 Author Share Posted August 6, 2011 What are they for? Can they be be used for some advantage over the existing AutoIt string handling methods?The answer is yes and the use of the WinAPI itself useful Link to comment Share on other sites More sharing options...
MsgBox Posted August 6, 2011 Author Share Posted August 6, 2011 ^I don't think it's any pragmatic approach for AutoIt. Simply I don't see any advantages. Maybe I am wrong but really I don't see. Misbelief Link to comment Share on other sites More sharing options...
martin Posted August 6, 2011 Share Posted August 6, 2011 The answer is yes and the use of the WinAPI itself usefulOk, then can you give an example of use? Or maybe more than one. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now