public void ReleaseRichEditOleInterface() { if (IRichEditOlePtr != IntPtr.Zero) { Marshal.Release(IRichEditOlePtr); } IRichEditOlePtr = IntPtr.Zero; IRichEditOleValue = null; }
public IRichEditOle GetRichEditOleInterface() { if (this.IRichEditOleValue == null) { // Allocate the ptr that EM_GETOLEINTERFACE will fill in. IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr))); // Alloc the ptr. Marshal.WriteIntPtr(ptr, IntPtr.Zero); // Clear it. try { if (0 != API.SendMessage(this.Handle, RichEditOle.EM_GETOLEINTERFACE, IntPtr.Zero, ptr)) { // Read the returned pointer. IntPtr pRichEdit = Marshal.ReadIntPtr(ptr); try { if (pRichEdit != IntPtr.Zero) { // Query for the IRichEditOle interface. Guid guid = new Guid("00020D00-0000-0000-c000-000000000046"); Marshal.QueryInterface(pRichEdit, ref guid, out this.IRichEditOlePtr); // Wrap it in the C# interface for IRichEditOle. this.IRichEditOleValue = (IRichEditOle)Marshal.GetTypedObjectForIUnknown(this.IRichEditOlePtr, typeof(IRichEditOle)); if (this.IRichEditOleValue == null) { throw new Exception("Failed to get the object wrapper for the interface."); } } else { throw new Exception("Failed to get the pointer."); } } finally { Marshal.Release(pRichEdit); } } else { throw new Exception("EM_GETOLEINTERFACE failed."); } } catch { this.ReleaseRichEditOleInterface(); } finally { // Free the ptr memory. Marshal.FreeCoTaskMem(ptr); //Marshal.DestroyStructure(ptr, typeof(REOBJECT)); } } return(this.IRichEditOleValue); }
public IRichEditOle GetRichEditOleInterface() { if (this.IRichEditOleValue == null) { // Allocate the ptr that EM_GETOLEINTERFACE will fill in. IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr))); // Alloc the ptr. Marshal.WriteIntPtr(ptr, IntPtr.Zero); // Clear it. try { if (0 != API.SendMessage(this.Handle, RichEditOle.EM_GETOLEINTERFACE, IntPtr.Zero, ptr)) { // Read the returned pointer. IntPtr pRichEdit = Marshal.ReadIntPtr(ptr); try { if (pRichEdit != IntPtr.Zero) { // Query for the IRichEditOle interface. Guid guid = new Guid("00020D00-0000-0000-c000-000000000046"); Marshal.QueryInterface(pRichEdit, ref guid, out this.IRichEditOlePtr); // Wrap it in the C# interface for IRichEditOle. this.IRichEditOleValue = (IRichEditOle)Marshal.GetTypedObjectForIUnknown(this.IRichEditOlePtr, typeof(IRichEditOle)); if (this.IRichEditOleValue == null) { throw new Exception("Failed to get the object wrapper for the interface."); } } else { throw new Exception("Failed to get the pointer."); } } finally { Marshal.Release(pRichEdit); } } else { throw new Exception("EM_GETOLEINTERFACE failed."); } } catch { this.ReleaseRichEditOleInterface(); } finally { // Free the ptr memory. Marshal.FreeCoTaskMem(ptr); //Marshal.DestroyStructure(ptr, typeof(REOBJECT)); } } return this.IRichEditOleValue; }
protected void ReleaseRichEditOleInterface() { if (this.IRichEditOlePtr != IntPtr.Zero) { Marshal.Release(this.IRichEditOlePtr); } this.IRichEditOlePtr = IntPtr.Zero; this.IRichEditOleValue = null; }
protected override void Dispose(bool disposing) { if (_ole != null) { Marshal.ReleaseComObject(_ole); } _ole = null; _document = null; base.Dispose(disposing); }
public Image Ole2Image(int width, int height) { Bitmap result = null; IRichEditOle richEditInterface = this.GetRichEditOleInterface(); if (richEditInterface.GetObjectCount() == 0) { return(result); } REOBJECT reObject = new REOBJECT(); // S_OK == 0, so 0 == success. if (0 == richEditInterface.GetObject(0, reObject, GetObjectOptions.REO_GETOBJ_POLEOBJ)) { try { IntPtr pViewObject = IntPtr.Zero; Guid guid = new Guid("{0000010d-0000-0000-C000-000000000046}"); Marshal.QueryInterface(reObject.poleobj, ref guid, out pViewObject); IViewObject viewobject = (IViewObject)Marshal.GetTypedObjectForIUnknown(pViewObject, typeof(IViewObject)); int imgwidth = width; int imgheight = System.Convert.ToInt32(reObject.sizel.y * 1.0 / reObject.sizel.x * imgwidth); result = new Bitmap(imgwidth, imgheight); Rectangle imgRectangle = new Rectangle(0, 0, imgwidth, imgheight); using (Graphics g = Graphics.FromImage(result)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; IntPtr hdc = g.GetHdc(); viewobject.Draw(1, -1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, hdc, ref imgRectangle, ref imgRectangle, IntPtr.Zero, 0); g.ReleaseHdc(hdc); g.DrawRectangle(Pens.White, imgRectangle); } //Release the pViewObject Marshal.Release(pViewObject); } finally { Marshal.Release(reObject.poleobj); } } return(result); }
protected IRichEditOle GetRichEditOleInterface() { IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteIntPtr(ptr, IntPtr.Zero); try { if (0 != Win32.SendMessage(this.Handle, Messages.EM_GETOLEINTERFACE, IntPtr.Zero, ptr)) { IntPtr pRichEdit = Marshal.ReadIntPtr(ptr); try { if (pRichEdit != IntPtr.Zero) { Guid guid = new Guid("00020D00-0000-0000-c000-000000000046"); Marshal.QueryInterface(pRichEdit, ref guid, out this.IRichEditOlePtr); this.IRichEditOleValue = (IRichEditOle)Marshal.GetTypedObjectForIUnknown(this.IRichEditOlePtr, typeof(IRichEditOle)); if (this.IRichEditOleValue == null) { throw new Exception("获取接口IRichEditOle失败。"); } } else { throw new Exception("读取指针失败。"); } } finally { Marshal.Release(pRichEdit); } } else { throw new Exception("EM_GETOLEINTERFACE 消息失败。"); } } catch { this.ReleaseRichEditOleInterface(); } finally { Marshal.FreeCoTaskMem(ptr); } return(this.IRichEditOleValue); }
internal RichTextDocument(AeroRichEdit box, IRichEditOle ole) { if (box == null) { throw new ArgumentNullException("box"); } if (ole == null) { throw new ArgumentNullException("ole"); } _richEdit = box; //_richEditOle = ole; _textDocument = (ITextDocument)(ole); }
public Size GetObjectSize(Size defaultSize) { Size size = defaultSize; IRichEditOle richEditInterface = this.GetRichEditOleInterface(); if (richEditInterface.GetObjectCount() == 0) { return(size); } REOBJECT reObject = new REOBJECT(); // S_OK == 0, so 0 == success. if (0 == richEditInterface.GetObject(0, reObject, GetObjectOptions.REO_GETOBJ_POLEOBJ)) { try { IntPtr pViewObject = IntPtr.Zero; Guid guid = new Guid("{0000010d-0000-0000-C000-000000000046}"); Marshal.QueryInterface(reObject.poleobj, ref guid, out pViewObject); IViewObject viewobject = (IViewObject)Marshal.GetTypedObjectForIUnknown(pViewObject, typeof(IViewObject)); size = new Size(reObject.sizel.x, reObject.sizel.y); //Release the pViewObject Marshal.Release(pViewObject); } finally { Marshal.Release(reObject.poleobj); } } return(size); }
/// <summary> /// Releases the IRichEditOle interface if it hasn't been already. /// </summary> /// <remarks>This is automatically called in Dispose if needed.</remarks> public void ReleaseRichEditOleInterface() { if (this.IRichEditOlePtr != IntPtr.Zero) { Marshal.Release(this.IRichEditOlePtr); } this.IRichEditOlePtr = IntPtr.Zero; this.IRichEditOleValue = null; }
internal RichEditOle(RichTextBoxEx richEdit) { this.richTextBox = richEdit; this.ole = SendMessage(this.richTextBox.Handle, EM_GETOLEINTERFACE, 0); }
public IRichEditOle GetRichEditOleInterface() { if (IRichEditOleValue == null) { // Allocate the ptr that EM_GETOLEINTERFACE will fill in IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr))); // Alloc the ptr. Marshal.WriteIntPtr(ptr, IntPtr.Zero); // Clear it. try { if (0 != SendMessage(rtbHandle, Messages.EM_GETOLEINTERFACE, IntPtr.Zero, ptr)) { // Read the returned pointer IntPtr pRichEdit = Marshal.ReadIntPtr(ptr); try { if (pRichEdit != IntPtr.Zero) { // Query for the IRichEditOle interface Guid guid = new Guid("00020D00-0000-0000-c000-000000000046"); Marshal.QueryInterface(pRichEdit, ref guid, out IRichEditOlePtr); // Wrap it in the C# interface for IRichEditOle IRichEditOleValue = (IRichEditOle)Marshal.GetTypedObjectForIUnknown(IRichEditOlePtr, typeof(IRichEditOle)); if (IRichEditOleValue == null) { throw new Exception("Failed to get the object wrapper for the IRichEditOle interface."); } // IID_ITextDocument guid = new Guid("8CC497C0-A1DF-11CE-8098-00AA0047BE5D"); Marshal.QueryInterface(pRichEdit, ref guid, out ITextDocumentPtr); // Wrap it in the C# interface for IRichEditOle ITextDocumentValue = (ITextDocument)Marshal.GetTypedObjectForIUnknown(ITextDocumentPtr, typeof(ITextDocument)); if (ITextDocumentValue == null) { throw new Exception("Failed to get the object wrapper for the ITextDocument interface."); } } else { throw new Exception("Failed to get the pointer."); } } finally { Marshal.Release(pRichEdit); } } else { throw new Exception("EM_GETOLEINTERFACE failed."); } } catch (Exception) { //Trace.WriteLine(err.ToString()); ReleaseRichEditOleInterface(); } finally { // Free the ptr memory Marshal.FreeCoTaskMem(ptr); } } return(IRichEditOleValue); }