Jump to content
Sign in to follow this  
MHz

PrivateProfileStringW

Recommended Posts

These functions handle ANSI and unicode inifiles similar to IniRead, IniWrite and IniDelete.

  • _WinAPI_WritePrivateProfileStringW
  • _WinAPI_GetPrivateProfileStringW

So you can read from unicode inifiles created from other programs or perhaps read and write to your own inifiles.

I was unable to figure out how the API function of WritePrivateProfileStringW can create a unicode file initially so I instead used FileOpen to create a unicode file and write the 1st entry to achieve this. Further use uses WritePrivateProfileStringW is ok to handle the unicode entries. ANSI file creation is done by WritePrivateProfileStringW by default.

Deletion of keys and sections may need use of Null which is in AutoIt 3.3.9.0 and later. I put comments with the code so hopefully understandable to you.

The functions use a similar parameter syntax to IniRead and IniWrite. _WinAPI_WritePrivateProfileStringW has an additional parameter to handle the flag passed to FileOpen for the initial creation of the inifile. _WinAPI_GetPrivateProfileStringW has an additional parameter in case you want the buffer that holds the return value within the UDF to be larger.

The example has some russian text in it so you need to save it in a unicode script for correct testing.

Example

; show message if script is not unicode. Unicode text in this script requires it to be UTF encoded.
; if needed in Scite, use menu bar, File -> Encoding -> UTF (any UTF type that suits you) and save the script.
If Not FileGetEncoding(@ScriptFullPath) Then MsgBox(0, @ScriptName, 'Script is not unicode')

; write to ini file
$return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', 'Open', 'Открыть', 0x21)
_Notify('Write', $return)

; read from ini file
$return = _WinAPI_GetPrivateProfileStringW("test.ini", 'russian', 'Open', 'Default')
_Notify('Read', $return)

#cs AutoIt 3.3.9.0 or later using Null keyword
; setting $sValue parameter with Null keyword will delete a key using AutoIt 3.3.9.x or later.
$return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', 'Open', Null)

; setting $sKey parameter with Null keyword will delete a section using AutoIt 3.3.9.x or later.
$return = _WinAPI_WritePrivateProfileStringW("test.ini", 'russian', Null, Null)

; setting $sSection parameter with Null keyword will flush using AutoIt 3.3.9.x or later.
$return = _WinAPI_WritePrivateProfileStringW("test.ini", Null, Null, Null)
#ce ; More info of an API that mimics these functions and explains use of Null at http://code.google.com/p/privateprofilestring/

Func _Notify($title, $return = 0, $error = @error, $extended = @extended)
    ; notify results from other function calls
    MsgBox(StringRegExpReplace($error, '-{0,1}([1-9])[0-9]*', '0x30'), $title, _
        '@error = ' & $error & @CRLF & _
        '@extended = ' & $extended & @CRLF & _
        '$return = ' & $return _
    )
EndFunc

User defined functions

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_WritePrivateProfileStringW
; Description ...: Write to ANSI and unicode encoded ini files
; Syntax.........: _WinAPI_WritePrivateProfileStringW($sFileName, $sSection, $sKey, $sValue[, $iMode = 1])
; Parameters ....: $sFileName - The filename of the .ini file
;                  $sSection - The section name in the .ini file
;                  $sKey - The key name in the in the .ini file
;                  $sValue - The value to write/change
;                  $iMode - Refer to FileOpen mode parameter
; Return values .: Success - Not 0
;                  Failure - 0
;                  @error 1 to 5 - Refer to DllCall
;                  @error 6 - FileOpen failed to open a handle to create the file
; Author ........: MHz
; Modified.......: 
; Remarks .......: Similar to IniWrite but uses unicode API calls. If $sValue is Null then $sKey is deleted. If $sKey is Null,
;                  then $sSection is deleted. If $sSection, $sKey and $sValue are all Null, then $sFileName is
;                  flushed. *** Null is a keyword that only exists in AutoIt3 versions 3.3.9.x and later ***
; Related .......: DllCall, FileOpen, IniWrite
; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/ms725501%28v=vs.85%29.aspx
;                  http://msdn.microsoft.com/en-us/library/windows/desktop/bb773660%28v=vs.85%29.aspx
; Example .......: Yes
; ===============================================================================================================================
Func _WinAPI_WritePrivateProfileStringW($sFileName, $sSection, $sKey, $sValue, $iMode = 1)
    Local $handle_write, $ret
    ; check if path is relative and make it absolute if it is relative
    $ret = DllCall('Shlwapi.dll', 'bool', 'PathIsRelativeW', 'wstr', $sFileName); lpszPath
    If Not @error And $ret[0] Then $sFileName = @WorkingDir & '\' & $sFileName
    ; create a unicode encoded file if needed and write the entry
    If Not FileExists($sFileName) And $iMode > 0x20 Then
        $handle_write = FileOpen($sFileName, $iMode)
        If $handle_write = -1 Then Return SetError(6, 0, 0)
        FileWrite($handle_write, '[' & $sSection & ']' & @CRLF & $sKey & '=' & $sValue & @CRLF)
        FileClose($handle_write)
        Return 1
    EndIf
    ; write to the ini file. $ret[0] will contain nonzero if successful
    $ret = DllCall('Kernel32.dll', 'bool', 'WritePrivateProfileStringW', _
        'wstr', $sSection, _
        'wstr', $sKey, _
        'wstr', $sValue, _
        'wstr', $sFileName _
    ); lpAppName, lpKeyName, lpString, lpFileName
    If @error Then Return SetError(@error, @extended, 0)
    Return SetExtended(0, $ret[0])
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _WinAPI_GetPrivateProfileStringW
; Description ...: Read from ANSI and unicode encoded ini files
; Syntax.........: _WinAPI_GetPrivateProfileStringW($sFileName, $sSection, $sKey[, $sDefault = ''[, $iBufferSize = 65536]])
; Parameters ....: $sFileName - The filename of the .ini file
;                  $sSection - The section name in the .ini file
;                  $sKey - The key name in the in the .ini file
;                  $sDefault - The default value to return if the requested key is not found
;                  $iBufferSize - Adjustable buffer size which contains the chars from the API call
; Return values .: Success - Returns the requested key value
;                  Failure - Returns the default string if requested key not found
;                  @error 1 to 5 - Refer to DllCall
; Author ........: MHz
; Modified.......: 
; Remarks .......: Similar to IniRead but uses unicode API calls
; Related .......: IniRead
; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724353%28v=vs.85%29.aspx
;                  http://msdn.microsoft.com/en-us/library/windows/desktop/bb773660%28v=vs.85%29.aspx
; Example .......: Yes
; ===============================================================================================================================
Func _WinAPI_GetPrivateProfileStringW($sFileName, $sSection, $sKey, $sDefault = '', $iBufferSize = 65536)
    Local $buffer, $ret
    ; check if path is relative and make it absolute if it is relative
    $ret = DllCall('Shlwapi.dll', 'bool', 'PathIsRelativeW', 'wstr', $sFileName); lpszPath
    If Not @error And $ret[0] Then $sFileName = @WorkingDir & '\' & $sFileName
    ; create a buffer to hold the returned string
    $buffer = DllStructCreate('wchar[' & $iBufferSize & ']')
    ; read from the ini file. $ret[0] will contain number of chars returned
    $ret = DllCall('Kernel32.dll', 'dword', 'GetPrivateProfileStringW', _
        'wstr', $sSection, _
        'wstr', $sKey, _
        'wstr', $sDefault, _
        'ptr', DllStructGetPtr($buffer), _
        'dword', DllStructGetSize($buffer), _
        'wstr', $sFileName _
    ); lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName
    If @error Then SetError(@error, @extended, $sDefault)
    Return SetExtended($ret[0], DllStructGetData($buffer, 1))
EndFunc

Thanks to AZJIO for some russian text for use in the example. :)

Edit:

Updated with summary correction by guiness in post #2

Edited by MHz

Share this post


Link to post
Share on other sites

If you create a Unicode file then the Ini functions should work with Unicode.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

Thanks guinness. Indeed they do with some testing. Arrh :censored:  :D

