this is my attempt but when executed the clipboard only has "he"
please note that I am not familiar with Wstring and whether I am using the datatype correctly, all help is much appreciated.
what's the function name to get the unicode string length?
Code: Select all
#define unicode
#include "windows.bi"
Public Sub SetClipboard(sUniText As LPCWSTR)
Dim iStrPtr As Long ptr
Dim iLen As Long
Dim iLock As LPWSTR
' Const GMEM_MOVEABLE As Long = &H2
' Const GMEM_ZEROINIT As Long = &H40
' Const CF_UNICODETEXT As Long = &HD
OpenClipboard 0&
EmptyClipboard
iLen = len(sUniText) + 2& ''LenB(sUniText) + 2&
iStrPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, iLen)
iLock = GlobalLock(iStrPtr)
lstrcpyW (iLock, sUniText)
GlobalUnlock iStrPtr
SetClipboardData CF_UNICODETEXT, iStrPtr
CloseClipboard
End Sub
Public Function GetClipboard() As String
Dim iStrPtr As Long ptr
Dim iLen As Long
Dim iLock As LPWSTR
Dim sUniText As wString ptr
' Const CF_UNICODETEXT As Long = 13&
OpenClipboard 0&
If IsClipboardFormatAvailable(CF_UNICODETEXT) Then
iStrPtr = GetClipboardData(CF_UNICODETEXT)
If iStrPtr Then
iLock = GlobalLock(iStrPtr)
iLen = GlobalSize(iStrPtr)
*sUniText = String(iLen , NULL) ''String(iLen \ 2& - 1&, NULL)
lstrcpyW ((sUniText), iLock)
GlobalUnlock iStrPtr
End If
GetClipboard = *sUniText
End If
CloseClipboard
End Function
dim as wstring ptr s = allocate(250)
*s = "hello"
SetClipboard(s)
deallocate(s)