Created
November 9, 2021 18:25
-
-
Save khchen/04af0db048beea845b49f6db969e27ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[ | |
| 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