Jump to content
Sign in to follow this  
Kilmatead

Possible _GUICtrlComboBox_GetEditText UDF Bug?

Recommended Posts

Kilmatead

As this UDF from GuiComboBox.au3 was unpredictably returning an extra nonsense character when it was called (the expected string text, plus a suffixed random character value), I noticed in the original definition the line:

Local $tText = DllStructCreate("wchar Text[" & $iLength + 1 & "]", DllStructGetPtr($tBuffer))

...which seems to allocate 1 more character than necessary ($iLength + 1) for retrieving the final string from its pointer location. Not fully understanding exactly how this UDF works, I just took the age-old Bull-in-a-China-Shop approach and removed the "+ 1" from the allocation. Surprisingly, this seems to have solved the issue.

Has anyone else enountered this? Or, better yet, is there a reason the allocation would have originally been written one char longer than necessary? (The only thing I can think of is that strings handled in this fashion are expected to be null-terminated so space was allowed for it - but that appears superfluous in this instance.)

Share this post


Link to post
Share on other sites
guinness

Could you perhaps provide a small reproducer. Thanks.


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
Kilmatead

Could you perhaps provide a small reproducer. Thanks.

This is in the UDF itself, not in the milieu of external code. The example in the help file exhibits the same behaviour (at least as far as Win7 x64 is concerned). I originally thought it may have been an issue with declared integer sizes and so forth given it has so many DLL calls to acheive its ends (obfuscating the issue by using multiple _SendMessage() wrappers didn't help).

As I said, the appended character in the string is random, and consistent at 1, though at times it resembles whitespace and so may not be immediately visible - but often amounts to one of those chinese-type characters so common in unicode strings.

By truncating the allocation to the exact string length, the issue appears to be solved - I'm just suggesting it needs to be fixed as (even though it's merely a UDF) it is distributed as part of the common library.

I wouldn't file a bug report as I can't claim to understand precisely how the UDF works - I'm just wondering if anyone else ever ran into this before, and/or might suggest if the truncation might cause other problems (I haven't encountered any as of yet).

Share this post


Link to post
Share on other sites
Melba23

Kilmatead,

The example in the Help file for this function does not return any extra characters - and the returned text is is identical whether the "+ 1" is there or not.

I presume you are using it on a combo in an external app. What sort of characters are you getting added to teh string? Printable ASCII or more wacky things? :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
guinness

I looked at the example and it worked for me, I also edited MemoWrite in the example omitting the @CRLF part and still it returned the correct number of characters.

What version of AutoIt are you using? I'm on Windows 7 x64 and using V3.3.9.2 beta.


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
Kilmatead

I presume you are using it on a combo in an external app.

No, wholly AutoIt, reading from the generic GUICtrlCreateCombo()

What version of AutoIt are you using?

AutoIt version 3.3.8.1, Win7 x64.

My apologies - upon closer inspection, the example provided in the help file is perhaps not the best, as it doesn't show why someone would wish to use this over the more mundane GuiCtrlRead(), but that's not our concern here. Try this instead, as it allows for actual random input, not just preset values.

#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>

Global $Text
GUICreate("ComboBox", 400, 196)
Global $hCombo = GUICtrlCreateCombo("", 2, 20, 396, 296)
GUICtrlSetData(-1, "||Molay|Messiaen", "")
GUISetState()

Global $Button_Read = GUICtrlCreateButton("Read", 20, 60)

While True
    Switch GUIGetMsg()
        Case $Button_Read
            $Text = _GUICtrlComboBox_GetEditText($hCombo)
            MsgBox(0, "", "Text: " & $Text & @LF & "Length: " & StringLen($Text))
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Type in a word to the edit and/or select one from the dropdown and click Read (obviously). Do this repeatedly if it doesn't show up right away - when it does, the string length will be the giveaway even if the extra character is non-visible. With the "+ 1" in the original function this read fault shows up about 90% of the time; with the "+ 1" removed from the UDF, the return is precise, 100% of the time.

