Skip to content

Instantly share code, notes, and snippets.

@khchen
Created November 9, 2021 18:25
Show Gist options
  • Select an option

  • Save khchen/04af0db048beea845b49f6db969e27ce to your computer and use it in GitHub Desktop.

Select an option

Save khchen/04af0db048beea845b49f6db969e27ce to your computer and use it in GitHub Desktop.
#[
Author: Ward
Example of GetClipboardData
References:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboarddata
]#
import winim/lean
if OpenClipboard(0) != 0:
defer: CloseClipboard()
var hData: HANDLE
# Read as ansi string
hData = GetClipboardData(CF_TEXT)
if hData != 0:
let pstr = cast[LPSTR](GlobalLock(hData))
defer: GlobalUnlock(hData)
if pstr != nil:
# `$` (defined in winstr) will convert ansi string (LPSTR) to nim string
echo $pstr
# Read as unicode string
hData = GetClipboardData(CF_UNICODETEXT)
if hData != 0:
let pwstr = cast[LPWSTR](GlobalLock(hData))
defer: GlobalUnlock(hData)
if pwstr != nil:
# `$` (defined in winstr) will convert unicode string (LPWSTR) to nim string
echo $pwstr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment