Skip to content

Instantly share code, notes, and snippets.

@sunflsks
Last active August 7, 2021 23:10
Show Gist options
  • Save sunflsks/c16a29535afe96dd50241dbc34671ff2 to your computer and use it in GitHub Desktop.
Save sunflsks/c16a29535afe96dd50241dbc34671ff2 to your computer and use it in GitHub Desktop.
simple win32 paste program
#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