Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function CloseClipboard Lib "User32" () As Long
Private Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
Private Declare Function EmptyClipboard Lib "User32" () As Long
Private Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Private Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Const GHND = &H42
Private Const CF_TEXT = 1
Private Const MAXSIZE = 4096
Public Function NaarKlemBord(tekst As String)
Dim mem1 As Long, mem2 As Long
Dim result As Long, X As Long
mem1 = GlobalAlloc(GHND, Len(tekst) + 1)
mem2 = GlobalLock(mem1)
mem2 = lstrcpy(mem2, tekst)
If GlobalUnlock(mem1) <> 0 Then
MsgBox "Geheugenprobleem", 16
GoTo OutOfHere2
End If
If OpenClipboard(0&) = 0 Then
MsgBox "Probleem met het klembord", 16
Exit Function
End If
X = EmptyClipboard()
result = SetClipboardData(CF_TEXT, mem1)
OutOfHere2:
If CloseClipboard() = 0 Then
MsgBox "Probleem met het sluiten van het klembord", 16
End If
End Function