Clipboard

void PrintClipboardContents() {
    IDataObject* pDataObject = nullptr;
    HRESULT hr = OleGetClipboard(&pDataObject);
    if (SUCCEEDED(hr)) {
        FORMATETC fmtetc = { CF_UNICODETEXT, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
        if (OleIsCurrentClipboard(pDataObject)) {
            STGMEDIUM stgmedium;

            // Retrieve the data
            hr = pDataObject->GetData(&fmtetc, &stgmedium);
            if (SUCCEEDED(hr)) {
                wchar_t* data = static_cast<wchar_t*>(GlobalLock(stgmedium.hGlobal));
                if (data != nullptr) {
                    std::wcout << L"Clipboard Contents:" << std::endl;
                    std::wcout << data << std::endl;
                    GlobalUnlock(stgmedium.hGlobal);
                }
                ReleaseStgMedium(&stgmedium);
            }
        }
        pDataObject->Release();
    }
}

Write to Clipboard

Alternatively, you can use the clipboard API


References