Who is an owner of data rendered by IDataObject::GetData?

infinityeternity 21 Reputation points
2021-01-20T09:48:50.053+00:00

Documentation wording on that matter is somewhat confusing. First it states:

The caller then assumes responsibility for releasing the STGMEDIUM structure

then in parameters description:

A pointer to the STGMEDIUM structure that indicates the storage medium containing the returned data through its tymed member, and the responsibility for releasing the medium through the value of its pUnkForRelease member.

I can't draw a reliable conclusion that I'm an owner from that and can modify the data without copying it. Obligation to release through pUnkForRelease makes returning the medium handle (e.g. HBITMAP or whatever) from a function impossible. Thus my ownership of the data is restricted, if it exists at all.

I don't want to make a needless copy. I think an implementer of IDataObject have to make a copy of data even if it will be identical to the source data, because nothing says that a user isn't allowed to modify it. Then why should I copy it again? Am I an owner of it?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,429 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Igor Tandetnik 1,106 Reputation points
    2021-01-20T14:40:20.767+00:00

    The documentation for ReleaseStgMedium provides the details. In short, if punkForRelease is not null, then the data provider still owns the data; if punkForRelease is null, then the caller owns the data. The documentation spells out the correct steps to dispose of the data in either case.

    0 comments No comments