I need to copy the contents of a handle returned by GetClipboardData from winuser.h, but can't seem to find anything about how to do this.
My program needs to be able to retrieve the contents of the clipboard (regardless of format), set clipboard contents, then return the clipboard contents to the original value, unfortunately since I have to call emptyClipboard() before setClipboardData(), this invalidates the handle returned by GetClipboardData(). I can't seem to find a way to get the length of whatever the handle points to to copy it myself, and the DuplicateHandle function doesn't seem to allow copying of clipboard handles if I understand the docs correctly.
Anyone have any ideas of what I can do here?
rough outline of what I'm trying to do for clarity:
HANDLE clipboardContents;
HANDLE copyMe = WhatIWantOnClipboard();
for (int i = 0; i < 26; i++) {
if ((clipboardContents = GetClipboardData(dataFormats[i])) != NULL) {
formatType = dataFormats[i];
break;
}
else if (i == 25) {
//nothing in clipboard
clipboardContents = -1;
}
}
EmptyClipboard();
SetClipboardData(FORMAT, copyMe);
DoSomethingWithClipboard();
EmptyClipboard();
SetClipboardData(formatType, clipboardContents);
//above will fail with error code 5: Access is denied. As I have emptied the clipboard, which I have to to set the data, from what I understand.
I've tried all different permutations of when I can call functions to no avail, I've attempted to memcopy the contents of the clipboard, but since I can't get the length of what is at the handle, I can't do this.