Beispiel #1
0
        public REOBJECT InsertOleObject(IOleObject oleObject, int index, int pos)
        {
            ILockBytes     bytes;
            IStorage       storage;
            IOleClientSite site;

            if (oleObject == null)
            {
                return(null);
            }
            NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes);
            NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage);
            this.IRichEditOle.GetClientSite(out site);
            Guid pClsid = new Guid();

            oleObject.GetUserClassID(ref pClsid);
            NativeMethods.OleSetContainedObject(oleObject, true);
            REOBJECT lpreobject = new REOBJECT {
                posistion = pos,
                clsid     = pClsid,
                pstg      = storage,
                poleobj   = Marshal.GetIUnknownForObject(oleObject),
                polesite  = site,
                dvAspect  = 1,
                dwFlags   = 2,
                dwUser    = (uint)index
            };

            this.IRichEditOle.InsertObject(lpreobject);
            Marshal.ReleaseComObject(bytes);
            Marshal.ReleaseComObject(site);
            Marshal.ReleaseComObject(storage);
            return(lpreobject);
        }
Beispiel #2
0
        public bool InsertImageFromFile(string strFilename, int position)
        {
            ILockBytes     bytes;
            IStorage       storage;
            IOleClientSite site;
            object         obj2;

            NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes);
            NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage);
            this.IRichEditOle.GetClientSite(out site);
            FORMATETC pFormatEtc = new FORMATETC {
                cfFormat = (CLIPFORMAT)0,
                ptd      = IntPtr.Zero,
                dwAspect = DVASPECT.DVASPECT_CONTENT,
                lindex   = -1,
                tymed    = TYMED.TYMED_NULL
            };
            Guid riid   = new Guid("{00000112-0000-0000-C000-000000000046}");
            Guid rclsid = new Guid("{00000000-0000-0000-0000-000000000000}");

            NativeMethods.OleCreateFromFile(ref rclsid, strFilename, ref riid, 1, ref pFormatEtc, site, storage, out obj2);
            if (obj2 == null)
            {
                Marshal.ReleaseComObject(bytes);
                Marshal.ReleaseComObject(site);
                Marshal.ReleaseComObject(storage);
                return(false);
            }
            IOleObject pUnk   = (IOleObject)obj2;
            Guid       pClsid = new Guid();

            pUnk.GetUserClassID(ref pClsid);
            NativeMethods.OleSetContainedObject(pUnk, true);
            REOBJECT lpreobject = new REOBJECT {
                posistion = position,
                clsid     = pClsid,
                pstg      = storage,
                poleobj   = Marshal.GetIUnknownForObject(pUnk),
                polesite  = site,
                dvAspect  = 1,
                dwFlags   = 2,
                dwUser    = 0
            };

            this.IRichEditOle.InsertObject(lpreobject);
            Marshal.ReleaseComObject(bytes);
            Marshal.ReleaseComObject(site);
            Marshal.ReleaseComObject(storage);
            Marshal.ReleaseComObject(pUnk);
            return(true);
        }
Beispiel #3
0
        public REOBJECT InsertOleObject(
            IOleObject oleObject,
            int index)
        {
            if (oleObject == null)
            {
                return(null);
            }

            ILockBytes pLockBytes;

            NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);

            IStorage pStorage;

            NativeMethods.StgCreateDocfileOnILockBytes(
                pLockBytes,
                (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE),
                0,
                out pStorage);

            IOleClientSite pOleClientSite;

            IRichEditOle.GetClientSite(out pOleClientSite);

            Guid guid = new Guid();

            oleObject.GetUserClassID(ref guid);
            NativeMethods.OleSetContainedObject(oleObject, true);

            REOBJECT reoObject = new REOBJECT();

            reoObject.cp       = _richEdit.TextLength;
            reoObject.clsid    = guid;
            reoObject.pstg     = pStorage;
            reoObject.poleobj  = Marshal.GetIUnknownForObject(oleObject);
            reoObject.polesite = pOleClientSite;
            reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT;
            reoObject.dwFlags  = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE;
            reoObject.dwUser   = (uint)index;

            IRichEditOle.InsertObject(reoObject);

            Marshal.ReleaseComObject(pLockBytes);
            Marshal.ReleaseComObject(pOleClientSite);
            Marshal.ReleaseComObject(pStorage);

            return(reoObject);
        }
Beispiel #4
0
			public void InsertOleObject(IOleObject oleObject)
			{
				if (oleObject == null)
					return;

				//-----------------------
				ILockBytes pLockBytes;
				CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);

				IStorage pStorage;
				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 = new Guid();

				oleObject.GetUserClassID(ref guid);
				//-----------------------

				//-----------------------
				OleSetContainedObject(oleObject, true);

				REOBJECT reoObject = new REOBJECT();
				
				reoObject.cp = this._richEdit.TextLength;

				reoObject.clsid = guid;
				reoObject.pstg = pStorage;
				reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject);
				reoObject.polesite = pOleClientSite;
				reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT;
				reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE;

				this.IRichEditOle.InsertObject(reoObject);
				//-----------------------

				//-----------------------
				Marshal.ReleaseComObject(pLockBytes);
				Marshal.ReleaseComObject(pOleClientSite);
				Marshal.ReleaseComObject(pStorage);
				//-----------------------
			}
        public REOBJECT InsertOleObject(IOleObject oleObject, int index, int pos)
        {
            if (oleObject == null)
            {
                return null;
            }

            ILockBytes pLockBytes;
            NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);

            IStorage pStorage;
            NativeMethods.StgCreateDocfileOnILockBytes(
                pLockBytes,
                (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE),
                0,
                out pStorage);

            IOleClientSite pOleClientSite;
            IRichEditOle.GetClientSite(out pOleClientSite);

            Guid guid = new Guid();

            oleObject.GetUserClassID(ref guid);
            NativeMethods.OleSetContainedObject(oleObject, true);

            REOBJECT reoObject = new REOBJECT();

            reoObject.posistion = pos;
            reoObject.clsid = guid;
            reoObject.pstg = pStorage;
            reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject);
            reoObject.polesite = pOleClientSite;
            reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT;
            reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE;
            reoObject.dwUser = (uint)index;

            IRichEditOle.InsertObject(reoObject);

            Marshal.ReleaseComObject(pLockBytes);
            Marshal.ReleaseComObject(pOleClientSite);
            Marshal.ReleaseComObject(pStorage);

            return reoObject;
        }