| Previous | Next |
| DV_E_DVTARGETDEVICE | DV_E_STATDATA |
DV_E_STGMEDIUM
Invalid STDGMEDIUM structure
DV_E_STGMEDIUM is HRESULT 2147745894 (0X80040066) from Winerror.h. AllStat describes it as “Invalid STDGMEDIUM structure.” The result normally appears while returning or accepting transferred data in an STGMEDIUM whose union member, tymed, or ownership is inconsistent. Its useful interpretation is precise: the STGMEDIUM transfer container is not valid for the exact provider, object, method, or lifecycle state that consumed it.
Preserve this result at the native boundary instead of flattening it into a generic exception. The symbol identifies the STGMEDIUM transfer container as the decisive part of the failed contract, but the owning layer may still be the application, Windows, a TAPI or media service provider, a remote switch, a device, or a COM data source. Correct handling starts by recording who produced the value and who rejected it.
Typical call path
- This result belongs to COM data transfer, clipboard, drag-and-drop, and OLE rendering.
- Associate this result with one concrete native method among IDataObject::GetData, GetDataHere, SetData, QueryGetData, FORMATETC negotiation, and ReleaseStgMedium.
- Before releasing objects after this result, retain provider identity, object generation, current state, requested transition, and the event sequence surrounding returning or accepting transferred data in an STGMEDIUM whose union member, tymed, or ownership is inconsistent.
When the application constructed the STGMEDIUM transfer container, it usually calls for caller-side validation. When enumeration or an event supplied it, it more often points to stale lifetime, provider replacement, device removal, configuration drift, or cross-session reuse. The ownership distinction for it prevents a broad repair from masking the real defect.
Root-cause hypotheses
- A wrapper can trigger it by converting an enumeration, identifier, duration, structure size, encoding, or ownership rule incorrectly.
- It can occur when the caller supplies a malformed, unsupported, stale, or out-of-scope STGMEDIUM transfer container.
- It can also indicate that the STGMEDIUM transfer container belonged to another address, call, device, provider generation, user session, or COM object.
- An asynchronous event can produce it when removal, disconnect, cancellation, reinitialization, or a state transition occurs after validation.
Choose among those branches only after comparing the failed STGMEDIUM transfer container with live capabilities or objects obtained from the same provider generation. A well-formed value can still be invalid because its scope, owner, state, or lifetime no longer matches the operation.
Diagnostic record
- Record it, 0X80040066, the native method, operation ID, elapsed time, process and thread IDs, application build, architecture, and COM apartment.
- capture tymed value, active union member, handle or interface validity, pUnkForRelease, allocation method, ownership transfer, and ReleaseStgMedium path.
- Keep provider version, address/call/phone/terminal identities, current state, requested state, object generation, and the first lower-level error that preceded it.
- Redact clipboard payloads and document contents from it telemetry while retaining lengths, types, hashes, ranges, capability flags, and opaque correlation identifiers.
A useful incident can answer whether the STGMEDIUM transfer container came from configuration, enumeration, user input, cached state, or a provider callback. The result record should also show whether the operation succeeds with a newly enumerated object or freshly validated value.
Investigation order
- Capture it at the first native return and identify the exact method used for returning or accepting transferred data in an STGMEDIUM whose union member, tymed, or ownership is inconsistent.
- Enumerate current provider capabilities or objects and compare them with the STGMEDIUM transfer container rejected by it.
- Validate the STGMEDIUM transfer container without silently correcting it; check type, size, range, encoding, identifier scope, ownership, and lifetime as applicable.
- Reconstruct the event timeline before it to find removal, disconnect, cancellation, service restart, provider reinitialization, or another state transition.
- Reproduce it with one object and one operation, then vary only the suspected field or state while tracking partial output and side effects.
Recovery conditions
The evidence-based correction for it is to pair the union member with the declared tymed, use a valid allocated resource, and define one unambiguous release owner. After it follows a provider, device, service, or configuration change, obtain a fresh object because an old interface or opaque identifier may remain invalid after recovery.
Treat it retry policy as part of the owning operation rather than a property of the hexadecimal value alone. User-visible handling of it should describe the actionable condition—invalid data, wrong state, missing resource, unavailable service, or policy refusal—rather than displaying only the HRESULT.
Failure example
For example, a source labels an IStream pointer as TYMED_HGLOBAL and the receiver rejects it; correcting the tymed and ownership fixes transfer The application should log the failed STGMEDIUM transfer container, provider and object generation, native method, and state-changing event, then verify recovery with a newly obtained object instead of reusing the instance that returned it.
Nearby constants
DV_E_FORMATETC concerns the requested format; it concerns the returned or supplied storage medium Keep that distinction when building dashboards and exception mappings for it; otherwise input defects, lifecycle races, capacity limits, service outages, and final call outcomes collapse into one misleading category.
Implementation guidance
Code that handles it should scope provider-defined identifiers to their creating session, serialize state transitions, validate caller-owned structures at the native boundary, and keep cleanup safe after partial initialization. Tests for it should cover cancellation, provider restart, device removal, stale cached objects, capability changes, wrong user context, and both successful and failed recovery.
Operational repair for it should target only the component identified by evidence: the Telephony service, service provider, COM server, device, configuration record, application package, or remote system. Copying arbitrary DLLs or broadly deleting registration data can create additional failures without correcting the original STGMEDIUM transfer container.
References
- Microsoft: generic COM error codes — official Microsoft documentation used to interpret it.
- Microsoft: STGMEDIUM structure
- Microsoft: IDataObject
- Microsoft: ReleaseStgMedium
Looking for a different code? Search another status or error code.