(And yes, I know _GUICtrlComboBox_GetEditText() expects a control handle whereas here it's fed an ID - that's not relevant as the UDF compensates for such oversights - this is just a quick example.)

Share this post


Link to post
Share on other sites
Melba23

Kilmatead,

I get no unexpected results with an extra character. I even put the _GUICtrlComboBox_GetEditText function in the idle loop and let it run for a few minutes while selecting different items and entering random text into the edit - every time the StringLen return matched the content:

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    $Text = _GUICtrlComboBox_GetEditText($hCombo)
    ConsoleWrite(StringLen($Text) & " - " & $Text & @CRLF)

WEnd

I am at a loss as to why you get an added character 9 times out of 10. The UDF function is commonly used and I cannot remember any earlier reports of a bug. :bye:

Out of interest why do you not use GUICtrlRead? :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
BrewManNH

I literally clicked this over 800 times, changed the code to a consolewrite replacing the msgbox, and used the Enter key with the Read button having focus, and in all the tests I did I couldn't get it to not return the correct text. Windows 7 x64 and x86.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
guinness

I had no problems either.


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
Kilmatead

I am at a loss as to why you get an added character 9 times out of 10. The UDF function is commonly used and I cannot remember any earlier reports of a bug. :doh:

Out of interest why do you not use GUICtrlRead? :bye:

And... I am at a loss as to why you are not generating the same faults as I get repeatedly (just with different end-characters):

Posted Image

As to why I don't use GUICtrlRead() - in the original application the input/combo dropdown is used to enter/track the history of accessed folders, with the usual bells and whistles where <Enter>, <Up>, <Down> etc are mapped to dummy controls which do the usual _GUICtrlComboBox_SetCurSel() fakery and dealing with the dropdown state, etc, so the combo doesn't fire on a keypress if read directly. (In fact it was one of your posts about using _GUICtrlComboBox_GetComboBoxInfo() to retrieve the separate DllStructGetData($tInfo, "hEdit") handle on the <Enter> keypress that sent me down this route.) To make a long story short, GuiCtrlRead() would not reliably return the text from the $hEdit handle under certain conditions (it had a bad habit of returning the last-selected value instead) - so _GUICtrlComboBox_GetEditText () came to the rescue.

Until I hit the repeating problem in the screenshot above, that is. As first I though this could have been due to any number of utilities one uses to hook screen elements (Listary comes to mind), but I could find no link, and no other conflicts - so I took a closer look at the DLL references in the UDF and found the extra allocated space which looked superfluous to me - and sure enough, removing it solved the problem (making me think the memory is not initialised upon allocation, thus it could contain any residue for that final wchar element).

As you tried the UDF without the "+ 1" reference and obviously the world didn't come to an end, I'm fairly confident I can live without it (the application is open-source, so can be used by others with different setups) - and if it didn't crash yours, hopefully it won't crash theirs.

If no one else can reproduce this :oops: then I'll look closer to home for an explanation - but I've never run into a situation where AutoIt didn't return the expected value from an in-programme created control before.

Very odd. Thank you all for trying.

Share this post


Link to post
Share on other sites
Kilmatead

At first I thought this could have been due to any number of utilities one uses to hook screen elements...

As a follow up, there does appear to be a conflict with DisplayFusion (a multi-monitor utility) as regards reading this particular control. If I disable it, then the UDF works fine every time, but the minute it's reactivated I get my odd extra character.

Normally the lads there are quite happy to hear about conflicts with other software, but I'm not sure how I'm going to explain "by the way, there's something inexplicable going on with your product and a wonky sequence of user32.dll calls". :oops:

Thanks again for trying. (Still bloody odd that my pseudo-fix worked...)

Share this post


Link to post
Share on other sites
Melba23

Kilmatead,

Thanks for the update. Good luck with the DisplayFusion developers on that one! :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Tankbuster

Sorry, re-activate this thread.

Do not ask me why I used  _GUICtrlComboBox_GetEditText and not GUICtrlRead, but I did. (but I changed my mind already)

I also found the additional char. I used the Example script from help file to check.

post-35896-0-20249100-1385511610_thumb.p

