windows - UTF-8 text to clipboard C -
i have been looking around on how bring string,
const char* output = "ヽ(⌐■_■)ノ♪♬";
to clipboard.
setclipboarddata(cf_unicodetext, hmem);
i have tried multibytetowidechar, have gotten noise , conflicting claims cannot save utf-16le clipboard (wchar_t). confused. direction or code sample great.
windows uses utf-16le. string should created l
prefix. use utf8 can declare string u8
prefix. example:
const char* text = u8"ヽ(⌐■_■)ノ♪♬e";
then have use multibytetowidechar
convert utf8 utf16 , use in winapi. note use u8
need newer compilers vs2015.
it's easier use utf16 in first place. example:
const wchar_t* text = l"ヽ(⌐■_■)ノ♪♬e"; int len = wcslen(text); hglobal hmem = globalalloc(gmem_moveable, (len + 1) * sizeof(wchar_t)); wchar_t* buffer = (wchar_t*)globallock(hmem); wcscpy_s(buffer, len + 1, text); globalunlock(hmem); openclipboard(null); emptyclipboard(); setclipboarddata(cf_unicodetext, hmem); closeclipboard();
Comments
Post a Comment