Menu

#926 #Define Unicode: Len(string) returns chars but lstrcpy translates to lstrcpyW

closed
nobody
None
compiler
2020-12-13
2020-11-20
jj2007
No
#define UNICODE ' **** DANGER ****
#include once "windows.bi"

Sub SaveToClipBoard(Byref Text As String)
    Var Buffer=GlobalAlloc(GMEM_MOVEABLE, Len(Text)+1)   ' Len refers to the Ansi version of the text
    lstrcpy(GlobalLock(Buffer), Text)         ' but the Unicode version gets copied!
    GlobalUnlock(Buffer)
    OpenClipboard(GetDesktopWindow())
    EmptyClipboard()
    SetClipboardData(CF_UNICODETEXT, Buffer)
    CloseClipboard()
End Sub

SaveToClipBoard("Hello world, how are you?")

print "text set to clipboard"
Sleep

Discussion

  • Jeff Marshall

    Jeff Marshall - 2020-12-05

    Len(text) returns the length of the ANSI text, which can include embedded NULL chars.
    Where is the bug?
    Either lstrcpy should not accept fb's ansi text STRING, or user needs to understand how UNICODE affects the win api.

     
  • Jeff Marshall

    Jeff Marshall - 2020-12-13
    • status: open --> closed
     

Log in to post a comment.