Beispiel #1
0
        /// Shows the Object Browser
        /// </summary>
        /// <returns></returns>
        protected virtual int ShowObjectBrowser()
        {
            if (String.IsNullOrEmpty(this.Url) || !System.IO.File.Exists(this.Url))
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }

            // Request unmanaged code permission in order to be able to creaet the unmanaged memory representing the guid.
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

            Guid   guid = GetBrowseLibraryGuid();
            IntPtr ptr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(guid.ToByteArray().Length);

            System.Runtime.InteropServices.Marshal.StructureToPtr(guid, ptr, false);
            int returnValue = VSConstants.S_OK;

            try
            {
                VSOBJECTINFO[] objInfo = new VSOBJECTINFO[1];
                ThreadHelper.ThrowIfNotOnUIThread();

                objInfo[0].pguidLib   = ptr;
                objInfo[0].pszLibName = this.Url;

                IVsObjBrowser objBrowser = this.ProjectMgr.Site.GetService(typeof(SVsObjBrowser)) as IVsObjBrowser;
                Assumes.Present(objBrowser);

                ErrorHandler.ThrowOnFailure(objBrowser.NavigateTo(objInfo, 0));
            }
            catch (COMException e)
            {
                XSettings.LogException(e, "ShowObjectBrowser");
                returnValue = e.ErrorCode;
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
                }
            }

            return(returnValue);
        }
        /// <summary>
        /// Shows the Object Browser
        /// </summary>
        /// <returns></returns>
        public virtual int ShowObjectBrowser()
        {
            if (!CanShowUrlInOnObjectBrowser())
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }

            // Request unmanaged code permission in order to be able to creaet the unmanaged memory representing the guid.
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();

            Guid   guid = GetBrowseLibraryGuid();
            IntPtr ptr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(guid.ToByteArray().Length);

            System.Runtime.InteropServices.Marshal.StructureToPtr(guid, ptr, false);

            int returnValue = VSConstants.S_OK;

            try
            {
                VSOBJECTINFO[] objInfo = new VSOBJECTINFO[1];

                objInfo[0].pguidLib   = ptr;
                objInfo[0].pszLibName = this.Url;

                IVsObjBrowser objBrowser = this.ProjectMgr.Site.GetService(typeof(SVsObjBrowser)) as IVsObjBrowser;

                ErrorHandler.ThrowOnFailure(objBrowser.NavigateTo(objInfo, 0));
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception" + e.ErrorCode);
                returnValue = e.ErrorCode;
            }
            finally
            {
                if (ptr != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
                }
            }

            return(returnValue);
        }
Beispiel #3
0
        /// <summary>
        /// Shows a referenced C#, VB, or VC project in the Object Browser.
        /// </summary>
        /// <returns>S_OK on success, else an error code.</returns>
        protected override int ShowObjectBrowser()
        {
            Guid browseGuid = this.GetBrowseGuid();

            if (browseGuid == Guid.Empty)
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }

            IntPtr guidPtr = IntPtr.Zero;

            try
            {
                guidPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Guid)));
                Marshal.StructureToPtr(browseGuid, guidPtr, false);

                VSOBJECTINFO[] objInfo = new VSOBJECTINFO[1];
                objInfo[0].pszLibName = this.ReferencedProjectName;
                objInfo[0].pguidLib   = guidPtr;

                IVsObjBrowser objBrowser = this.ProjectMgr.Site.GetService(typeof(SVsObjBrowser)) as IVsObjBrowser;
                ErrorHandler.ThrowOnFailure(objBrowser.NavigateTo(objInfo, 0));

                return(VSConstants.S_OK);
            }
            catch (COMException e)
            {
                return(e.ErrorCode);
            }
            finally
            {
                if (guidPtr != IntPtr.Zero)
                {
                    System.Runtime.InteropServices.Marshal.FreeCoTaskMem(guidPtr);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Shows the Object Browser
        /// </summary>
        /// <returns></returns>
        protected virtual int ShowObjectBrowser()
        {
            if (String.IsNullOrEmpty(this.Url) || !File.Exists(this.Url))
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }

            Guid   guid = VSConstants.guidCOMPLUSLibrary;
            IntPtr ptr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(guid.ToByteArray().Length);

            System.Runtime.InteropServices.Marshal.StructureToPtr(guid, ptr, false);
            int returnValue = VSConstants.S_OK;

            try
            {
                VSOBJECTINFO[] objInfo = new VSOBJECTINFO[1];

                objInfo[0].pguidLib   = ptr;
                objInfo[0].pszLibName = this.Url;

                IVsObjBrowser objBrowser = this.ProjectMgr.Site.GetService(typeof(SVsObjBrowser)) as IVsObjBrowser;

                ErrorHandler.ThrowOnFailure(objBrowser.NavigateTo(objInfo, 0));
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception" + e.ErrorCode);
                returnValue = e.ErrorCode;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.FreeCoTaskMem(ptr);
            }

            return(returnValue);
        }