
Extern "Win32"
 Const GMEM_FIXED:Int = 0
 Const CF_TEXT:Int=1

 Function OpenClipboard(hwnd%)
 Function CloseClipboard()
 Function EmptyClipboard()
 Function SetClipboardData(format%, hMem:Byte ptr)

 Function GlobalAlloc:Byte ptr( uflags:Int, bytes:Byte )
 Function GlobalFree( buf:Byte Ptr )

End Extern  

' -----------------------------------------------

Function Paste2ClipBoard(txt:String)
 Local hbuf:Byte Ptr
 If OpenClipboard(0)
	EmptyClipboard
	hbuf = GlobalAllocString( txt )
	SetClipboardData CF_TEXT, hbuf
	CloseClipboard
 Else
	RuntimeError "Failed to open Clipboard"
 EndIf

 If hbuf GlobalFree( hbuf )
 End
EndFunction 

Function GlobalAllocString:Byte Ptr( txt$ )
	local p:byte ptr= GlobalAlloc( GMEM_FIXED , len(txt)+1 )
	For Local i:Int=0 Until Len(txt)
		p[i]=txt[i]
	next
	p[Len(txt)+1]=0
	Return p
EndFunction