| Previous | Next |
| CLIPBRD_E_CANT_EMPTY | CLIPBRD_E_BAD_DATA |
CLIPBRD_E_CANT_SET
SetClipboard Failed
CLIPBRD_E_CANT_SET is the failure HRESULT 2147746258 (0x800401D2, signed -2147221038) from winerror.h. AllStat defines it as “SetClipboard Failed”. In practical terms, SetClipboardData failed for the supplied format and handle. Interpret it in the context of publishing one clipboard format after OpenClipboard and EmptyClipboard.
The high bit in 0x800401D2 is set, so this is a failure rather than a success or informational result. Its facility field is 4 (FACILITY_ITF) and its low 16-bit code is 466 (0x01D2). Those bit fields classify the value, but they do not identify the failing object by themselves; the native method, object identity, and first producer of CLIPBRD_E_CANT_SET remain essential.
Contract boundary
Understanding CLIPBRD_E_CANT_SET requires this subsystem context: The Win32 clipboard is a short ownership transaction with format-specific handle semantics. For CLIPBRD_E_CANT_SET, logging only a final HRESULT loses whether the failure happened while opening, emptying, publishing, or later consuming data.
- Associate
CLIPBRD_E_CANT_SETwith one exact operation in OpenClipboard, EmptyClipboard, SetClipboardData, format-specific handle rules, delayed rendering, and clipboard ownership. - Confirm that
CLIPBRD_E_CANT_SETcame from publishing one clipboard format after OpenClipboard and EmptyClipboard, rather than from cleanup or a wrapper that ran afterward. - Preserve any IErrorInfo, underlying Win32 result, provider message, or callback failure that preceded
CLIPBRD_E_CANT_SET; the HRESULT alone should not erase a more specific cause.
Likely cause branches
CLIPBRD_E_CANT_SETcan result when the clipboard is not open or has no valid owner after EmptyClipboard.CLIPBRD_E_CANT_SETcan result when the handle type or memory allocation rules do not match the format.CLIPBRD_E_CANT_SETcan result when ownership was transferred or the same handle was reused, freed, locked, or modified incorrectly.
Evidence to preserve
A useful CLIPBRD_E_CANT_SET incident records the clipboard opener HWND, owner HWND, sequence number, format ID and name, handle type, allocation flags, delayed-rendering choice, last-error value, and thread or message-loop state. For CLIPBRD_E_CANT_SET, also retain the application and component build, architecture, process and thread IDs, COM apartment, operation correlation ID, elapsed time, and the first state-changing event before the failure. When logging CLIPBRD_E_CANT_SET, redact content and credentials while preserving types, lengths, hashes, opaque identities, and lifecycle generations needed to reproduce its contract.
- For
CLIPBRD_E_CANT_SET, record format ID/name, handle kind, allocation flags, size, owner HWND, and last error. - For
CLIPBRD_E_CANT_SET, validate format-specific requirements such as movable global memory. - For
CLIPBRD_E_CANT_SET, publish multiple formats transactionally and note which earlier formats already succeeded.
Diagnostic sequence
- Capture
CLIPBRD_E_CANT_SETat the first native return before a wrapper maps it to a generic exception. - Identify the exact object, method, and lifecycle phase involved in publishing one clipboard format after OpenClipboard and EmptyClipboard.
- Record format ID/name, handle kind, allocation flags, size, owner HWND, and last error.
- Validate format-specific requirements such as movable global memory.
- Publish multiple formats transactionally and note which earlier formats already succeeded.
- Reproduce
CLIPBRD_E_CANT_SETwith one controlled input or state change, and verify that the correction changes the decisive evidence rather than merely hiding the result.
Recovery and retry
Correction. For CLIPBRD_E_CANT_SET, create a valid format-specific handle, repeat the complete clipboard transaction, and relinquish ownership only after successful SetClipboardData. Retry boundary. Retry after rebuilding the handle and reopening the clipboard; do not free a handle after successful ownership transfer. Before repeating the CLIPBRD_E_CANT_SET operation, close the clipboard on every path, determine whether EmptyClipboard changed ownership, and never free a handle successfully transferred to the system.
Practical scenario
An application passes a fixed GMEM_FIXED block for CF_UNICODETEXT; allocating movable global memory and leaving it owned by the system after success resolves publication. This isolates CLIPBRD_E_CANT_SET within Win32 clipboard ownership and data publication and provides a regression test for the stated correction.
Difference from related HRESULTs
DV_E_CLIPFORMAT is a COM FORMATETC validation result; CLIPBRD_E_CANT_SET comes from the Win32 clipboard publication sequence. For CLIPBRD_E_CANT_SET, keep those outcomes separate in exception mappings, telemetry dimensions, user messages, and automated retry policy.
Developer and administrator guidance
For CLIPBRD_E_CANT_SET, serialize the open-empty-publish-close transaction, use the documented handle type for each format, and retain delayed-rendering ownership until WM_RENDERFORMAT handling completes. Regression coverage for CLIPBRD_E_CANT_SET should include clipboard contention, owner-window destruction, invalid handle types, delayed rendering, empty data, multiple formats, and failure after ownership has changed.
Operational repair for CLIPBRD_E_CANT_SET must target the evidence-backed owner: identify the process holding or publishing the clipboard and reproduce without clipboard managers or remote-session redirection before changing system configuration. Retain before-and-after traces for CLIPBRD_E_CANT_SET so the change can be attributed and reversed.
References
- Microsoft: generic COM error codes — official Microsoft documentation relevant to
CLIPBRD_E_CANT_SET. - Microsoft: HRESULT values — official Microsoft documentation relevant to
CLIPBRD_E_CANT_SET. - Microsoft: EmptyClipboard — official Microsoft documentation relevant to
CLIPBRD_E_CANT_SET. - Microsoft: SetClipboardData — official Microsoft documentation relevant to
CLIPBRD_E_CANT_SET. - Microsoft: using the clipboard — official Microsoft documentation relevant to
CLIPBRD_E_CANT_SET.
Looking for a different code? Search another status or error code.