• Welcome to PlanetSquires Forums.
 

AfxGetComboBoxText

Started by Paul Squires, August 19, 2019, 03:00:19 PM

Previous topic - Next topic

Paul Squires

Hi Jose,

Looks like AfxGetComboBoxText is returning a trailing NULL character. You probably need to modify the last line of the function similar to how you handle AfxGetWindowText.

Current code in AfxCtl.inc:

' ========================================================================================
' Gets a string from a list in a combo box.
' - hComboBox: A handle to the combobox.
' - nIndex: The zero-based index of the item.
' ========================================================================================
PRIVATE FUNCTION AfxGetComboBoxText (BYVAL hComboBox AS HWND, BYVAL nIndex AS LONG) AS CWSTR
   DIM nLen AS LONG = SendMessageW(hComboBox, CB_GETLBTEXTLEN, nIndex, 0)
   DIM cwsText AS CWSTR = SPACE(nLen + 1)
   SendMessageW(hComboBox, CB_GETLBTEXT, nIndex, cast(LPARAM, *cwsText))
   RETURN cwsText
END FUNCTION
' ========================================================================================


Maybe:
   RETURN cwsText

Should be:
  RETURN LEFT(**cwsText, LEN(cwsText) - 1)

Took me a while to find out why some of my Form files with ToolBars were not loading. Appears that the NULL was being inserted into the file causing the parsing on load to fail.

Thanks,

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Done. Thanks for spotting it.