public void InsertMyImage(string imageFile) { myDataObject mdo = new myDataObject(); mdo.SetImage(imageFile); this.InsertMyDataObject(mdo); }
public void InsertMyDataObject(myDataObject mdo) { if (mdo == null) return; //----------------------- ILockBytes pLockBytes; int sc = CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes); IStorage pStorage; sc = StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage); IOleClientSite pOleClientSite; this.IRichEditOle.GetClientSite(out pOleClientSite); //----------------------- Guid guid = Marshal.GenerateGuidForType(mdo.GetType()); Guid IID_IOleObject = new Guid("{00000112-0000-0000-C000-000000000046}"); Guid IID_IDataObject = new Guid("{0000010e-0000-0000-C000-000000000046}"); Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); object pOleObject; int hr = OleCreateStaticFromData(mdo, ref IID_IOleObject, (uint)OLERENDER.OLERENDER_FORMAT, ref mdo.mpFormatetc, pOleClientSite, pStorage, out pOleObject); if (pOleObject == null) return; //----------------------- //----------------------- OleSetContainedObject(pOleObject, true); REOBJECT reoObject = new REOBJECT(); reoObject.cp = this._richEdit.TextLength; reoObject.clsid = guid; reoObject.pstg = pStorage; reoObject.poleobj = Marshal.GetIUnknownForObject(pOleObject); reoObject.polesite = pOleClientSite; reoObject.dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT); reoObject.dwFlags = (uint)(REOOBJECTFLAGS.REO_BELOWBASELINE); reoObject.dwUser = 0; this.IRichEditOle.InsertObject(reoObject); //----------------------- //----------------------- Marshal.ReleaseComObject(pLockBytes); Marshal.ReleaseComObject(pOleClientSite); Marshal.ReleaseComObject(pStorage); Marshal.ReleaseComObject(pOleObject); //----------------------- }
public void InsertMyDataObject(myDataObject mdo) { RichEditOle ole = new RichEditOle(this); ole.InsertMyDataObject(mdo); }