How do i copy a string to the clipboard?
Printable View
How do i copy a string to the clipboard?
Anyone?
This will copy the string "vlatko" to the clipboard:
Code:#include <windows.h>
int main(int argc, char* argv[])
{
LPTSTR lptstrCopy;
OpenClipboard(NULL);
EmptyClipboard();
HGLOBAL txt = GlobalAlloc(GMEM_DDESHARE,(strlen("vlatko") +1 ) * sizeof(TCHAR));
lptstrCopy = (char*)GlobalLock(txt);
memcpy(lptstrCopy,"vlatko",(strlen("vlatko")) * sizeof(TCHAR));
lptstrCopy[strlen("vlatko")] = (TCHAR) 0;
GlobalUnlock(txt);
SetClipboardData(CF_TEXT,txt);
CloseClipboard();
return 0;
}
What is argc?
It is an argument of the main function. It doesn't do nothing in this case. argc contains the nuber of parameters passed to the program.