internal void InsertControl(MyGIF gif) { if (gif == null) { return; } Guid guid = Marshal.GenerateGuidForType(gif.Box.GetType()); ILockBytes lockBytes; CreateILockBytesOnHGlobal(IntPtr.Zero, true, out lockBytes); IStorage storage; StgCreateDocfileOnILockBytes(lockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE), 0, out storage); IOleClientSite oleClientSite; this.ole.GetClientSite(out oleClientSite); REOBJECT reObject = new REOBJECT() { cp = this.richTextBox.SelectionStart, clsid = guid, pstg = storage, poleobj = Marshal.GetIUnknownForObject(gif.Box), polesite = oleClientSite, dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT), dwFlags = (uint)0x00000002, }; try { reObject.dwUser = gif.Index; } catch (Exception ex) { //MessageBox.Show(ex.Message); } this.ole.InsertObject(reObject); Marshal.ReleaseComObject(lockBytes); Marshal.ReleaseComObject(oleClientSite); Marshal.ReleaseComObject(storage); }
public string GetGIFInfo() { string imageInfo = ""; REOBJECT reObject = new REOBJECT(); reObject.cbStruct = Marshal.SizeOf(typeof(REOBJECT)); for (int i = 0; i < this.richEditOle.GetObjectCount(); i++) { this.richEditOle.GetObject(i, reObject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES); MyGIF gif = this.gifList.Find(p => p != null && p.Index == reObject.dwUser); if (gif != null) { imageInfo += reObject.cp.ToString() + ":" + gif.Name + "|"; } } return(imageInfo); }