In documentation
If the clipboard format is not available, the return value is zero. To get extended error information, call GetLastError. IsClipboardFormatAvailable function (winuser.h)
but the output of this code is 0:
#include <Windows.h>
#include <cstdio>
#include <winerror.h>
int main()
{
//I copied an image to the clipboard before running the program
if(!IsClipboardFormatAvailable(CF_UNICODETEXT))
{
printf("%lu", GetLastError());
}
}
Why didn't the IsClipboardFormatAvailable function set the last error?
I've seen this pattern before. Typically IsClipboardFormatAvailable() is not a function that can fail; and there's not expected to be anything useful to report because the last thing in the clipboard just doesn't match any known format.
If you're really in a situation where IsClipboardFormatAvailable() can fail and need to check and do something about the difference, this fragment is correct:
SetLastError(0);
if(!IsClipboardFormatAvailable(CF_UNICODETEXT))
{
if (GetLastError() == 0)
{
printf("Clipboard doesn't contain text.");
} else {
printf("IsClipboardFormatAvailable: %lu", GetLastError());
}
}
You described a case of image in the clipboard in the question. The function didn't fail.
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