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); } } }
/// <summary> /// /// </summary> /// <param name="grfCreateDoc"></param> /// <param name="pszMkDocument"></param> /// <param name="pszPhysicalView"></param> /// <param name="pvHier"></param> /// <param name="itemid"></param> /// <param name="punkDocDataExisting"></param> /// <param name="ppunkDocView"></param> /// <param name="ppunkDocData"></param> /// <param name="pbstrEditorCaption"></param> /// <param name="pguidCmdUI"></param> /// <param name="pgrfCDW"></param> /// <returns></returns> public virtual int CreateEditorInstance( uint createEditorFlags, string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IntPtr docDataExisting, out IntPtr docView, out IntPtr docData, out string editorCaption, out Guid commandUIGuid, out int createDocumentWindowFlags) { // Initialize output parameters docView = IntPtr.Zero; docData = IntPtr.Zero; commandUIGuid = Guid.Empty; createDocumentWindowFlags = 0; editorCaption = null; // Validate inputs if ((createEditorFlags & (uint)(VSConstants.CEF.OpenFile | VSConstants.CEF.Silent)) == 0) { return(VSConstants.E_INVALIDARG); } if (docDataExisting != IntPtr.Zero && _promptEncodingOnLoad) { return(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } // Get a text buffer IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker); // Assign docData IntPtr to either existing docData or the new text buffer if (docDataExisting != IntPtr.Zero) { docData = docDataExisting; Marshal.AddRef(docData); } else { docData = Marshal.GetIUnknownForObject(textLines); } try { object docViewObject = CreateDocumentView(documentMoniker, physicalView, hierarchy, itemid, textLines, docDataExisting == IntPtr.Zero, out editorCaption, out commandUIGuid); docView = Marshal.GetIUnknownForObject(docViewObject); } finally { if (docView == IntPtr.Zero) { if (docDataExisting != docData && docData != IntPtr.Zero) { // Cleanup the instance of the docData that we have addref'ed Marshal.Release(docData); docData = IntPtr.Zero; } } } return(VSConstants.S_OK); }