locked
Clipboard WinRT originate error 0x8004006A DV_E_CLIPFORMAT

    Question

  • I am attempting to read content that was copied from another application into my windows store application. To clarify the steps:

    1. Open my windows store application
    2. Drop back to the desktop and open another application (wordpad, notepad, browser)
    3. Select and copy (Ctrl + V) text
    4. Assuming my app is still active in the background the following code runs in response to Clipboard ContentChanged event

    I have run the following code inside and outside of the UI thread with the same result.    

     DataPackageView content = Clipboard.GetContent();
     StringBuilder sb = new StringBuilder();                    
    
     try
     {
        if(content.Contains(StandardDataFormats.Text)) 
        {
           string text = await content.GetTextAsync();
           sb.Append(text);
        }
        // other content types are here but left out ...
     }
     catch(Exception ex)
     {
        sb.Append("Exception: " + ex.Message);
     }


    Inside "content.Contains" above I get the following trace printout:

    First-chance exception at 0x768B2C1A (KernelBase.dll) in FoliaWrt.exe: 0x40080201: WinRT originate error (parameters: 0x8004006A, 0x0000001A, 0x05B4F1D4).

    The first parameter (0x8004006A) is DV_E_CLIPFORMAT "Invalid clipboard format" 

    I do not get an exception in the catch. When running in VS the error prints and I can paste the text correctly, when running outside of VS I cannot paste the copied text. I have copied from various sources with the same result. When I copy within my application I do not get this error.

    I know the Clipboard is not an "agile" object and should be run in a STA thread. I thought the UI thread counted as STA. 

    Any suggestions on preventing this issue?

     
    Tuesday, May 06, 2014 3:36 PM

Answers

  • Matt - I ran this code just fine with no problems. My code was set up in the App.xaml.cs page:

    public App()
    {
       this.InitializeComponent();
       this.Suspending += OnSuspending;
       Windows.ApplicationModel.DataTransfer.Clipboard.ContentChanged += Clipboard_ContentChanged;
    }

    async void Clipboard_ContentChanged(object sender, object e)
    {
      DataPackageView content = Clipboard.GetContent();
      try
      {
        if (content.Contains(StandardDataFormats.Text))
        {
          string text = await content.GetTextAsync();
          Debug.WriteLine(text);
        }
         // other content types are here but left out ...
      }
      catch (Exception ex)
      {
        Debug.WriteLine("Exception: " + ex.Message);
      }
    }

    
    

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, May 07, 2014 1:14 PM
    Moderator
  • Thanks Matt, 

    Unfortunately, running the Clipboard sample and/or a clean test project I do not see the issue either. My app uses 3 projects, the primary windows store C#/Xaml project, a C++/CX "bridge" project and a native C++ project. I have moved my code into various locations (on UI thread and not, all inside App.xaml.cs, before any other system initialization, removing all initialization and just clipboard), all with the same result. Running outside of the debugger the app crashes when a copy occurs from another application. My next debugging attempt is to move the clipboard retrieval code into the C++/CX project, it might shed more light.

    Thanks for taking a pass at it.

    Matt



    Wednesday, May 07, 2014 3:42 PM

All replies

  • Matt - I ran this code just fine with no problems. My code was set up in the App.xaml.cs page:

    public App()
    {
       this.InitializeComponent();
       this.Suspending += OnSuspending;
       Windows.ApplicationModel.DataTransfer.Clipboard.ContentChanged += Clipboard_ContentChanged;
    }

    async void Clipboard_ContentChanged(object sender, object e)
    {
      DataPackageView content = Clipboard.GetContent();
      try
      {
        if (content.Contains(StandardDataFormats.Text))
        {
          string text = await content.GetTextAsync();
          Debug.WriteLine(text);
        }
         // other content types are here but left out ...
      }
      catch (Exception ex)
      {
        Debug.WriteLine("Exception: " + ex.Message);
      }
    }

    
    

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, May 07, 2014 1:14 PM
    Moderator
  • Thanks Matt, 

    Unfortunately, running the Clipboard sample and/or a clean test project I do not see the issue either. My app uses 3 projects, the primary windows store C#/Xaml project, a C++/CX "bridge" project and a native C++ project. I have moved my code into various locations (on UI thread and not, all inside App.xaml.cs, before any other system initialization, removing all initialization and just clipboard), all with the same result. Running outside of the debugger the app crashes when a copy occurs from another application. My next debugging attempt is to move the clipboard retrieval code into the C++/CX project, it might shed more light.

    Thanks for taking a pass at it.

    Matt



    Wednesday, May 07, 2014 3:42 PM
  • Assuming my app is still active in the background the following code runs in response to Clipboard ContentChanged event

    Clipboard access is blocked to applications that are not in the foreground. Further, when apps are not visible they generally are suspended, so you won't see the change until the user switches to your app. Once you become the foreground app you can access the clipboard.

    Friday, May 23, 2014 9:12 PM