#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
Len(text)returns the length of the ANSI text, which can include embedded NULL chars.Where is the bug?
Either
lstrcpyshould not accept fb's ansi textSTRING, or user needs to understand howUNICODEaffects the win api.