Does someone see why Kaspersky on Win10 gets angered with this (dodi's one) version :
Code: Select all
#include once "windows.bi"
Sub SaveToClipBoard(Byref Text As String)
'https://www.freebasic.net/forum/viewtopic.php?p=210732#p210732
Var Num=GlobalAlloc(0,Len(Text)+1)
Var Chars=GlobalLock(Num)
Chars= @text[0]
GlobalUnlock(Num)
OpenClipboard(0)
EmptyClipboard()
SetClipboardData(CF_TEXT,Chars)
CloseClipboard()
End Sub
SaveToClipBoard("hello")
Code: Select all
#include once "windows.bi"
Sub set_clipboard(Byref txt As Const String)
'https://www.freebasic.net/forum/viewtopic.php?f=7&t=14933&p=128787&hilit=clipboard+empty#p128787
Dim As HANDLE hText = NULL
Dim As Ubyte Ptr clipmem = NULL
Dim As Integer n = Len(txt)
If n > 0 Then
hText = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, n + 1)
Sleep 15
If (hText) Then
clipmem = GlobalLock(hText)
If clipmem Then
CopyMemory(clipmem, Strptr(txt), n)
Else
hText = NULL
End If
If GlobalUnlock(hText) Then
hText = NULL
End If
End If
If (hText) Then
If OpenClipboard(NULL) Then
Sleep 15
If EmptyClipboard() Then
Sleep 15
If SetClipboardData(CF_TEXT, hText) Then
Sleep 15
End If
End If
CloseClipboard()
End If
End If
End If
End Sub
set_clipboard("hello")