Last active
October 13, 2024 00:57
-
-
Save sunflsks/c16a29535afe96dd50241dbc34671ff2 to your computer and use it in GitHub Desktop.
simple win32 paste program
This file contains 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
#include <windows.h> | |
#include <stdio.h> | |
int main(void) { | |
if (!OpenClipboard(NULL)) { | |
fprintf(stderr, "Failed to open clipboard!\n"); | |
return 1; | |
} | |
HANDLE clipboard; | |
if (!(clipboard = GetClipboardData(CF_TEXT))) { | |
fprintf(stderr, "Failed to get clipboard data handle!\n"); | |
return 2; | |
} | |
const char* text = (const char*)GlobalLock(clipboard); | |
if (!text) { | |
fprintf(stderr, "Failed to lock clipboard data handle!\n"); | |
return 3; | |
} | |
printf("%s", text); | |
GlobalUnlock(clipboard); | |
CloseClipboard(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment