This code should send a string to the clipboard. However, I made it work once. Now this does not work correctly when I CTRL + V.
But when I use this snippet to identify the clipboard text, it shows what it should be.
#include <windows.h>
#include <iostream>
BOOL SetClipboardText(LPCTSTR pszText)
{
BOOL ok = FALSE;
if(OpenClipboard(NULL)) {
HGLOBAL hMem = GlobalAlloc(GMEM_SHARE | GMEM_MOVEABLE,
(lstrlen(pszText)+1)*sizeof(pszText[0]) );
LPTSTR ptxt = (LPTSTR)GlobalLock(hMem);
lstrcpy(ptxt, pszText);
GlobalUnlock(hMem);
ok = (BOOL)SetClipboardData(CF_TEXT, hMem);
CloseClipboard();
}
return ok;
}
int main()
{
LPCTSTR test = "DOG";
SetClipboardText(test);
return 0;
}
#include <windows.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
HANDLE clip;
if (OpenClipboard(NULL))
clip = GetClipboardData(CF_TEXT);
printf("%s",clip);
cin.get();}
killgo0r
source
share