To put data onto the clipboard, first construct a
CClipboard
object and prepare it for writing using the
NewForWritingLC()
static member function. The following code
fragment shows this.
CClipboard* cb = CClipboard::NewForWritingLC(fsSession);
The function needs a file server session.
The file associated with the clipboard's store may or may not exist.
If it already exists, any existing content is discarded; if the file does not
exist, it is created. In either event, NewForWritingLC()
results
in an empty clipboard.
Once the CClipboard
object has been created, data is
stored into the clipboard 's store. Both the store (CStreamStore
)
and the stream dictionary (CStreamDictionary
), which the example
needs to access, are encapsulated by CClipboard
. The class,
therefore, provides the Store()
and
StreamDictionary()
member functions to return suitable
references.
In this example, the data to be put into the clipboard's store is a
single object item
.
RStoreWriteStream stream;
TStreamId stid = stream.CreateLC(cb->Store());
stream << *item;
stream.CommitL();
(cb->StreamDictionary()).AssignL(KExampleClipUid,stid);
CleanupStack::PopAndDestroy(); // stream
cb->CommitL();
CleanupStack::PopAndDestroy(); // cb
The steps are as follows:
A new stream is prepared for writing using the
CreateLC()
member function of RStoreWriteStream
; the
CClipboard
's store is to contain the new stream and so
cb->Store()
is passed as a parameter to
CreateLC()
.
The item
object is externalised.
The stream is committed.
The resulting streamid and the UID, which identifies the data
type, i.e. stid
and KExampleClipUid
, respectively,
are placed in the stream dictionary using the stream dictionary's
AssignL()
member function.
The process concludes by calling CClipboard
's
CommitL()
member function to store the dictionary store as the
root stream of the store and to commit all changes to the store.
Deleting the CClipboard
object causes the file
associated with the clipboard's store to be closed, allowing other applications
to access it.