-2021-08-24 Mark Geisert <mark@maxrnd.com>
+2021-08-28 Mark Geisert <mark@maxrnd.com> (1.4.16-6)
+
+ * src/clip/putclip.c: Supply terminator for Unicode input lacking it.
+ Add diagnostic for OpenClipboard() failure that results in "Couldn't
+ write CF_TEXT format to the clipboard" error message. Thanks to
+ Takashi Yano for the reports.
+ * Makefile.am: src_clip_getclip_LDADD no longer needs -lkernel32.
+
+2021-08-24 Mark Geisert <mark@maxrnd.com> (1.4.16-5)
* src/clip/putclip.c: Fix broken Unicode support. Don't GlobalFree a
handle that's been transferred to the system by SetClipboardData().
Thanks to Christian Franke for that last bit.
-2021-08-15 Mark Geisert <mark@maxrnd.com>
+2021-08-15 Mark Geisert <mark@maxrnd.com> (1.4.16-4)
* Makefile.am: Add -lkernel32 to src_clip_getclip_LDADD. This somehow
didn't make it into the released -3 package. Thank you Takashi Yano.
* src/cygdrop/cygdrop.cc: Fix crash with recent gcc and fix printf
format strings. Thank you Christian Franke.
-2021-07-05 Mark Geisert <mark@maxrnd.com>
+2021-07-05 Mark Geisert <mark@maxrnd.com> (1.4.16-3)
* src/clip/getclip.c: Add Unicode support.
const char *CYGWIN_NATIVE = "CYGWIN_NATIVE_CLIPBOARD";
UINT cygnativeformat;
- OpenClipboard (0);
+ if (!OpenClipboard (0))
+ {
+ fprintf (stderr, "Unable to open the clipboard\n");
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "OpenClipboard returns %ld\n", err);
+#endif
+ return (PUTCLIP_ERR);
+ }
cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
CloseClipboard ();
/* Allocate memory and copy the string to it */
/* cygwin native format */
- OpenClipboard (0);
+ if (!OpenClipboard (0))
+ {
+ fprintf (stderr, "Unable to open the clipboard\n");
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "OpenClipboard returns %ld\n", err);
+#endif
+ if (convbuf)
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
if (cygNewFormat)
hData = GlobalAlloc (GMEM_MOVEABLE, convlen + sizeof (cygcb_t));
else
fprintf (f,
"Couldn't write native format to the clipboard %04x %x\n",
cygnativeformat, hData);
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "SetClipboardData returns %ld\n", err);
+#endif
free (convbuf);
return (PUTCLIP_ERR);
}
clipbuf = NULL;
/* CF_UNICODETEXT format */
- OpenClipboard (0);
+ if (!OpenClipboard (0))
+ {
+ fprintf (f, "Unable to open the clipboard\n");
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "OpenClipboard returns %ld\n", err);
+#endif
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
if (!(hData = GlobalAlloc (GMEM_MOVEABLE, sizeof (WCHAR) * convlen + 2)))
{
fprintf (f, "Couldn't allocate global buffer for write.\n");
#if DEBUGGING
DWORD err = GetLastError ();
/* look up error code displayed here in w32api/winerror.h */
- fprintf (stderr, "MultiByteToWideChar returns %d\n", err);
+ fprintf (stderr, "MultiByteToWideChar returns %ld\n", err);
#endif
}
else /* res != 0 */
{
+ *((WCHAR *) clipbuf + res) = 0; /* NULL-terminate just in case */
#if DEBUGGING
fprintf (stderr, "len %d, convlen %d, res %d\n", len, convlen, res);
#endif
if (!SetClipboardData (CF_UNICODETEXT, hData))
{
fprintf (f, "Couldn't write CF_UNICODETEXT format to the clipboard.\n");
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "SetClipboardData returns %ld\n", err);
+#endif
free (convbuf);
return (PUTCLIP_ERR);
}
clipbuf = NULL;
/* CF_TEXT format */
- OpenClipboard (0);
+ if (!OpenClipboard (0))
+ {
+ fprintf (f, "Unable to open the clipboard\n");
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "OpenClipboard returns %ld\n", err);
+#endif
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
if (!(hData = GlobalAlloc (GMEM_MOVEABLE, convlen + 2)))
{
fprintf (f, "Couldn't allocate global buffer for write.\n");
if (!SetClipboardData (CF_TEXT, hData))
{
fprintf (f, "Couldn't write CF_TEXT format to the clipboard.\n");
+#if DEBUGGING
+ DWORD err = GetLastError ();
+ /* look up error code displayed here in w32api/winerror.h */
+ fprintf (stderr, "SetClipboardData returns %ld\n", err);
+#endif
free (convbuf);
return (PUTCLIP_ERR);
}