Ejemplo n.º 1
0
 public bool InsertImageFromFile(string strFilename)
 {
     CCWin.SkinControl.ILockBytes bytes;
     CCWin.SkinControl.IStorage storage;
     CCWin.SkinControl.IOleClientSite site;
     object obj2;
     CCWin.Win32.NativeMethods.CreateILockBytesOnHGlobal(IntPtr.Zero, true, out bytes);
     CCWin.Win32.NativeMethods.StgCreateDocfileOnILockBytes(bytes, 0x1012, 0, out storage);
     this.IRichEditOle.GetClientSite(out site);
     FORMATETC pFormatEtc = new FORMATETC();
     pFormatEtc.cfFormat = (CLIPFORMAT) 0;
     pFormatEtc.ptd = IntPtr.Zero;
     pFormatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
     pFormatEtc.lindex = -1;
     pFormatEtc.tymed = TYMED.TYMED_NULL;
     Guid riid = new Guid("{00000112-0000-0000-C000-000000000046}");
     Guid rclsid = new Guid("{00000000-0000-0000-0000-000000000000}");
     CCWin.Win32.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;
     }
     CCWin.SkinControl.IOleObject pUnk = (CCWin.SkinControl.IOleObject) obj2;
     Guid pClsid = new Guid();
     pUnk.GetUserClassID(ref pClsid);
     CCWin.Win32.NativeMethods.OleSetContainedObject(pUnk, true);
     REOBJECT lpreobject = new REOBJECT();
     lpreobject.cp = this._richEdit.TextLength;
     lpreobject.clsid = pClsid;
     lpreobject.pstg = storage;
     lpreobject.poleobj = Marshal.GetIUnknownForObject(pUnk);
     lpreobject.polesite = site;
     lpreobject.dvAspect = 1;
     lpreobject.dwFlags = 2;
     lpreobject.dwUser = 0;
     this.IRichEditOle.InsertObject(lpreobject);
     Marshal.ReleaseComObject(bytes);
     Marshal.ReleaseComObject(site);
     Marshal.ReleaseComObject(storage);
     Marshal.ReleaseComObject(pUnk);
     return true;
 }
 public static extern int OleCreateFromFile([In] ref Guid rclsid, [MarshalAs(UnmanagedType.LPWStr)] string lpszFileName, [In] ref Guid riid, uint renderopt, ref FORMATETC pFormatEtc, IOleClientSite pClientSite, IStorage pStg, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObj);