Skip to content

Commit

Permalink
handle unicode text for clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 22, 2024
1 parent 614f176 commit 69d2a98
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ static void set_clipboard(char *text) {
if (!OpenClipboard(ctx->hwnd)) return;
EmptyClipboard();

HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, strlen(text) + 1);
int len = MultiByteToWideChar(CP_UTF8, 0, text, -1, NULL, 0);
HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, len * sizeof(WCHAR));
if (hData != NULL) {
char *data = (char *)GlobalLock(hData);
WCHAR *data = (WCHAR *)GlobalLock(hData);
if (data != NULL) {
strcpy(data, text);
MultiByteToWideChar(CP_UTF8, 0, text, -1, data, len);
GlobalUnlock(hData);
SetClipboardData(CF_TEXT, hData);
SetClipboardData(CF_UNICODETEXT, hData);
}
}
CloseClipboard();
Expand Down

0 comments on commit 69d2a98

Please sign in to comment.