1. 程式人生 > >C++讀取UNICODE內容到剪貼簿

C++讀取UNICODE內容到剪貼簿

if (OpenClipboard()) {
			HGLOBAL clipBuffer;
			EmptyClipboard();
			wchar_t*buffer;
			clipBuffer = GlobalAlloc(GMEM_DDESHARE, 2 * lstrlen(str) + sizeof(wchar_t));
			buffer = (wchar_t*)GlobalLock(clipBuffer);
			wcscpy_s(buffer, str.GetLength() + 1, str);
			GlobalUnlock(clipBuffer);
			SetClipboardData(CF_UNICODETEXT, clipBuffer);
			CloseClipboard();
		}