Задайте вопросЗадайте вопрос
 

ОтвеченоClibpoard bug in VB 2005 or DotNetFramework 2.0

  • 9 января 2006 г. 17:03Ted Carron Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    I am writing code to transfer text to the clipboard in a number of formats in VB2005. I already have code which does this fine under VB.Net 2003

    Everything is fine until the text data which I have written onto the clipboard via a DataObject is pasted into Excel or Word,  When you do this you get the following exception.

    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)

    You do not get the exception pasting into notepad

    You do not get the exception if you put the text strait onto the clipboard without a dataobject. i.e. by clipboard.SetText(...)  This is not a solution to my problem however because I want to copy a bespoke version of the data onto the clipboard as well as the text version.

    The exception is thrown weather or not the data is represented in the data object as more than one form or not.

    You can get the same exception when pasting into the same VB program if the paste is done by 

    Dataobject.SetText(..)

    and read out of the data object by

    Dataobject.GetData(DataFormats.Text)

    If you change the set text to

    Dataobject.SetData(DataFormats.Text)

    the exception disappears!

    You do not get this problem under VB.Net 2003

    I can find no reference to this problem on MSDN has anybody else encountered this problem or seen it on MSDN?

    Thanks in advance to anyone who can help.

Ответы

Все ответы