Hi,

I am trying to copy/paste a structure to the clipboard the copy appears to work but the paste errors with "COMException crossed a native/managed boundary ErrorCode = -2147467259". The error occurs on the highlighted code line below. Is it possible to put a structure on the clipboard? If so how?

Thanks, Jeff

Public Structure Obstacle
        Dim Type As obs
        Dim Deleted As Boolean
        Dim Wip As Dact
        Dim Angle As Integer
        Dim Length As Single
        Dim Width As Single
        Dim Heigth As Single
        Dim Thickness As Single
        Dim Diameter As Single
        Dim Spread As Single
        Dim Wings As Single
        Dim Bars As Integer
        Dim Pieces As Integer
        Dim Ascending As Boolean
End Structure


Private Sub CopyToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripButton.Click
        If ObsSelected > 0 Then
            Dim odo As New DataObject
            odo.SetData("Obstacle", False, Obstacles(ObsSelected))
            Clipboard.SetDataObject(odo)
        End If
    End Sub

Private Sub PasteToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripButton.Click
        Dim odo As DataObject = Clipboard.GetDataObject()
        If odo.GetDataPresent("Obstacle") Then
            Obstacles(newObs()) = DirectCast(odo.GetData("Obstacle", False, Obstacle))

System.Runtime.InteropServices.COMException crossed a native/managed boundary
ErrorCode=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=mscorlib
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
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:

Hi,

I am trying to copy/paste a structure to the clipboard the copy appears to work but the paste errors with "COMException crossed a native/managed boundary ErrorCode = -2147467259". The error occurs on the highlighted code line below. Is it possible to put a structure on the clipboard? If so how?

Thanks, Jeff

Public Structure Obstacle
        Dim Type As obs
        Dim Deleted As Boolean
        Dim Wip As Dact
        Dim Angle As Integer
        Dim Length As Single
        Dim Width As Single
        Dim Heigth As Single
        Dim Thickness As Single
        Dim Diameter As Single
        Dim Spread As Single
        Dim Wings As Single
        Dim Bars As Integer
        Dim Pieces As Integer
        Dim Ascending As Boolean
End Structure


Private Sub CopyToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripButton.Click
        If ObsSelected > 0 Then
            Dim odo As New DataObject
            odo.SetData("Obstacle", False, Obstacles(ObsSelected))
            Clipboard.SetDataObject(odo)
        End If
    End Sub

Private Sub PasteToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripButton.Click
        Dim odo As DataObject = Clipboard.GetDataObject()
        If odo.GetDataPresent("Obstacle") Then
            Obstacles(newObs()) = DirectCast(odo.GetData("Obstacle", False, Obstacle))

System.Runtime.InteropServices.COMException crossed a native/managed boundary
ErrorCode=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=mscorlib
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
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:

Solution a structure needs to be serializable to cut/copy/paste.

<Serializable()> Public Structure Obstacle
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.