I have a custom data format in the clipboard (it is put there by a third-party program). I get the size of the data from the clipboard using:
HANDLE data = GetClipboardData(format);
DWORD len = GlobalSize(data);
The problem is, I get incorrect data size (about plus 100 bytes of what it actually should be). I mean, the size of real "valid" data in the clipboard is different. Moreover, I get different (!) data sizes from one call to another (although, the data itself does not change). Looks mysterious. I mean, if I just keep executing the above two lines in a loop, I'll be getting different values in "len" for this format.
So I have two questions basically...
How comes that "GlobalSize" may return non-constant values from one call to another for the very same data?
How do I get the "real" data size for the clipboard data in this format?
Thank you in advance!
From the MSDN page on the GlobalSize
function:
The size of a memory block may be larger than the size requested when the memory was allocated
So you can not rely on GlobalSize
to return the requested size of the allocation. Instead, you should pass the size as part of the data object itself (e.g. begin with a DWORD
containing the size, followed by your data).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With