I thought it was teamviewer, but turning it on and off did not change it. I also tried beta 3.3.9.21. No diff.

Based on the last post I shutdown every app/service that obviously got something that references to screen. But that does not change anything.

I have to add that in some cases on the same system ( ! ) it works. I thought it is the length of the edit (20 or 21) but guess what: On investigating in that direction. It was gone.

For me it is not predicable when it happens and when not.

In the meantime I followed the advice and replaced the _GUICtrlComboBox_GetEditText with GUICtrlRead.

And this is working for sure.

I do not really expect that someone fixes this. I only wanted to add that it was not limited to one system.

 

//fyi:

I played with the sample of the help file:

1 )First my dummy code

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>

Global $iMemo

for $I = 1 to 1
    Example()
Next

Func Example()
    Local $hCombo

    ; Create GUI
    GUICreate("ComboBox Get Edit Text", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 266, 0)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()


    ; Set Edit Text

        for $j = 1 to 10
            $cData=""
            for $k = 1 to $j
                $cData=$cData&"x"
            next
            _GUICtrlComboBox_SetEditText($hCombo, $cData)
            MemoWrite("Edit Text: " & _GUICtrlComboBox_GetEditText($hCombo))
            ConsoleWrite("======================================="&@LF)
            ConsoleWrite("Edit Text UDF: " & _GUICtrlComboBox_GetEditText($hCombo)&@LF)
            ConsoleWrite("Edit Text def: " & GUICtrlRead($hCombo)&@LF)
            ConsoleWrite("Length UDF: " &stringlen(_GUICtrlComboBox_GetEditText($hCombo))&@LF)
            ConsoleWrite("Length def: " &stringlen(GUICtrlRead($hCombo))&@LF)
            ConsoleWrite("Last Char is: " &StringRight(_GUICtrlComboBox_GetEditText($hCombo),1)&@LF)
            ConsoleWrite("Last Char is: " &AscW (StringRight(_GUICtrlComboBox_GetEditText($hCombo),1))&@LF)
;~          AscW ( "char" )
        Next



    ; Get Edit Text




    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

2)Console ouput

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "E:\1work\hilfe.au3" /UserParams    
+>02:11:39 Starting AutoIt3Wrapper v.2.1.2.9    Environment(Language:0407  Keyboard:00000407  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64)
-> Skipping AU3check: Current version doesn't support the AutoIt3 v 3.3.9.5+ syntax.
>Running:(3.3.9.21):C:\Program Files (x86)\AutoIt3\autoit3.exe "E:\1work\hilfe.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
=======================================
Edit Text UDF: x~
Edit Text def: x
Length UDF: 2
Length def: 1
Last Char is: ?
Last Char is: 120
=======================================
Edit Text UDF: xx?
Edit Text def: xx
Length UDF: 3
Length def: 2
Last Char is: ?
Last Char is: 120
=======================================
Edit Text UDF: xxx?
Edit Text def: xxx
Length UDF: 4
Length def: 3
Last Char is: ?
Last Char is: 120
=======================================
Edit Text UDF: xxxx
Edit Text def: xxxx
Length UDF: 5
Length def: 4
Last Char is: ?
Last Char is: 2418
=======================================
Edit Text UDF: xxxxx
Edit Text def: xxxxx
Length UDF: 6
Length def: 5
Last Char is: 
Last Char is: 23
=======================================
Edit Text UDF: xxxxxx
Edit Text def: xxxxxx
Length UDF: 7
Length def: 6
Last Char is: ?
Last Char is: 24290
=======================================
Edit Text UDF: xxxxxxx?
Edit Text def: xxxxxxx
Length UDF: 8
Length def: 7
Last Char is: ?
Last Char is: 33538
=======================================
Edit Text UDF: xxxxxxxx?
Edit Text def: xxxxxxxx
Length UDF: 9
Length def: 8
Last Char is: ?
Last Char is: 53900
=======================================
Edit Text UDF: xxxxxxxxx?
Edit Text def: xxxxxxxxx
Length UDF: 10
Length def: 9
Last Char is: ~
Last Char is: 126
=======================================
Edit Text UDF: xxxxxxxxxx
Edit Text def: xxxxxxxxxx
Length UDF: 11
Length def: 10
Last Char is: ?
Last Char is: 25338

