locked
SetDataObject troubles RRS feed

  • Question

  • Hi,

    I have this code:

    private void button1_Click(object sender, System.EventArgs e)
    {
        StringBuilder str=new StringBuilder("Hello world");

        System.Windows.Forms.Clipboard.SetDataObject(str.ToString(), false);         
     }

    On the same PC, when this code is build with VS2005 and .NET1.1 when button1 is clicked, the string is copied to the Clipboard and I can paste it into Excel, Word or Notepad
    When it is built with VC# express and .NET 2.0 or .NET 3.5 when the button is clicked, the string is presumably copied to the Clipboard, but when I try to paste into Excel or Word, the program crashes and Excel coplains that "Excel cannot paste the data" .

    This is the crash information:
    ////////////////////////////////////////////////////////////////////////////////////////

    System.Runtime.InteropServices.COMException crossed a native/managed boundary

      Message="Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))"

      Source="mscorlib"

      ErrorCode=-2147221404

      StackTrace:

           at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

           at System.Windows.Forms.DataObject.GetDataIntoOleStructs(FORMATETC& formatetc, STGMEDIUM& medium)

           at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium)

           at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium)

      InnerException:


    /////////////////////////////////////////////


    The problem is fixed if I pass true for a second parameter instead of false.



    My questions are:

    1. Whay does this happen with .NET 2.0 and not with .NET 1.1

    2. Is this my problem (i.e. invalid arguments passed to SetDataObject, although I dont see how) or .NET compatibility problem or what?


    Thank you



    zsavovAThotmail.com








    Monday, April 14, 2008 3:00 AM

Answers

  • Hi,

     

    I built an application in the way as you said and compile it on .NET Framework 2.0 and 3.5. However, I didn’t get the error which you described. Is this a onetime crash or a constantly occurred error?

     

    If you are sure that it is a bug. Please describe it carefully so that we can reproduce the scenario.

     

    Regards,

    Jacob

    Thursday, April 17, 2008 9:31 AM

All replies

  • Hi,

    I have this code in a simple WindowsForm:

    private void button1_Click(object sender, System.EventArgs e)
    {
        StringBuilder str=new StringBuilder("Hello world");

        System.Windows.Forms.Clipboard.SetDataObject(str.ToString(), false);         
     }

    When this code is build with VS2005 and .NET1.1 when button1 is clicked, the string is copied to the Clipboard and I can paste it into Excel, Word or Notepad
    When it is built with VC# express and .NET 2.0 or .NET 3.5 when the button is clicked, the string is presumably copied to the Clipboard, but when I try to paste into Excel or Word, the program crashes and Excel complains that "Excel cannot paste the data" .

    Whay does this happen with .NET 2.0 and not with .NET 1.1


    Thank you



    zsavov@hotmail.com


    Tuesday, April 15, 2008 12:07 AM
  • Hi,

     

    I built an application in the way as you said and compile it on .NET Framework 2.0 and 3.5. However, I didn’t get the error which you described. Is this a onetime crash or a constantly occurred error?

     

    If you are sure that it is a bug. Please describe it carefully so that we can reproduce the scenario.

     

    Regards,

    Jacob

    Thursday, April 17, 2008 9:31 AM

  • Hi,

    No, it happens all the time.
    This is the exception information


    ////////////////////////////////////////////////////////////////////////////////////////

    System.Runtime.InteropServices.COMException crossed a native/managed boundary

      Message="Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))"

      Source="mscorlib"

      ErrorCode=-2147221404

      StackTrace:

           at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

           at System.Windows.Forms.DataObject.GetDataIntoOleStructs(FORMATETC& formatetc, STGMEDIUM& medium)

           at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC& formatetc, STGMEDIUM& medium)

           at System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& formatetc, STGMEDIUM& medium)

      InnerException:


    /////////////////////////////////////////////


    Thursday, April 24, 2008 3:34 AM
  •  Here's a solution that has worked for me.
    1. I take note of the TagPrefix in this registry.

    <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false"  CodeFile="Default3.aspx.vb" Inherits="Content_Default3" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    2. When I need a control from the AJAX Control ToolKit, I hand code the entry in Note Pad and paste it into the page.

    Example:
    <cc1:AnimationExtender id="OpenAnimation" runat="server" TargetControlID="btnInfo"> </cc1:AnimationExtender>


    Eugene Williams
    Saturday, January 31, 2009 10:31 AM