#include #include int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdLn, int nShowCmd) { HGLOBAL hglb; LPTSTR lptstr; char *txt = 0; int txtlen; // check that it is possible to get the clipboard as plain text if (!::IsClipboardFormatAvailable(CF_TEXT)) return 1; // open the clipboard and grab the data as text if (!::OpenClipboard(NULL)) return 1; hglb = ::GetClipboardData(CF_TEXT); // get the data and stick it into a local buffer if (hglb != NULL) { lptstr = (LPTSTR)::GlobalLock(hglb); if (lptstr != NULL) { txtlen = strlen(lptstr); if(txtlen>0) { txt = (char*)malloc(txtlen+1); if(txt) strcpy(txt, lptstr); } ::GlobalUnlock(hglb); } } if(!txt) { ::CloseClipboard(); return 1; } // empty the existing contents of the clipboard ::EmptyClipboard(); // try to get a global buffer for the text HGLOBAL hglbCopy = ::GlobalAlloc(GMEM_MOVEABLE, txtlen+1); if (hglbCopy == NULL) { ::CloseClipboard(); return 1; } // copy local buffer into global buffer LPTSTR memPtr = (LPTSTR)::GlobalLock(hglbCopy); memcpy(memPtr, txt, txtlen + 1); free(txt); ::GlobalUnlock(hglbCopy); // put global buffer on the clipboard ::SetClipboardData(CF_TEXT, hglbCopy); ::CloseClipboard(); return 0; }