3)screenshot

post-35896-0-96779500-1385515223_thumb.p

Share this post


Link to post
Share on other sites
Kilmatead

I've been using my original "fix" (removing the "+ 1" from the struct's string-length declaration in the UDF) for almost a year now with no negative side-effects, so I haven't thought of it since. :ermm:

Share this post


Link to post
Share on other sites
Tankbuster

Thx, for your reply. More or less I wanted to say: Klimatead is not the only one.

(And also I hope that Melba or some other take a look...)

Maybe "they" should incorporate your fix.....(in other words)

 

Share this post


Link to post
Share on other sites
Melba23

Tankbuster,

 

I hope that Melba or some other take a look...

I just have done exactly that and, as before, I cannot reproduce the problem you are having. When I run the script you posted I get this:

=======================================
Edit Text UDF: x
Edit Text def: x
Length UDF: 1
Length def: 1
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xx
Edit Text def: xx
Length UDF: 2
Length def: 2
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxx
Edit Text def: xxx
Length UDF: 3
Length def: 3
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxx
Edit Text def: xxxx
Length UDF: 4
Length def: 4
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxx
Edit Text def: xxxxx
Length UDF: 5
Length def: 5
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxx
Edit Text def: xxxxxx
Length UDF: 6
Length def: 6
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxx
Edit Text def: xxxxxxx
Length UDF: 7
Length def: 7
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxxx
Edit Text def: xxxxxxxx
Length UDF: 8
Length def: 8
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxxxx
Edit Text def: xxxxxxxxx
Length UDF: 9
Length def: 9
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxxxxx
Edit Text def: xxxxxxxxxx
Length UDF: 10
Length def: 10
Last Char is: x
Last Char is: 120
So I cannot help at all - the UDF is working fine for me, as it appears to do for everyone bar you and Kilmatead. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Kilmatead

The notable thing (which was never clarified back when the thread was virginal) is why does there "appear" to be an extra character allocated in the UDF as it is?  In my case, the aberrance was localised to a single 3rd-party programme, when that was removed, the "problem" was solved.  But what is interesting, is that the UDF will also work just fine (apparently for "everyone") with that "+ 1 allocation" removed... extra 3rd-party interference or not.

So... "with" the +1 the UDF fails for 2 in a million, and "without" the +1 it would (apparently) fail for 0 in a million.  Or is that just a facetious syllogism based on empirical luck rather than logic? :)

 

Share this post


Link to post
Share on other sites
Tankbuster

Thx, Melba, for taking a look.

I also added the fix (remove +1) in the GuiComboBox.au3. And I have to confirm it is now always working correct.

But as stated before: Sometimes it is working even without the fix.

The same code (compiled with original GuiComboBox.au3) showed this:

1 out of 2 Win7 64x - additional char

1 out of 3 Win7 32x - additional char

 

Does not make sense but more or less I'm facing the same as Klimatead.

So we (Klimatead and myself) are either blessed ones or the opposite.

 

Maybe Klimatead should marked the thread as [Mystic] vs [solved] :-)

Share this post


Link to post
Share on other sites
Melba23

Kilmatead & Tankbuster,

All I can think of is that your systems are creating the buffer over existing data and so the return includes the extra character which has not been overwritten. But why just your systems? I would expect the same behaviour from all systems if this was the case - and it evidently is not. :wacko:

