public BreakpointResolutionLocationCode(BP_RESOLUTION_LOCATION location, bool releaseComObjects) { if (location.bpType != (uint)enum_BP_TYPE.BPT_CODE) { throw new ArgumentException(); } try { if (location.unionmember1 != IntPtr.Zero) { _codeContext = Marshal.GetObjectForIUnknown(location.unionmember1) as IDebugCodeContext2; } } finally { if (releaseComObjects && location.unionmember1 != IntPtr.Zero) { Marshal.Release(location.unionmember1); } } }
protected virtual IVsTextLines GetTextBuffer(System.IntPtr docDataExisting, string filename) { IVsTextLines textLines; if (docDataExisting == IntPtr.Zero) { // Create a new IVsTextLines buffer. Type textLinesType = typeof(IVsTextLines); Guid riid = textLinesType.GUID; Guid clsid = typeof(VsTextBufferClass).GUID; textLines = _package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines; // set the buffer's site ((IObjectWithSite)textLines).SetSite(_serviceProvider.GetService(typeof(IOleServiceProvider))); } else { // Use the existing text buffer Object dataObject = Marshal.GetObjectForIUnknown(docDataExisting); textLines = dataObject as IVsTextLines; if (textLines == null) { // Try get the text buffer from textbuffer provider IVsTextBufferProvider textBufferProvider = dataObject as IVsTextBufferProvider; if (textBufferProvider != null) { textBufferProvider.GetTextBuffer(out textLines); } } if (textLines == null) { // Unknown docData type then, so we have to force VS to close the other editor. throw Marshal.GetExceptionForHR(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } } return(textLines); }