// hwnd can be null, lpsztext is a string that needs to be copied.
Bool CopyStringToClipboard (hwnd hwnd, lpctstr lpsztext) {int Nlen = Strlen (lpsztext); if (nlen == 0) Return False;
// Copy the contents of SzText to the clipboard hglobal hglbcopy; lptstr lptstrcopy;
IF (! :: OpenClipboard (hwnd)) Return False;
Hglbcopy = Globalalloc (gmem_ddeshare, (Nlen 1) * Sizeof (char)); if (hglbcopy == null) {closeclipboard (); returnaf
EMPTYCLIPBOARD ();
lptstrCopy = (LPTSTR) GlobalLock (hglbCopy); memcpy (lptstrCopy, lpszText, nlen); lptstrCopy [nlen] = (TCHAR) 0; // null character GlobalUnlock (lptstrCopy); SetClipboardData (CF_TEXT, hglbCopy); CloseClipboard ();
Return True;}