No problem.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By argumentum
      There is a _ArrayToString() but no _ArrayFromString().  ( searched in the forum and google )
      The example is based on the _ArrayToString() help file, to show the reconstruction of the array.
      #include <Array.au3> #include <MsgBoxConstants.au3> Local $aArray[20] For $i = 0 To 19 $aArray[$i] = $i Next _ArrayDisplay($aArray, "1D Array") MsgBox($MB_SYSTEMMODAL, "Items 1-7", _ArrayToString($aArray, @TAB, 1, 7)) ConsoleWrite('>' & _ArrayToString($aArray, @TAB, 1, 7) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, @TAB, 1, 7), @TAB), "1D ArrayFromString") Local $aArray[10][10] For $i = 0 To 9 For $j = 0 To 9 $aArray[$i][$j] = $i & "-" & $j Next Next _ArrayDisplay($aArray, "2D Array") MsgBox($MB_SYSTEMMODAL, "Rows 4-7, cols 2-5", _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5)) ConsoleWrite('>' & _ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5) & '<' & @CRLF) _ArrayDisplay(_ArrayFromString(_ArrayToString($aArray, " :: ", 4, 7, @CRLF, 2, 5), " :: ", @CRLF), "2D ArrayFromString") ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFromString ; Description ...: Reconstruct an array from _ArrayToString() or _SQLite_Display2DResult()** ; Syntax ........: _ArrayFromString($sArrayStr[, $sDelim_Col = "|", [$sDelim_Row = @CRLF, [$bForce2D = False]]]) ; Parameters ....: $sArrayStr : A string formated by _ArrayToString() or _SQLite_Display2DResult()** ; $sDelim_Col : [optional] default is "|" ; $sDelim_Row : [optional] default is @CRLF ; $bForce2D : [optional] default is False. True will force a 2 dimensional array even if 1 dimensional. ; Return values .: Success - An array ; Failure - Return 0 with error = 1 ; Link...........: https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ ; Author ........: argumentum ; Remarks .......: ** for _SQLite_Display2DResult(), $sDelim_Col must be declared. ; =============================================================================================================================== Func _ArrayFromString($sArrayStr, $sDelim_Col = "|", $sDelim_Row = @CRLF, $bForce2D = False) If $sDelim_Col = Default Then $sDelim_Col = "|" If $sDelim_Row = Default Then $sDelim_Row = @CRLF If $bForce2D = Default Then $bForce2D = False Local $aRow, $aCol = StringSplit($sArrayStr, $sDelim_Row, 3) $aRow = StringSplit($aCol[0], $sDelim_Col, 3) If UBound($aCol) = 1 And Not $bForce2D Then For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) Next Return $aRow EndIf Local $aRet[UBound($aCol)][UBound($aRow)] For $n = 0 To UBound($aCol) - 1 $aRow = StringSplit($aCol[$n], $sDelim_Col, 3) If UBound($aRow) > UBound($aRet, 2) Then Return SetError(1) For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) $aRet[$n][$m] = $aRow[$m] Next Next Return $aRet EndFunc ;==>_ArrayFromString
      PS: so, how to save an array to an ini file ? ( small array, the limitations of an ini file still applies )
      #include <Array.au3>; For _ArrayDisplay() ; if you declare it, it will use it, else, use default ;Global $g_iniFile = @ScriptDir & "\ThisTest.ini" Example() Func Example() Local $n, $aTest, $aArray[3] = ["00", "one", "2"] ; if is not in the INI file, it will save it $aTest = IniGet("Test", $aArray) _ArrayDisplay($aTest, "1st") ; since is saved, it'll recall it $aTest = IniGet("Test") For $n = 0 To UBound($aTest) - 1 ; ..just to show the elements found as integer If IsInt($aTest[$n]) Then $aTest[$n] &= " = IsInt() = " & (IsInt($aTest[$n]) = 1) Next _ArrayDisplay($aTest, "2nd") EndFunc ;==>Example Func IniGet($sKey, $vDefault = Default, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" Local $v, $s = IniRead($ini, $sSection, $sKey, Chr(1)) If $s = Chr(1) Then If $vDefault == Default Then Return SetError(1, 0, "") Else IniSet($sKey, $vDefault, $sSection) Return $vDefault EndIf EndIf $v = StringLeft($s, 1) Switch $v Case "i" Return Int(StringTrimLeft($s, 2)) Case "a" Return _ArrayFromString(BinaryToString(StringTrimLeft($s, 2)), Chr(1), Chr(2)) Case "d" Return Binary(StringTrimLeft($s, 2)) Case Else Return String(StringTrimLeft($s, 2)) EndSwitch EndFunc ;==>IniGet Func IniSet($sKey, $vValue, $sSection = "Settings") Local Static $ini = IsDeclared("g_iniFile") ? Eval("g_iniFile") : StringTrimRight(@ScriptFullPath, 4) & ".ini" If IsInt($vValue) Then $vValue = "i:" & $vValue ElseIf IsArray($vValue) Then $vValue = "a:" & StringToBinary(_ArrayToString($vValue, Chr(1), -1, -1, Chr(2))) ElseIf IsBinary($vValue) Then $vValue = "d:" & $vValue Else $vValue = "s:" & $vValue EndIf $vValue = IniWrite($ini, $sSection, $sKey, $vValue) Return SetError(@error, @extended, $vValue) EndFunc ;==>IniSet ; au3.user.calltips.api: ; _ArrayFromString($sString , [$sDelim_Col = "|" [, $sDelim_Row = @CRLF [, $iForce2D = 0]]]) Rebuild an array from _ArrayToString() ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFromString ; Description ...: Reconstruct an array from _ArrayToString() or _SQLite_Display2DResult()** ; Syntax ........: _ArrayFromString($sArrayStr[, $sDelim_Col = "|", [$sDelim_Row = @CRLF, [$bForce2D = False]]]) ; Parameters ....: $sArrayStr : A string formated by _ArrayToString() or _SQLite_Display2DResult()** ; $sDelim_Col : [optional] default is "|" ; $sDelim_Row : [optional] default is @CRLF ; $bForce2D : [optional] default is False. True will force a 2 dimensional array even if 1 dimensional. ; Return values .: Success - An array ; Failure - Return 0 with error = 1 ; Link...........: https://www.autoitscript.com/forum/topic/197277-_arrayfromstring/ ; Author ........: argumentum ; Remarks .......: ** for _SQLite_Display2DResult(), $sDelim_Col must be declared. ; =============================================================================================================================== Func _ArrayFromString($sArrayStr, $sDelim_Col = "|", $sDelim_Row = @CRLF, $bForce2D = False) If $sDelim_Col = Default Then $sDelim_Col = "|" If $sDelim_Row = Default Then $sDelim_Row = @CRLF If $bForce2D = Default Then $bForce2D = False Local $aRow, $aCol = StringSplit($sArrayStr, $sDelim_Row, 3) $aRow = StringSplit($aCol[0], $sDelim_Col, 3) If UBound($aCol) = 1 And Not $bForce2D Then For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) Next Return $aRow EndIf Local $aRet[UBound($aCol)][UBound($aRow)] For $n = 0 To UBound($aCol) - 1 $aRow = StringSplit($aCol[$n], $sDelim_Col, 3) If UBound($aRow) > UBound($aRet, 2) Then Return SetError(1) For $m = 0 To UBound($aRow) - 1 $aRow[$m] = StringStripWS($aRow[$m], 3) If $aRow[$m] == Int($aRow[$m]) Then $aRow[$m] = Int($aRow[$m]) $aRet[$n][$m] = $aRow[$m] Next Next Return $aRet EndFunc ;==>_ArrayFromString
      PS2: https://www.autoitscript.com/trac/autoit/ticket/3696#ticket
    • By Danp2
      Hi all,
      I'm reading the file https://msedgedriver.azureedge.net/LATEST_RELEASE_83 using WinHTTP, and the string I get back looks like this when I view this file in Scite --
      xEFxBFxBF83.0.478.54 Here's what I've come up with as a means to strip off the Unicode BOM from the beginning of the string --
      If Asc($sDriverLatest) = 255 Then ConsoleWrite("Unicode detected!" & @CRLF) $sDriverLatest = BinaryToString($sDriverLatest, $SB_UTF16LE) If Asc($sDriverLatest) = 63 Then $sDriverLatest = StringMid($sDriverLatest,2) ; skip ? EndIf ConsoleWrite("Latest=" & $sDriverLatest & @CRLF) Is there a more reliable way to eliminate these unicode characters?
      Dan
    • By max23ed
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Debug.au3> #Region ### START Koda GUI section ### Form=c:\users\ali\downloads\!testproject\form1.kxf Global $Form1_1 = GUICreate("Form1", 956, 667, -1, -1) Global $Browsbtn = GUICtrlCreateButton("Browse a setup", 776, 64, 123, 25) Global $locationtxt = GUICtrlCreateInput("", 584, 64, 169, 21) Global $showbtn = GUICtrlCreateButton("Add", 776, 104, 123, 25) Global $silent_list = GUICtrlCreateList("", 32, 48, 241, 552) Global $record_list = GUICtrlCreateList("", 320, 48, 249, 552) Global $aaaaaa = GUICtrlCreateLabel("Silent installs", 40, 16, 64, 17) Global $Label1 = GUICtrlCreateLabel("Non-Silent installs", 328, 16, 87, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### global $filename global $abc global $file_usage While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Browsbtn GUICtrlSetData($locationtxt, FileOpenDialog("Select the program to analyze", '', "Supported files (*.exe;*.msi;*.reg;*.inf)|Executable Files (*.exe)|Microsoft Installer files (*.msi)|Registry files (*.reg)|Inf files (*.inf)", 3)) Sleep(100) $abc = GUICtrlRead($locationtxt) $filename = StringTrimLeft($abc, StringInStr($abc, '\', 0, -1)) Case $showbtn IniWrite("configg.ini", $filename, "switch", "abc") Run("ussf.exe " & $abc, "", @SW_HIDE) WinWait('USSF', 'Universal Silent Switch Finder',-1) WinSetState("USSF", "Universal Silent Switch Finder", @SW_HIDE) ; ############################################## Config.ini values ########################################## ; Looping to get the ini values Local $file_extension WinWait("USSF") Do $file_extension = ControlGetText("USSF", "", "Edit2") $file_type = ControlGetText("USSF", "", "Edit3") $file_usage = ControlGetText("USSF", "", "Edit4") Until $file_extension <> "Loading..." And $file_extension <> "" And $file_type <> "Loading..." And $file_type <> "" And $file_usage <> "Loading..." And $file_usage <> "" sleep(5000) ;Here IniWrite is not working idk why IniWrite("config.ini", $filename, "switch", $file_usage) EndSwitch WEnd Hi, i don't know why its not writing. i need it in ini format please help thanks.
    • By GillesMaisonneuve
      Good morning,
       
      I am trying to read a Unicode utf8 string from a perl subprocess via StdoutRead.
      I use an AUtoIt GUI and display result in an 'Edit' control (see my code below) using 'Courier New', a font that can handle Unicode characters.
      I was expecting a result looking like (CMD console):
      ++$ chcp 65001>NUL: & perl -Mutf8 -CS -e "use 5.018; binmode STDOUT,q(:utf8); say qq(\x{03A9})" & chcp 850>NUL: Ω Instead I get someting like this (see downward the screen copy):
      ++$ chcp 1250>NUL: & perl -Mutf8 -CS -e "use 5.018; binmode STDOUT,q(:utf8); say qq(\x{03A9})" & chcp 850>NUL: Ω Obviously while I was expecting to receive an utf8 char, it seems to have been converted to Windows ANSI codepage 1250 (Windows default for Western/Central Europe, right ?)
      What am I doing wrong? Is there someone who could guide me?
       
      Here is my code and my output in the GUI.
      Creating and configuring the Edit control:
      Local $Edit1 = GUICtrlCreateEdit( "", 20, 110, 780, 500, BitOr($GUI_SS_DEFAULT_EDIT,$ES_MULTILINE,$ES_READONLY) ) GUICtrlSetData($Edit1, "This field will contain text result from external Perl command") GUICtrlSetFont($Edit1, 10, $FW_THIN, $GUI_FONTNORMAL, "Courier New")  
      Executing Perl command (note: `-Mutf8` and `-CS` garantees that I work in utf8 and STDOUT accepts wide-characters):
      local $ExePath = 'perl.exe -Mutf8 -CS ' ;~ if perl in PATH, no need for full path C:\Perl\bin\perl.exe local $Params = '-e "use 5.018; use utf8; use charnames q(:full); binmode STDOUT,q(:utf8);' & _ 'say scalar localtime; say qq(\N{GREEK CAPITAL LETTER OMEGA})"' local $Cmd = $ExePath & ' ' & $Params Local $iPID = Run($Cmd, "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))  
      Reading STDOUT and displaying it into the Edit control:
      While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd If $sOutput <> '' Then GUICtrlSetData($Edit1, $sOutput) EndIf  
      And now, what I get on my GUI:
       

    • By Skysnake
      'F‌inal' ; <========= problem between F and i 'F‌inal' ; <========= problem between F and i 'Final' ; <========= Notepad ANSI, no problem
      F‌inal

      PostgreSQL complains about that red dot.  Notepad++ marks the first word.
      Notepad said it contains Unicode.  Saved as ANSI and put back. Red dot is gone.
       
      the Text is inserted manually into an AutoIt Input box.  Things get done to it, and it ends up in a SQL database.  The data seems fine, but when I start generating reports, all kinds of funny problems show up.
       
      If I can ID that character, I can remove it.
      Any ideas?
×
×
  • Create New...