none
converting code from C# to VB 2010

    Question

  • i'm trying convert 1 C# code: https://www.codeproject.com/Articles/12135/Inserting-images-into-a-RichTextBox-control-the-OL

    to VB2010 using: http://converter.telerik.com/

    and the result was:

    Imports System.ComponentModel
    Imports System.Collections
    Imports System.Diagnostics
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    
    Namespace MyExtRichTextBox
    #Region "OLE definitions"
        ' STGM
        <Flags(), ComVisible(False)> _
        Public Enum STGM As Integer
            STGM_DIRECT = &H0
            STGM_TRANSACTED = &H10000
            STGM_SIMPLE = &H8000000
            STGM_READ = &H0
            STGM_WRITE = &H1
            STGM_READWRITE = &H2
            STGM_SHARE_DENY_NONE = &H40
            STGM_SHARE_DENY_READ = &H30
            STGM_SHARE_DENY_WRITE = &H20
            STGM_SHARE_EXCLUSIVE = &H10
            STGM_PRIORITY = &H40000
            STGM_DELETEONRELEASE = &H4000000
            STGM_NOSCRATCH = &H100000
            STGM_CREATE = &H1000
            STGM_CONVERT = &H20000
            STGM_FAILIFTHERE = &H0
            STGM_NOSNAPSHOT = &H200000
        End Enum
    
        ' DVASPECT
        <Flags(), ComVisible(False)> _
        Public Enum DVASPECT As Integer
            DVASPECT_CONTENT = 1
            DVASPECT_THUMBNAIL = 2
            DVASPECT_ICON = 4
            DVASPECT_DOCPRINT = 8
            DVASPECT_OPAQUE = 16
            DVASPECT_TRANSPARENT = 32
        End Enum
    
        ' CLIPFORMAT
        <ComVisible(False)> _
        Public Enum CLIPFORMAT As Integer
            CF_TEXT = 1
            CF_BITMAP = 2
            CF_METAFILEPICT = 3
            CF_SYLK = 4
            CF_DIF = 5
            CF_TIFF = 6
            CF_OEMTEXT = 7
            CF_DIB = 8
            CF_PALETTE = 9
            CF_PENDATA = 10
            CF_RIFF = 11
            CF_WAVE = 12
            CF_UNICODETEXT = 13
            CF_ENHMETAFILE = 14
            CF_HDROP = 15
            CF_LOCALE = 16
            CF_MAX = 17
            CF_OWNERDISPLAY = &H80
            CF_DSPTEXT = &H81
            CF_DSPBITMAP = &H82
            CF_DSPMETAFILEPICT = &H83
            CF_DSPENHMETAFILE = &H8E
        End Enum
    
        ' Object flags
        <Flags(), ComVisible(False)> _
        Public Enum REOOBJECTFLAGS As UInteger
            REO_NULL = &H0
            ' No flags
            REO_READWRITEMASK = &H3F
            ' Mask out RO bits
            REO_DONTNEEDPALETTE = &H20
            ' Object doesn't need palette
            REO_BLANK = &H10
            ' Object is blank
            REO_DYNAMICSIZE = &H8
            ' Object defines size always
            REO_INVERTEDSELECT = &H4
            ' Object drawn all inverted if sel
            REO_BELOWBASELINE = &H2
            ' Object sits below the baseline
            REO_RESIZABLE = &H1
            ' Object may be resized
            REO_LINK = &H80000000UI
            ' Object is a link (RO)
            REO_STATIC = &H40000000
            ' Object is static (RO)
            REO_SELECTED = &H8000000
            ' Object selected (RO)
            REO_OPEN = &H4000000
            ' Object open in its server (RO)
            REO_INPLACEACTIVE = &H2000000
            ' Object in place active (RO)
            REO_HILITED = &H1000000
            ' Object is to be hilited (RO)
            REO_LINKAVAILABLE = &H800000
            ' Link believed available (RO)
            REO_GETMETAFILE = &H400000
            ' Object requires metafile (RO)
        End Enum
    
        ' OLERENDER
        <ComVisible(False)> _
        Public Enum OLERENDER As Integer
            OLERENDER_NONE = 0
            OLERENDER_DRAW = 1
            OLERENDER_FORMAT = 2
            OLERENDER_ASIS = 3
        End Enum
    
        ' TYMED
        <Flags(), ComVisible(False)> _
        Public Enum TYMED As Integer
            TYMED_NULL = 0
            TYMED_HGLOBAL = 1
            TYMED_FILE = 2
            TYMED_ISTREAM = 4
            TYMED_ISTORAGE = 8
            TYMED_GDI = 16
            TYMED_MFPICT = 32
            TYMED_ENHMF = 64
        End Enum
    
        <StructLayout(LayoutKind.Sequential), ComVisible(False)> _
        Public Structure FORMATETC
            Public cfFormat As CLIPFORMAT
            Public ptd As IntPtr
            Public dwAspect As DVASPECT
            Public lindex As Integer
            Public tymed As TYMED
        End Structure
    
        <StructLayout(LayoutKind.Sequential), ComVisible(False)> _
        Public Structure STGMEDIUM
            '[MarshalAs(UnmanagedType.I4)]
            Public tymed As Integer
            Public unionmember As IntPtr
            Public pUnkForRelease As IntPtr
        End Structure
    
        <ComVisible(True), ComImport(), Guid("00000103-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IEnumFORMATETC
            <PreserveSig()> _
            Function [Next](<[In](), MarshalAs(UnmanagedType.U4)> celt As Integer, <Out()> rgelt As FORMATETC, <[In](), Out(), MarshalAs(UnmanagedType.LPArray)> pceltFetched As Integer()) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Skip(<[In](), MarshalAs(UnmanagedType.U4)> celt As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Reset() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Clone(<Out(), MarshalAs(UnmanagedType.LPArray)> ppenum As IEnumFORMATETC()) As <MarshalAs(UnmanagedType.I4)> Integer
        End Interface
    
        <ComVisible(True), StructLayout(LayoutKind.Sequential)> _
        Public Class COMRECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
    
            Public Sub New()
            End Sub
    
            Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)
                Me.left = left
                Me.top = top
                Me.right = right
                Me.bottom = bottom
            End Sub
    
            Public Shared Function FromXYWH(x As Integer, y As Integer, width As Integer, height As Integer) As COMRECT
                Return New COMRECT(x, y, x + width, y + height)
            End Function
        End Class
    
        Public Enum GETOBJECTOPTIONS
            REO_GETOBJ_NO_INTERFACES = &H0
            REO_GETOBJ_POLEOBJ = &H1
            REO_GETOBJ_PSTG = &H2
            REO_GETOBJ_POLESITE = &H4
            REO_GETOBJ_ALL_INTERFACES = &H7
        End Enum
    
        Public Enum GETCLIPBOARDDATAFLAGS
            RECO_PASTE = 0
            RECO_DROP = 1
            RECO_COPY = 2
            RECO_CUT = 3
            RECO_DRAG = 4
        End Enum
    
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure CHARRANGE
            Public cpMin As Integer
            Public cpMax As Integer
        End Structure
    
        <StructLayout(LayoutKind.Sequential)> _
        Public Class REOBJECT
            Public cbStruct As Integer = Marshal.SizeOf(GetType(REOBJECT))
            ' Size of structure
            Public cp As Integer
            ' Character position of object
            Public clsid As Guid
            ' Class ID of object
            Public poleobj As IntPtr
            ' OLE object interface
            Public pstg As IStorage
            ' Associated storage interface
            Public polesite As IOleClientSite
            ' Associated client site interface
            Public sizel As Size
            ' Size of object (may be 0,0)
            Public dvAspect As UInteger
            ' Display aspect to use
            Public dwFlags As UInteger
            ' Object status flags
            Public dwUser As UInteger
            ' Dword for user's use
        End Class
    
        <ComVisible(True), Guid("0000010F-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IAdviseSink
    
            'C#r: UNDONE (Field in interface) public static readonly    Guid iid;
            Sub OnDataChange(<[In]()> pFormatetc As FORMATETC, <[In]()> pStgmed As STGMEDIUM)
    
            Sub OnViewChange(<[In](), MarshalAs(UnmanagedType.U4)> dwAspect As Integer, <[In](), MarshalAs(UnmanagedType.I4)> lindex As Integer)
    
            Sub OnRename(<[In](), MarshalAs(UnmanagedType.[Interface])> pmk As Object)
    
            Sub OnSave()
    
    
            Sub OnClose()
        End Interface
    
        <ComVisible(False), StructLayout(LayoutKind.Sequential)> _
        Public NotInheritable Class STATDATA
    
            <MarshalAs(UnmanagedType.U4)> _
            Public advf As Integer
            <MarshalAs(UnmanagedType.U4)> _
            Public dwConnection As Integer
    
        End Class
    
        <ComVisible(False), StructLayout(LayoutKind.Sequential)> _
        Public NotInheritable Class tagOLEVERB
            <MarshalAs(UnmanagedType.I4)> _
            Public lVerb As Integer
    
            <MarshalAs(UnmanagedType.LPWStr)> _
            Public lpszVerbName As [String]
    
            <MarshalAs(UnmanagedType.U4)> _
            Public fuFlags As Integer
    
            <MarshalAs(UnmanagedType.U4)> _
            Public grfAttribs As Integer
    
        End Class
    
        <ComVisible(True), ComImport(), Guid("00000104-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IEnumOLEVERB
    
            <PreserveSig()> _
            Function [Next](<MarshalAs(UnmanagedType.U4)> celt As Integer, <Out()> rgelt As tagOLEVERB, <Out(), MarshalAs(UnmanagedType.LPArray)> pceltFetched As Integer()) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Skip(<[In](), MarshalAs(UnmanagedType.U4)> celt As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            Sub Reset()
    
    
            Sub Clone(ByRef ppenum As IEnumOLEVERB)
    
    
        End Interface
    
        <ComVisible(True), Guid("00000105-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IEnumSTATDATA
    
            'C#r: UNDONE (Field in interface) public static readonly    Guid iid;
    
            Sub [Next](<[In](), MarshalAs(UnmanagedType.U4)> celt As Integer, <Out()> rgelt As STATDATA, <Out(), MarshalAs(UnmanagedType.LPArray)> pceltFetched As Integer())
    
    
            Sub Skip(<[In](), MarshalAs(UnmanagedType.U4)> celt As Integer)
    
    
            Sub Reset()
    
    
            Sub Clone(<Out(), MarshalAs(UnmanagedType.LPArray)> ppenum As IEnumSTATDATA())
    
    
        End Interface
    
        <ComVisible(True), Guid("0000011B-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IOleContainer
    
    
            Sub ParseDisplayName(<[In](), MarshalAs(UnmanagedType.[Interface])> pbc As Object, <[In](), MarshalAs(UnmanagedType.BStr)> pszDisplayName As String, <Out(), MarshalAs(UnmanagedType.LPArray)> pchEaten As Integer(), <Out(), MarshalAs(UnmanagedType.LPArray)> ppmkOut As Object())
    
    
            Sub EnumObjects(<[In](), MarshalAs(UnmanagedType.U4)> grfFlags As Integer, <Out(), MarshalAs(UnmanagedType.LPArray)> ppenum As Object())
    
    
            Sub LockContainer(<[In](), MarshalAs(UnmanagedType.I4)> fLock As Integer)
        End Interface
    
        <ComVisible(True), ComImport(), Guid("0000010E-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IDataObject
            <PreserveSig()> _
            Function GetData(ByRef a As FORMATETC, ByRef b As STGMEDIUM) As UInteger
    
            <PreserveSig()> _
            Function GetDataHere(ByRef pFormatetc As FORMATETC, ByRef pMedium As STGMEDIUM) As UInteger
    
            <PreserveSig()> _
            Function QueryGetData(ByRef pFormatetc As FORMATETC) As UInteger
    
            <PreserveSig()> _
            Function GetCanonicalFormatEtc(ByRef pformatectIn As FORMATETC, ByRef pformatetcOut As FORMATETC) As UInteger
    
            <PreserveSig()> _
            Function SetData(ByRef pFormatectIn As FORMATETC, ByRef pmedium As STGMEDIUM, <[In](), MarshalAs(UnmanagedType.Bool)> fRelease As Boolean) As UInteger
    
            <PreserveSig()> _
            Function EnumFormatEtc(dwDirection As UInteger, penum As IEnumFORMATETC) As UInteger
    
            <PreserveSig()> _
            Function DAdvise(ByRef pFormatetc As FORMATETC, advf As Integer, <[In](), MarshalAs(UnmanagedType.[Interface])> pAdvSink As IAdviseSink, ByRef pdwConnection As UInteger) As UInteger
    
            <PreserveSig()> _
            Function DUnadvise(dwConnection As UInteger) As UInteger
    
            <PreserveSig()> _
            Function EnumDAdvise(<Out(), MarshalAs(UnmanagedType.[Interface])> ByRef ppenumAdvise As IEnumSTATDATA) As UInteger
        End Interface
    
        <ComVisible(True), Guid("00000118-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IOleClientSite
    
            <PreserveSig()> _
            Function SaveObject() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetMoniker(<[In](), MarshalAs(UnmanagedType.U4)> dwAssign As Integer, <[In](), MarshalAs(UnmanagedType.U4)> dwWhichMoniker As Integer, <Out(), MarshalAs(UnmanagedType.[Interface])> ByRef ppmk As Object) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetContainer(<MarshalAs(UnmanagedType.[Interface])> ByRef container As IOleContainer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function ShowObject() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function OnShowWindow(<[In](), MarshalAs(UnmanagedType.I4)> fShow As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function RequestNewObjectLayout() As <MarshalAs(UnmanagedType.I4)> Integer
        End Interface
    
        <ComVisible(False), StructLayout(LayoutKind.Sequential)> _
        Public NotInheritable Class tagLOGPALETTE
            'leftover(offset=0, palVersion)
            <MarshalAs(UnmanagedType.U2)> _
            Public palVersion As Short
    
            'leftover(offset=2, palNumEntries)
            <MarshalAs(UnmanagedType.U2)> _
            Public palNumEntries As Short
    
            ' UNMAPPABLE: palPalEntry: Cannot be used as a structure field.
            '   /** @com.structmap(UNMAPPABLE palPalEntry) */
            '  public UNMAPPABLE palPalEntry;
        End Class
    
        <ComVisible(True), ComImport(), Guid("00000112-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IOleObject
    
            <PreserveSig()> _
            Function SetClientSite(<[In](), MarshalAs(UnmanagedType.[Interface])> pClientSite As IOleClientSite) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetClientSite(ByRef site As IOleClientSite) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetHostNames(<[In](), MarshalAs(UnmanagedType.LPWStr)> szContainerApp As String, <[In](), MarshalAs(UnmanagedType.LPWStr)> szContainerObj As String) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Close(<[In](), MarshalAs(UnmanagedType.I4)> dwSaveOption As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetMoniker(<[In](), MarshalAs(UnmanagedType.U4)> dwWhichMoniker As Integer, <[In](), MarshalAs(UnmanagedType.[Interface])> pmk As Object) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetMoniker(<[In](), MarshalAs(UnmanagedType.U4)> dwAssign As Integer, <[In](), MarshalAs(UnmanagedType.U4)> dwWhichMoniker As Integer, ByRef moniker As Object) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function InitFromData(<[In](), MarshalAs(UnmanagedType.[Interface])> pDataObject As IDataObject, <[In](), MarshalAs(UnmanagedType.I4)> fCreation As Integer, <[In](), MarshalAs(UnmanagedType.U4)> dwReserved As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            Function GetClipboardData(<[In](), MarshalAs(UnmanagedType.U4)> dwReserved As Integer, ByRef data As IDataObject) As Integer
    
            <PreserveSig()> _
            Function DoVerb(<[In](), MarshalAs(UnmanagedType.I4)> iVerb As Integer, <[In]()> lpmsg As IntPtr, <[In](), MarshalAs(UnmanagedType.[Interface])> pActiveSite As IOleClientSite, <[In](), MarshalAs(UnmanagedType.I4)> lindex As Integer, <[In]()> hwndParent As IntPtr, <[In]()> lprcPosRect As COMRECT) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function EnumVerbs(ByRef e As IEnumOLEVERB) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Update() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function IsUpToDate() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetUserClassID(<[In](), Out()> ByRef pClsid As Guid) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetUserType(<[In](), MarshalAs(UnmanagedType.U4)> dwFormOfType As Integer, <Out(), MarshalAs(UnmanagedType.LPWStr)> ByRef userType As String) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetExtent(<[In](), MarshalAs(UnmanagedType.U4)> dwDrawAspect As Integer, <[In]()> pSizel As Size) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetExtent(<[In](), MarshalAs(UnmanagedType.U4)> dwDrawAspect As Integer, <Out()> pSizel As Size) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Advise(<[In](), MarshalAs(UnmanagedType.[Interface])> pAdvSink As IAdviseSink, ByRef cookie As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function Unadvise(<[In](), MarshalAs(UnmanagedType.U4)> dwConnection As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function EnumAdvise(ByRef e As IEnumSTATDATA) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetMiscStatus(<[In](), MarshalAs(UnmanagedType.U4)> dwAspect As Integer, ByRef misc As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetColorScheme(<[In]()> pLogpal As tagLOGPALETTE) As <MarshalAs(UnmanagedType.I4)> Integer
        End Interface
    
        <ComImport()> _
        <Guid("0000000d-0000-0000-C000-000000000046")> _
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IEnumSTATSTG
            ' The user needs to allocate an STATSTG array whose size is celt.
            <PreserveSig()> _
            Function [Next](celt As UInteger, <MarshalAs(UnmanagedType.LPArray), Out()> rgelt As STATSTG(), ByRef pceltFetched As UInteger) As UInteger
    
            Sub Skip(celt As UInteger)
    
            Sub Reset()
    
            Function Clone() As <MarshalAs(UnmanagedType.[Interface])> IEnumSTATSTG
        End Interface
    
        <ComImport()> _
        <Guid("0000000b-0000-0000-C000-000000000046")> _
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IStorage
            ' [string][in] 
            ' [in] 
            ' [in] 
            ' [in] 
            ' [out] 
            Function CreateStream(pwcsName As String, grfMode As UInteger, reserved1 As UInteger, reserved2 As UInteger, ByRef ppstm As IStream) As Integer
    
            ' [string][in] 
            ' [unique][in] 
            ' [in] 
            ' [in] 
            ' [out] 
            Function OpenStream(pwcsName As String, reserved1 As IntPtr, grfMode As UInteger, reserved2 As UInteger, ByRef ppstm As IStream) As Integer
    
            ' [string][in] 
            ' [in] 
            ' [in] 
            ' [in] 
            ' [out] 
            Function CreateStorage(pwcsName As String, grfMode As UInteger, reserved1 As UInteger, reserved2 As UInteger, ByRef ppstg As IStorage) As Integer
    
            ' [string][unique][in] 
            ' [unique][in] 
            ' [in] 
            ' [unique][in] 
            ' [in] 
            ' [out] 
            Function OpenStorage(pwcsName As String, pstgPriority As IStorage, grfMode As UInteger, snbExclude As IntPtr, reserved As UInteger, ByRef ppstg As IStorage) As Integer
    
            ' [in] 
            ' [size_is][unique][in] 
            ' [unique][in] 
            ' [unique][in] 
            Function CopyTo(ciidExclude As UInteger, rgiidExclude As Guid, snbExclude As IntPtr, pstgDest As IStorage) As Integer
    
            ' [string][in] 
            ' [unique][in] 
            ' [string][in] 
            ' [in] 
            Function MoveElementTo(pwcsName As String, pstgDest As IStorage, pwcsNewName As String, grfFlags As UInteger) As Integer
    
            ' [in] 
            Function Commit(grfCommitFlags As UInteger) As Integer
    
            Function Revert() As Integer
    
            ' [in] 
            ' [size_is][unique][in] 
            ' [in] 
            ' [out] 
            Function EnumElements(reserved1 As UInteger, reserved2 As IntPtr, reserved3 As UInteger, ByRef ppenum As IEnumSTATSTG) As Integer
    
            ' [string][in] 
            Function DestroyElement(pwcsName As String) As Integer
    
            ' [string][in] 
            ' [string][in] 
            Function RenameElement(pwcsOldName As String, pwcsNewName As String) As Integer
    
            ' [string][unique][in] 
            ' [unique][in] 
            ' [unique][in] 
            ' [unique][in] 
            Function SetElementTimes(pwcsName As String, pctime As FILETIME, patime As FILETIME, pmtime As FILETIME) As Integer
    
            ' [in] 
            Function SetClass(clsid As Guid) As Integer
    
            ' [in] 
            ' [in] 
            Function SetStateBits(grfStateBits As UInteger, grfMask As UInteger) As Integer
    
            ' [out] 
            ' [in] 
            Function Stat(ByRef pstatstg As STATSTG, grfStatFlag As UInteger) As Integer
    
        End Interface
    
        <ComImport()> _
        <Guid("0000000a-0000-0000-C000-000000000046")> _
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface ILockBytes
            ' [in] 
            ' [unique][out] 
            ' [in] 
            ' [out] 
            Function ReadAt(ulOffset As ULong, pv As IntPtr, cb As UInteger, ByRef pcbRead As IntPtr) As Integer
    
            ' [in] 
            ' [size_is][in] 
            ' [in] 
            ' [out] 
            Function WriteAt(ulOffset As ULong, pv As IntPtr, cb As UInteger, ByRef pcbWritten As IntPtr) As Integer
    
            Function Flush() As Integer
    
            ' [in] 
            Function SetSize(cb As ULong) As Integer
    
            ' [in] 
            ' [in] 
            ' [in] 
            Function LockRegion(libOffset As ULong, cb As ULong, dwLockType As UInteger) As Integer
    
            ' [in] 
            ' [in] 
            ' [in] 
            Function UnlockRegion(libOffset As ULong, cb As ULong, dwLockType As UInteger) As Integer
    
            ' [out] 
            ' [in] 
            Function Stat(ByRef pstatstg As STATSTG, grfStatFlag As UInteger) As Integer
    
        End Interface
    
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0c733a30-2a1c-11ce-ade5-00aa0044773d")> _
        Public Interface ISequentialStream
            ' [length_is][size_is][out] 
            ' [in] 
            ' [out] 
            Function Read(pv As IntPtr, cb As UInteger, ByRef pcbRead As UInteger) As Integer
    
            ' [size_is][in] 
            ' [in] 
            ' [out] 
            Function Write(pv As IntPtr, cb As UInteger, ByRef pcbWritten As UInteger) As Integer
    
        End Interface
    
        <ComImport()> _
        <Guid("0000000c-0000-0000-C000-000000000046")> _
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IStream
            Inherits ISequentialStream
            ' [in] 
            ' [in] 
            ' [out] 
            Function Seek(dlibMove As ULong, dwOrigin As UInteger, ByRef plibNewPosition As ULong) As Integer
    
            ' [in] 
            Function SetSize(libNewSize As ULong) As Integer
    
            ' [unique][in] 
            ' [in] 
            ' [out] 
            ' [out] 
            Function CopyTo(<[In]()> pstm As IStream, cb As ULong, ByRef pcbRead As ULong, ByRef pcbWritten As ULong) As Integer
    
            ' [in] 
            Function Commit(grfCommitFlags As UInteger) As Integer
    
            Function Revert() As Integer
    
            ' [in] 
            ' [in] 
            ' [in] 
            Function LockRegion(libOffset As ULong, cb As ULong, dwLockType As UInteger) As Integer
    
            ' [in] 
            ' [in] 
            ' [in] 
            Function UnlockRegion(libOffset As ULong, cb As ULong, dwLockType As UInteger) As Integer
    
            ' [out] 
            ' [in] 
            Function Stat(ByRef pstatstg As STATSTG, grfStatFlag As UInteger) As Integer
    
            ' [out] 
            Function Clone(ByRef ppstm As IStream) As Integer
    
        End Interface
    
        ''' <summary>
        ''' Definition for interface IPersist.
        ''' </summary>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0000010c-0000-0000-C000-000000000046")> _
        Public Interface IPersist
            ''' <summary>
            ''' getClassID
            ''' </summary>
            ''' <param name="pClassID"></param>
            ' [out] 
            Sub GetClassID(ByRef pClassID As Guid)
        End Interface
    
        ''' <summary>
        ''' Definition for interface IPersistStream.
        ''' </summary>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000109-0000-0000-C000-000000000046")> _
        Public Interface IPersistStream
            Inherits IPersist
            ''' <summary>
            ''' GetClassID
            ''' </summary>
            ''' <param name="pClassID"></param>
            Shadows Sub GetClassID(ByRef pClassID As Guid)
            ''' <summary>
            ''' isDirty
            ''' </summary>
            ''' <returns></returns>
            <PreserveSig()> _
            Function IsDirty() As Integer
            ''' <summary>
            ''' Load
            ''' </summary>
            ''' <param name="pStm"></param>
            Sub Load(<[In]()> pStm As UCOMIStream)
            ''' <summary>
            ''' Save
            ''' </summary>
            ''' <param name="pStm"></param>
            ''' <param name="fClearDirty"></param>
            Sub Save(<[In]()> pStm As UCOMIStream, <[In](), MarshalAs(UnmanagedType.Bool)> fClearDirty As Boolean)
            ''' <summary>
            ''' GetSizeMax
            ''' </summary>
            ''' <param name="pcbSize"></param>
            Sub GetSizeMax(ByRef pcbSize As Long)
        End Interface
    
        <ComImport(), Guid("00020D00-0000-0000-c000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
        Public Interface IRichEditOle
            <PreserveSig()> _
            Function GetClientSite(ByRef site As IOleClientSite) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetObjectCount() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetLinkCount() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetObject(iob As Integer, <[In](), Out()> lpreobject As REOBJECT, <MarshalAs(UnmanagedType.U4)> flags As GETOBJECTOPTIONS) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function InsertObject(lpreobject As REOBJECT) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function ConvertObject(iob As Integer, rclsidNew As Guid, lpstrUserTypeNew As String) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function ActivateAs(rclsid As Guid, rclsidAs As Guid) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetHostNames(lpstrContainerApp As String, lpstrContainerObj As String) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetLinkAvailable(iob As Integer, fAvailable As Boolean) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SetDvaspect(iob As Integer, dvaspect As UInteger) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function HandsOffStorage(iob As Integer) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function SaveCompleted(iob As Integer, lpstg As IStorage) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function InPlaceDeactivate() As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function ContextSensitiveHelp(fEnterMode As Boolean) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function GetClipboardData(<[In](), Out()> ByRef lpchrg As CHARRANGE, <MarshalAs(UnmanagedType.U4)> reco As GETCLIPBOARDDATAFLAGS, ByRef lplpdataobj As IDataObject) As <MarshalAs(UnmanagedType.I4)> Integer
    
            <PreserveSig()> _
            Function ImportDataObject(lpdataobj As IDataObject, cf As Integer, hMetaPict As IntPtr) As <MarshalAs(UnmanagedType.I4)> Integer
        End Interface
    #End Region
    
        Public Class myDataObject
            Implements IDataObject
            Private mBitmap As Bitmap
            Public mpFormatetc As FORMATETC
    
    #Region "IDataObject Members"
    
            Private Const S_OK As UInteger = 0
            Private Const E_POINTER As UInteger = &H80004003UI
            Private Const E_NOTIMPL As UInteger = &H80004001UI
            Private Const E_FAIL As UInteger = &H80004005UI
    
            Public Function GetData(ByRef pFormatetc As FORMATETC, ByRef pMedium As STGMEDIUM) As UInteger Implements IDataObject.GetData
                Dim hDst As IntPtr = mBitmap.GetHbitmap()
    
                pMedium.tymed = CInt(TYMED.TYMED_GDI)
                pMedium.unionmember = hDst
                pMedium.pUnkForRelease = IntPtr.Zero
    
                Return CUInt(S_OK)
            End Function
    
            Public Function GetDataHere(ByRef pFormatetc As FORMATETC, ByRef pMedium As STGMEDIUM) As UInteger Implements IDataObject.GetDataHere
                Trace.WriteLine("GetDataHere")
    
                pMedium = New STGMEDIUM()
    
                Return CUInt(E_NOTIMPL)
            End Function
    
            Public Function QueryGetData(ByRef pFormatetc As FORMATETC) As UInteger Implements IDataObject.QueryGetData
                Trace.WriteLine("QueryGetData")
    
                Return CUInt(E_NOTIMPL)
            End Function
    
            Public Function GetCanonicalFormatEtc(ByRef pFormatetcIn As FORMATETC, ByRef pFormatetcOut As FORMATETC) As UInteger Implements IDataObject.GetCanonicalFormatEtc
                Trace.WriteLine("GetCanonicalFormatEtc")
    
                pFormatetcOut = New FORMATETC()
    
                Return CUInt(E_NOTIMPL)
            End Function
    
            Public Function SetData(ByRef a As FORMATETC, ByRef b As STGMEDIUM, fRelease As Boolean) As UInteger
                'mpFormatetc = pFormatectIn;
                'mpmedium = pmedium;
    
                Trace.WriteLine("SetData")
    
                Return CInt(S_OK)
            End Function
    
            Public Function EnumFormatEtc(dwDirection As UInteger, penum As IEnumFORMATETC) As UInteger
                Trace.WriteLine("EnumFormatEtc")
    
                Return CInt(S_OK)
            End Function
    
            Public Function DAdvise(ByRef a As FORMATETC, advf As Integer, pAdvSink As IAdviseSink, ByRef pdwConnection As UInteger) As UInteger
                Trace.WriteLine("DAdvise")
    
                pdwConnection = 0
    
                Return CUInt(E_NOTIMPL)
            End Function
    
            Public Function DUnadvise(dwConnection As UInteger) As UInteger
                Trace.WriteLine("DUnadvise")
    
                Return CUInt(E_NOTIMPL)
            End Function
    
            Public Function EnumDAdvise(ByRef ppenumAdvise As IEnumSTATDATA) As UInteger Implements IDataObject.EnumDAdvise
                Trace.WriteLine("EnumDAdvise")
    
                ppenumAdvise = Nothing
    
                Return CUInt(E_NOTIMPL)
            End Function
    
    #End Region
    
            Public Sub New()
                mBitmap = New Bitmap(16, 16)
                mpFormatetc = New FORMATETC()
            End Sub
    
            Public Sub SetImage(strFilename As String)
                Try
                    mBitmap = DirectCast(Bitmap.FromFile(strFilename, True), Bitmap)
    
                    mpFormatetc.cfFormat = CLIPFORMAT.CF_BITMAP
                    ' Clipboard format = CF_BITMAP
                    mpFormatetc.ptd = IntPtr.Zero
                    ' Target Device = Screen
                    mpFormatetc.dwAspect = DVASPECT.DVASPECT_CONTENT
                    ' Level of detail = Full content
                    mpFormatetc.lindex = -1
                    ' Index = Not applicaple
                    ' Storage medium = HBITMAP handle
                    mpFormatetc.tymed = TYMED.TYMED_GDI
                Catch
                End Try
            End Sub
    
            Public Sub SetImage(image As Image)
                Try
                    mBitmap = New Bitmap(image)
    
                    mpFormatetc.cfFormat = CLIPFORMAT.CF_BITMAP
                    ' Clipboard format = CF_BITMAP
                    mpFormatetc.ptd = IntPtr.Zero
                    ' Target Device = Screen
                    mpFormatetc.dwAspect = DVASPECT.DVASPECT_CONTENT
                    ' Level of detail = Full content
                    mpFormatetc.lindex = -1
                    ' Index = Not applicaple
                    ' Storage medium = HBITMAP handle
                    mpFormatetc.tymed = TYMED.TYMED_GDI
                Catch
                End Try
            End Sub
        End Class
    
        Public Class MyExtRichTextBox
            Inherits RichTextBox
            Public Sub New()
            End Sub
    
    #Region "Imports and structs"
    
            ' It makes no difference if we use PARAFORMAT or
            ' PARAFORMAT2 here, so I have opted for PARAFORMAT2.
            <StructLayout(LayoutKind.Sequential)> _
            Public Structure PARAFORMAT
                Public cbSize As Integer
                Public dwMask As UInteger
                Public wNumbering As Short
                Public wReserved As Short
                Public dxStartIndent As Integer
                Public dxRightIndent As Integer
                Public dxOffset As Integer
                Public wAlignment As Short
                Public cTabCount As Short
                <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
                Public rgxTabs As Integer()
    
                ' PARAFORMAT2 from here onwards.
                Public dySpaceBefore As Integer
                Public dySpaceAfter As Integer
                Public dyLineSpacing As Integer
                Public sStyle As Short
                Public bLineSpacingRule As Byte
                Public bOutlineLevel As Byte
                Public wShadingWeight As Short
                Public wShadingStyle As Short
                Public wNumberingStart As Short
                Public wNumberingStyle As Short
                Public wNumberingTab As Short
                Public wBorderSpace As Short
                Public wBorderWidth As Short
                Public wBorders As Short
            End Structure
    
            <StructLayout(LayoutKind.Sequential)> _
            Public Structure CHARFORMAT
                Public cbSize As Integer
                Public dwMask As UInt32
                Public dwEffects As UInt32
                Public yHeight As Int32
                Public yOffset As Int32
                Public crTextColor As Int32
                Public bCharSet As Byte
                Public bPitchAndFamily As Byte
                <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
                Public szFaceName As Char()
    
                ' CHARFORMAT2 from here onwards.
                Public wWeight As Short
                Public sSpacing As Short
                Public crBackColor As Int32
                Public lcid As UInteger
                Public dwReserved As UInteger
                Public sStyle As Short
                Public wKerning As Short
                Public bUnderlineType As Byte
                Public bAnimation As Byte
                Public bRevAuthor As Byte
                Public bReserved1 As Byte
            End Structure
    
            <DllImport("user32", CharSet:=CharSet.Auto)> _
            Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, lParam As Integer) As Integer
            End Function
    
            <DllImport("user32", CharSet:=CharSet.Auto)> _
            Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lp As PARAFORMAT) As Integer
            End Function
    
            <DllImport("user32", CharSet:=CharSet.Auto)> _
            Private Shared Function SendMessage(hWnd As HandleRef, msg As Integer, wParam As Integer, ByRef lp As CHARFORMAT) As Integer
            End Function
    
            Private Const EM_SETEVENTMASK As Integer = 1073
            Private Const WM_SETREDRAW As Integer = 11
    
            <DllImport("User32.dll", CharSet:=CharSet.Auto, PreserveSig:=False)> _
            Public Shared Function SendMessage(hWnd As IntPtr, message As Integer, wParam As Integer) As IRichEditOle
            End Function
    
            <DllImport("user32.dll", ExactSpelling:=True, CharSet:=CharSet.Auto)> _
            Friend Shared Function GetClientRect(hWnd As IntPtr, <[In](), Out()> ByRef rect As Rectangle) As Boolean
            End Function
    
            <DllImport("user32.dll", ExactSpelling:=True, CharSet:=CharSet.Auto)> _
            Friend Shared Function GetWindowRect(hWnd As IntPtr, <[In](), Out()> ByRef rect As Rectangle) As Boolean
            End Function
    
            <DllImport("user32.dll", ExactSpelling:=True, CharSet:=CharSet.Auto)> _
            Friend Shared Function GetParent(hWnd As IntPtr) As IntPtr
            End Function
    
            <DllImport("ole32.dll")> _
            Private Shared Function OleSetContainedObject(<MarshalAs(UnmanagedType.IUnknown)> pUnk As Object, fContained As Boolean) As Integer
            End Function
    
            <DllImport("ole32.dll")> _
            Private Shared Function OleLoadPicturePath(<MarshalAs(UnmanagedType.LPWStr)> lpszPicturePath As String, <MarshalAs(UnmanagedType.IUnknown)> <[In]()> pIUnknown As Object, dwReserved As UInteger, clrReserved As UInteger, ByRef riid As Guid, <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObj As Object) As Integer
            End Function
    
            <DllImport("ole32.dll")> _
            Private Shared Function OleCreateFromFile(<[In]()> ByRef rclsid As Guid, <MarshalAs(UnmanagedType.LPWStr)> lpszFileName As String, <[In]()> ByRef riid As Guid, renderopt As UInteger, ByRef pFormatEtc As FORMATETC, pClientSite As IOleClientSite, _
       pStg As IStorage, <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObj As Object) As Integer
            End Function
    
            <DllImport("ole32.dll")> _
            Private Shared Function OleCreateFromData(pSrcDataObj As IDataObject, <[In]()> ByRef riid As Guid, renderopt As UInteger, ByRef pFormatEtc As FORMATETC, pClientSite As IOleClientSite, pStg As IStorage, _
       <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObj As Object) As Integer
            End Function
    
            <DllImport("ole32.dll")> _
            Private Shared Function OleCreateStaticFromData(<MarshalAs(UnmanagedType.[Interface])> pSrcDataObj As IDataObject, <[In]()> ByRef riid As Guid, renderopt As UInteger, ByRef pFormatEtc As FORMATETC, pClientSite As IOleClientSite, pStg As IStorage, _
       <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObj As Object) As Integer
            End Function
    
            <DllImport("ole32.dll")> _
            Private Shared Function OleCreateLinkFromData(<MarshalAs(UnmanagedType.[Interface])> pSrcDataObj As IDataObject, <[In]()> ByRef riid As Guid, renderopt As UInteger, ByRef pFormatEtc As FORMATETC, pClientSite As IOleClientSite, pStg As IStorage, _
       <MarshalAs(UnmanagedType.IUnknown)> ByRef ppvObj As Object) As Integer
            End Function
    
    #End Region
    
    
            Public Sub InsertOleObject(oleObj As IOleObject)
                Dim ole As New RichEditOle(Me)
                ole.InsertOleObject(oleObj)
            End Sub
    
            Public Sub InsertControl(control As Control)
                Dim ole As New RichEditOle(Me)
                ole.InsertControl(control)
            End Sub
    
            Public Sub InsertMyDataObject(mdo As myDataObject)
                Dim ole As New RichEditOle(Me)
                ole.InsertMyDataObject(mdo)
            End Sub
    
            Public Sub UpdateObjects()
                Dim ole As New RichEditOle(Me)
                ole.UpdateObjects()
            End Sub
    
            Public Sub InsertImage(image As Image)
                Dim mdo As New myDataObject()
    
                mdo.SetImage(image)
    
                Me.InsertMyDataObject(mdo)
            End Sub
    
            Public Sub InsertImage(imageFile As String)
                Dim mdo As New myDataObject()
    
                mdo.SetImage(imageFile)
    
                Me.InsertMyDataObject(mdo)
            End Sub
    
            Public Sub InsertImageFromFile(strFilename As String)
                Dim ole As New RichEditOle(Me)
                ole.InsertImageFromFile(strFilename)
            End Sub
    
            Public Sub InsertActiveX(strProgID As String)
                Dim t As Type = Type.GetTypeFromProgID(strProgID)
                If t Is Nothing Then
                    Return
                End If
    
                Dim o As Object = System.Activator.CreateInstance(t)
    
                Dim b As Boolean = (TypeOf o Is IOleObject)
    
                If b Then
                    Me.InsertOleObject(DirectCast(o, IOleObject))
                End If
            End Sub
    
            ' RichEditOle wrapper and helper
            Private Class RichEditOle
                Public Const WM_USER As Integer = &H400
                Public Const EM_GETOLEINTERFACE As Integer = WM_USER + 60
    
                Private _richEdit As MyExtRichTextBox
                Private _RichEditOle As IRichEditOle
    
                Public Sub New(richEdit As MyExtRichTextBox)
                    Me._richEdit = richEdit
                End Sub
    
                Private ReadOnly Property IRichEditOle() As IRichEditOle
                    Get
                        If Me._RichEditOle Is Nothing Then
                            Me._RichEditOle = SendMessage(Me._richEdit.Handle, EM_GETOLEINTERFACE, 0)
                        End If
    
                        Return Me._RichEditOle
                    End Get
                End Property
    
    
                <DllImport("ole32.dll", PreserveSig:=False)> _
                Friend Shared Function CreateILockBytesOnHGlobal(hGlobal As IntPtr, fDeleteOnRelease As Boolean, <Out()> ByRef ppLkbyt As ILockBytes) As Integer
                End Function
    
                <DllImport("ole32.dll")> _
                Private Shared Function StgCreateDocfileOnILockBytes(plkbyt As ILockBytes, grfMode As UInteger, reserved As UInteger, ByRef ppstgOpen As IStorage) As Integer
                End Function
    
                Public Sub InsertControl(control As Control)
                    If control Is Nothing Then
                        Return
                    End If
    
                    Dim guid As Guid = Marshal.GenerateGuidForType(control.[GetType]())
    
                    '-----------------------
                    Dim pLockBytes As ILockBytes
                    CreateILockBytesOnHGlobal(IntPtr.Zero, True, pLockBytes)
    
                    Dim pStorage As IStorage
                    StgCreateDocfileOnILockBytes(pLockBytes, CUInt(STGM.STGM_SHARE_EXCLUSIVE Or STGM.STGM_CREATE Or STGM.STGM_READWRITE), 0, pStorage)
    
                    Dim pOleClientSite As IOleClientSite
                    Me.IRichEditOle.GetClientSite(pOleClientSite)
                    '-----------------------
    
                    '-----------------------
                    Dim reoObject As New REOBJECT()
    
                    reoObject.cp = Me._richEdit.TextLength
    
                    reoObject.clsid = guid
                    reoObject.pstg = pStorage
                    reoObject.poleobj = Marshal.GetIUnknownForObject(control)
                    reoObject.polesite = pOleClientSite
                    reoObject.dvAspect = CUInt(DVASPECT.DVASPECT_CONTENT)
                    reoObject.dwFlags = CUInt(REOOBJECTFLAGS.REO_BELOWBASELINE)
                    reoObject.dwUser = 1
    
                    Me.IRichEditOle.InsertObject(reoObject)
                    '-----------------------
    
                    '-----------------------
                    Marshal.ReleaseComObject(pLockBytes)
                    Marshal.ReleaseComObject(pOleClientSite)
                    Marshal.ReleaseComObject(pStorage)
                    '-----------------------
                End Sub
    
                Public Function InsertImageFromFile(strFilename As String) As Boolean
                    '-----------------------
                    Dim pLockBytes As ILockBytes
                    CreateILockBytesOnHGlobal(IntPtr.Zero, True, pLockBytes)
    
                    Dim pStorage As IStorage
                    StgCreateDocfileOnILockBytes(pLockBytes, CUInt(STGM.STGM_SHARE_EXCLUSIVE Or STGM.STGM_CREATE Or STGM.STGM_READWRITE), 0, pStorage)
    
                    Dim pOleClientSite As IOleClientSite
                    Me.IRichEditOle.GetClientSite(pOleClientSite)
                    '-----------------------
    
    
                    '-----------------------
                    Dim formatEtc As New FORMATETC()
    
                    formatEtc.cfFormat = 0
                    formatEtc.ptd = IntPtr.Zero
                    formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT
                    formatEtc.lindex = -1
                    formatEtc.tymed = TYMED.TYMED_NULL
    
                    Dim IID_IOleObject As New Guid("{00000112-0000-0000-C000-000000000046}")
                    Dim CLSID_NULL As New Guid("{00000000-0000-0000-0000-000000000000}")
    
                    Dim pOleObjectOut As Object
    
                    ' I don't sure, but it appears that this function only loads from bitmap
                    ' You can also try OleCreateFromData, OleLoadPictureIndirect, etc.
                    Dim hr As Integer = OleCreateFromFile(CLSID_NULL, strFilename, IID_IOleObject, CUInt(OLERENDER.OLERENDER_DRAW), formatEtc, pOleClientSite, _
                     pStorage, pOleObjectOut)
    
                    If pOleObjectOut Is Nothing Then
                        Marshal.ReleaseComObject(pLockBytes)
                        Marshal.ReleaseComObject(pOleClientSite)
                        Marshal.ReleaseComObject(pStorage)
    
                        Return False
                    End If
    
                    Dim pOleObject As IOleObject = DirectCast(pOleObjectOut, IOleObject)
                    '-----------------------
    
    
                    '-----------------------
                    Dim guid As New Guid()
    
                    'guid = Marshal.GenerateGuidForType(pOleObject.GetType());
                    pOleObject.GetUserClassID(guid)
                    '-----------------------
    
                    '-----------------------
                    OleSetContainedObject(pOleObject, True)
    
                    Dim reoObject As New REOBJECT()
    
                    reoObject.cp = Me._richEdit.TextLength
    
                    reoObject.clsid = guid
                    reoObject.pstg = pStorage
                    reoObject.poleobj = Marshal.GetIUnknownForObject(pOleObject)
                    reoObject.polesite = pOleClientSite
                    reoObject.dvAspect = CUInt(DVASPECT.DVASPECT_CONTENT)
                    reoObject.dwFlags = CUInt(REOOBJECTFLAGS.REO_BELOWBASELINE)
                    reoObject.dwUser = 0
    
                    Me.IRichEditOle.InsertObject(reoObject)
                    '-----------------------
    
                    '-----------------------
                    Marshal.ReleaseComObject(pLockBytes)
                    Marshal.ReleaseComObject(pOleClientSite)
                    Marshal.ReleaseComObject(pStorage)
                    Marshal.ReleaseComObject(pOleObject)
                    '-----------------------
    
                    Return True
                End Function
    
                Public Sub InsertMyDataObject(mdo As myDataObject)
                    If mdo Is Nothing Then
                        Return
                    End If
    
                    '-----------------------
                    Dim pLockBytes As ILockBytes
                    Dim sc As Integer = CreateILockBytesOnHGlobal(IntPtr.Zero, True, pLockBytes)
    
                    Dim pStorage As IStorage
                    sc = StgCreateDocfileOnILockBytes(pLockBytes, CUInt(STGM.STGM_SHARE_EXCLUSIVE Or STGM.STGM_CREATE Or STGM.STGM_READWRITE), 0, pStorage)
    
                    Dim pOleClientSite As IOleClientSite
                    Me.IRichEditOle.GetClientSite(pOleClientSite)
                    '-----------------------
    
                    Dim guid As Guid = Marshal.GenerateGuidForType(mdo.[GetType]())
    
                    Dim IID_IOleObject As New Guid("{00000112-0000-0000-C000-000000000046}")
                    Dim IID_IDataObject As New Guid("{0000010e-0000-0000-C000-000000000046}")
                    Dim IID_IUnknown As New Guid("{00000000-0000-0000-C000-000000000046}")
    
                    Dim pOleObject As Object
    
                    Dim hr As Integer = OleCreateStaticFromData(mdo, IID_IOleObject, CUInt(OLERENDER.OLERENDER_FORMAT), mdo.mpFormatetc, pOleClientSite, pStorage, _
                     pOleObject)
    
                    If pOleObject Is Nothing Then
                        Return
                    End If
                    '-----------------------
    
    
                    '-----------------------
                    OleSetContainedObject(pOleObject, True)
    
                    Dim reoObject As New REOBJECT()
    
                    reoObject.cp = Me._richEdit.TextLength
    
                    reoObject.clsid = guid
                    reoObject.pstg = pStorage
                    reoObject.poleobj = Marshal.GetIUnknownForObject(pOleObject)
                    reoObject.polesite = pOleClientSite
                    reoObject.dvAspect = CUInt(DVASPECT.DVASPECT_CONTENT)
                    reoObject.dwFlags = CUInt(REOOBJECTFLAGS.REO_BELOWBASELINE)
                    reoObject.dwUser = 0
    
                    Me.IRichEditOle.InsertObject(reoObject)
                    '-----------------------
    
                    '-----------------------
                    Marshal.ReleaseComObject(pLockBytes)
                    Marshal.ReleaseComObject(pOleClientSite)
                    Marshal.ReleaseComObject(pStorage)
                    Marshal.ReleaseComObject(pOleObject)
                    '-----------------------
                End Sub
    
                Public Sub InsertOleObject(oleObject As IOleObject)
                    If oleObject Is Nothing Then
                        Return
                    End If
    
                    '-----------------------
                    Dim pLockBytes As ILockBytes
                    CreateILockBytesOnHGlobal(IntPtr.Zero, True, pLockBytes)
    
                    Dim pStorage As IStorage
                    StgCreateDocfileOnILockBytes(pLockBytes, CUInt(STGM.STGM_SHARE_EXCLUSIVE Or STGM.STGM_CREATE Or STGM.STGM_READWRITE), 0, pStorage)
    
                    Dim pOleClientSite As IOleClientSite
                    Me.IRichEditOle.GetClientSite(pOleClientSite)
                    '-----------------------
    
                    '-----------------------
                    Dim guid As New Guid()
    
                    oleObject.GetUserClassID(guid)
                    '-----------------------
    
                    '-----------------------
                    OleSetContainedObject(oleObject, True)
    
                    Dim reoObject As New REOBJECT()
    
                    reoObject.cp = Me._richEdit.TextLength
    
                    reoObject.clsid = guid
                    reoObject.pstg = pStorage
                    reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject)
                    reoObject.polesite = pOleClientSite
                    reoObject.dvAspect = CUInt(DVASPECT.DVASPECT_CONTENT)
                    reoObject.dwFlags = CUInt(REOOBJECTFLAGS.REO_BELOWBASELINE)
    
                    Me.IRichEditOle.InsertObject(reoObject)
                    '-----------------------
    
                    '-----------------------
                    Marshal.ReleaseComObject(pLockBytes)
                    Marshal.ReleaseComObject(pOleClientSite)
                    Marshal.ReleaseComObject(pStorage)
                    '-----------------------
                End Sub
    
                Public Sub UpdateObjects()
                    Dim k As Integer = Me.IRichEditOle.GetObjectCount()
    
                    For i As Integer = 0 To k - 1
                        Dim reoObject As New REOBJECT()
    
                        Me.IRichEditOle.GetObject(i, reoObject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES)
    
                        If reoObject.dwUser = 1 Then
                            Dim pt As Point = Me._richEdit.GetPositionFromCharIndex(reoObject.cp)
                            Dim rect As New Rectangle(pt, reoObject.sizel)
    
                            ' repaint
                            Me._richEdit.Invalidate(rect, False)
                        End If
                    Next
                End Sub
            End Class
        End Class
    End Namespace

    on line 747, we have:

    Implements IDataObject

    but i get 4 errors:

    1 - "Class 'myDataObject' must implement 'Function DAdvise(ByRef pFormatetc As FORMATETC, advf As Integer, pAdvSink As IAdviseSink, ByRef pdwConnection As UInteger) As UInteger' for interface 'IDataObject'. "

    2 - "Class 'myDataObject' must implement 'Function DUnadvise(dwConnection As UInteger) As UInteger' for interface 'IDataObject'."

    3 - "Class 'myDataObject' must implement 'Function EnumFormatEtc(dwDirection As UInteger, penum As IEnumFORMATETC) As UInteger' for interface 'IDataObject'."

    4 - "Class 'myDataObject' must implement 'Function SetData(ByRef pFormatectIn As FORMATETC, ByRef pmedium As STGMEDIUM, fRelease As Boolean) As UInteger' for interface 'IDataObject'."

    how can i fix these errors?

    Monday, April 24, 2017 12:34 PM

Answers

  • Hi Cambalinho,

    According to your description, there are some issue in your implement Function for interface 'IDataObject'

    Please refer to the code below

    Public Function DAdvise(ByRef a As FORMATETC, advf As Integer, pAdvSink As IAdviseSink, ByRef pdwConnection As UInteger) As UInteger Implements IDataObject.DAdvise
                Trace.WriteLine("DAdvise")
    
                pdwConnection = 0
    
                Return CUInt(E_NOTIMPL)
            End Function

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Cambalinho Thursday, April 27, 2017 3:56 PM
    Thursday, April 27, 2017 10:28 AM
    Moderator

All replies

  • Hi Cambalinho,

    According to your description, there are some issue in your implement Function for interface 'IDataObject'

    Please refer to the code below

    Public Function DAdvise(ByRef a As FORMATETC, advf As Integer, pAdvSink As IAdviseSink, ByRef pdwConnection As UInteger) As UInteger Implements IDataObject.DAdvise
                Trace.WriteLine("DAdvise")
    
                pdwConnection = 0
    
                Return CUInt(E_NOTIMPL)
            End Function

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Cambalinho Thursday, April 27, 2017 3:56 PM
    Thursday, April 27, 2017 10:28 AM
    Moderator
  • thank you so much.

    i get the point:

    Implements IDataObject.something

    i must use the 'Implements'.


    after that change that you tell me, i was thinking how i can fix the others errors. and now it's fixed
    • Edited by Cambalinho Thursday, April 27, 2017 3:57 PM
    Thursday, April 27, 2017 3:56 PM