Anyway, after some time spent looking through MSDN (which always leaves me feeling a bit suicidal :() I can see no reason why the $tText struct in the UDF has the added length - nor the earlier $tBuffer struct have the length value increased by 2. When I test the UDF with these 2 structs set to exactly the returned length I still get the same return:

Edit Text UDF: x
Edit Text UDF: x
Edit Text def: x
Length UDF: 1
Length Mod: 1
Length def: 1
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xx
Edit Text UDF: xx
Edit Text def: xx
Length UDF: 2
Length Mod: 2
Length def: 2
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxx
Edit Text UDF: xxx
Edit Text def: xxx
Length UDF: 3
Length Mod: 3
Length def: 3
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxx
Edit Text UDF: xxxx
Edit Text def: xxxx
Length UDF: 4
Length Mod: 4
Length def: 4
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxx
Edit Text UDF: xxxxx
Edit Text def: xxxxx
Length UDF: 5
Length Mod: 5
Length def: 5
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxx
Edit Text UDF: xxxxxx
Edit Text def: xxxxxx
Length UDF: 6
Length Mod: 6
Length def: 6
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxx
Edit Text UDF: xxxxxxx
Edit Text def: xxxxxxx
Length UDF: 7
Length Mod: 7
Length def: 7
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxxx
Edit Text UDF: xxxxxxxx
Edit Text def: xxxxxxxx
Length UDF: 8
Length Mod: 8
Length def: 8
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxxxx
Edit Text UDF: xxxxxxxxx
Edit Text def: xxxxxxxxx
Length UDF: 9
Length Mod: 9
Length def: 9
Last Char is: x
Last Char is: 120
=======================================
Edit Text UDF: xxxxxxxxxx
Edit Text UDF: xxxxxxxxxx
Edit Text def: xxxxxxxxxx
Length UDF: 10
Length Mod: 10
Length def: 10
Last Char is: x
Last Char is: 120
Could one or both of you please try the code posted above with this modified function to see if you too get the same results on your systems:

Func _GUICtrlComboBox_GetEditText_Mod($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Local $tInfo
    If _GUICtrlComboBox_GetComboBoxInfo($hWnd, $tInfo) Then
        Local $hEdit = DllStructGetData($tInfo, "hEdit")
        Local $iLine = 0
        Local $iIndex = _SendMessage($hEdit, $__COMBOBOXCONSTANT_EM_LINEINDEX, $iLine)
        Local $iLength = _SendMessage($hEdit, $__COMBOBOXCONSTANT_EM_LINELENGTH, $iIndex)
        If $iLength = 0 Then Return ""
        Local $tBuffer = DllStructCreate("short Len;wchar Text[" & $iLength & "]") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< removed + 2
        DllStructSetData($tBuffer, "Len", $iLength) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< removed + 2

        Local $iRet = _SendMessage($hEdit, $__COMBOBOXCONSTANT_EM_GETLINE, $iLine, $tBuffer, 0, "wparam", "struct*")
        If $iRet = 0 Then Return SetError(-1, -1, "")

        Local $tText = DllStructCreate("wchar Text[" & $iLength & "]", DllStructGetPtr($tBuffer)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< removed + 1
        Return DllStructGetData($tText, "Text")
    Else
        Return SetError(-1, -1, "")
    EndIf
EndFunc   ;==>_GUICtrlComboBox_GetEditText_Mod
If you find no problems then I suggest a bug report on Trac with a link to this thread. I will leave it to you to decide who gets the honour! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Kilmatead

In the interest of full disclosure, in the intervening 16.666666666666664% of a decade, I have reinstalled Windows twice and no longer use the original offending application, and now I get the same results as everyone else (including your last test of the "fixed" version).  In my defence, I was not imagining it at the time, and could only track the interference down to a single 3rd party.

I would suggest Tankbuster's case to be the more significant at the moment, as he hasn't been able to localise the problem as yet - and indeed would be better placed to test any possible "permanent" fixes.

I have, as a precaution, always taken to using the "fixed" UDF for anything released in the wild, simply because I "know" that one will work no matter what.  But, again, I can't test it properly since I can no longer reproduce the fault. :

Re MSDN: it doesn't help that in this case it says text buffer (sizes) are defined dynamically on an as-needed basis (possibly "using memory outside the application's data segment"), so buffer size/location doesn't seem to be an easily predictable thing.  How AutoIt does it initially is well outside my paygrade, blissfully. :D

Edited by Kilmatead

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  

×