Discussion:
SetClipboardData CF_TEXT - last char disappears
(too old to reply)
R.Wieser
2019-08-29 17:31:11 UTC
Permalink
Hello all,

Just now I placed some text into the clipboard using
SetClipboardData,CF_TEXT, ofcourse providing it with a handle to some global
movable memory. (remark: just the text, not including a terminating zero).
But when I than paste the contents (into notepad) the last char has gone.
:-(

As a test I just allocated the global memory a single byte larger (no other
change!), and as the result the last char appeared again. whut!

The thing is that, on
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setclipboarddata I
do not see any kind of remark or warning for it. Which makes me wonder
what I ran into ... My misunderstanding of something, or MS being
less-than-complete in its docs ?

(OS: XPsp3)

Regards,
Rudy Wieser
Udo Steinbach
2019-08-30 13:35:13 UTC
Permalink
https://docs.microsoft.com/de-de/windows/win32/dataxchg/standard-clipboard-formats
3 kinds of Text, and, traraaaaaaa,
"A null character signals the end of the data."
"A null character signals the end of the data."
"A null character signals the end of the data."
--
Fahrradverkehr in Deutschland: http://radwege.udoline.de/
GPG: A245 F153 0636 6E34 E2F3 E1EB 817A B14D 3E7E 482E
R.Wieser
2019-08-30 15:41:07 UTC
Permalink
Udo,
Post by Udo Steinbach
"A null character signals the end of the data."
NOW he tells me :-)

Yep. After I followed the link to the different clipboard formats I saw
that mentioned too. Mea culpa.

But! That still leaves the question why the last character of my
stored-into-clipboard text disappeared, instead of throwing an error (bad
format) or perhaps just appending the zero.

By the way, that SetClipboardData was able to figure out the end of my text
is remarkable, as I only gave it some movable global memory - and the
GlobalSize function specifies that "The size of a memory block may be larger
than the size requested when the memory was allocated."

Regards,
Rudy Wieser
Udo Steinbach
2019-09-10 13:10:39 UTC
Permalink
Post by R.Wieser
That still leaves the question why the last character of my
stored-into-clipboard text disappeared
No, no But. That's garbage in, garbage out at work. If you ask about
handling garbage that way, I ask, why Windows does not generally answer
with killing the process. But that's another topic.
--
Fahrradverkehr in Deutschland: http://radwege.udoline.de/
GPG: A245 F153 0636 6E34 E2F3 E1EB 817A B14D 3E7E 482E
R.Wieser
2019-09-10 15:03:24 UTC
Permalink
Udo,
Post by Udo Steinbach
No, no But. That's garbage in, garbage out at work.
True. But in that case I would have expected "random" chars to appear with
the pasting (upto the size of the allocated memory block).
Post by Udo Steinbach
I ask, why Windows does not generally answer
with killing the process.
:-) A bit BOFH there ? :-p

Regards,
Rudy Wieser

Loading...