elad-ep
elad-ep

Reputation: 383

using the clipboard in native c++ metro app

I'm looking for the interfaces to allow me to access the clipboard in native c++ metro app - similar to DataTransfer::Clipboard::SetContent in C#.

can someone please refer me to those interfaces and how can it be done using the WRL library?

Upvotes: 0

Views: 426

Answers (1)

Jeffrey Chen
Jeffrey Chen

Reputation: 4680

In WRL, you need to get the IClipboardStatics interface which contains the SetContent method.

#include <Windows.Foundation.h>
#include <Windows.ApplicationModel.DataTransfer.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>

using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::ApplicationModel::DataTransfer;

    // Initialize the Windows Runtime.
    RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);

    if (FAILED(initialize))
    {
        cout << "Failed to initialize";
    }

    ComPtr<IClipboardStatics> clipboard;

    HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_Clipboard).Get(), &clipboard);

    if (FAILED(hr))
    {
        cout << "failed to create a runtime instance";

        return 0;
    }

    ComPtr<IDataPackage> datapackage;

    // create a package and set the data
    // ...

    clipboard->SetContent(datapackage.Get());

Upvotes: 1

Related Questions