public IMFMediaEngineClassFactory()
 {
     ComUtilities.CreateComInstance(
         ClsidMFMediaEngineClassFactory,
         ComContext.InprocServer, typeof(IMFMediaEngineClassFactory).GUID,
         this);
 }
예제 #2
0
 public IWICImagingFactory2()
 {
     ComUtilities.CreateComInstance(
         WICImagingFactoryClsid,
         ComUtilities.CLSCTX.ClsctxInprocServer,
         typeof(IWICImagingFactory2).GUID,
         this);
 }
 public IWICImagingFactory()
 {
     ComUtilities.CreateComInstance(
         WICImagingFactoryClsid,
         ComContext.InprocServer,
         typeof(IWICImagingFactory).GUID,
         this);
 }
예제 #4
0
        bool IsEmptySelectionContext(IVsTrackSelectionEx selCtx)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Validate.IsNotNull(selCtx, "selCtx");
            IVsMonitorSelection2 monitorSelection2 = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection2;

            monitorSelection2.GetEmptySelectionContext(out var emptySelCtxt);
            return(ComUtilities.IsSameComObject(selCtx, emptySelCtxt));
        }
예제 #5
0
        /// <summary>
        /// Enumerate the window frames looking for the owner of the context
        /// </summary>
        /// <param name="selCtx"></param>
        /// <returns></returns>
        object GetContextOwner(IVsTrackSelectionEx selCtx)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (selCtx == null)
            {
                return(null);
            }

            // No frame owns the empty selection context, just return it as its own owner.
            if (IsEmptySelectionContext(selCtx))
            {
                return(selCtx);
            }

            IVsUIShell4 shell4 = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell4;

            Guid trackSelectionExServiceGuid = typeof(SVsTrackSelectionEx).GUID;
            Guid trackSelecitonExGuid        = typeof(IVsTrackSelectionEx).GUID;

            shell4.GetWindowEnum((uint)__WindowFrameTypeFlags.WINDOWFRAMETYPE_All, out var frameEnum);

            foreach (IVsWindowFrame frame in ComUtilities.EnumerableFrom(frameEnum))
            {
                if (ErrorHandler.Succeeded(frame.GetProperty((int)__VSFPROPID.VSFPROPID_SPFrame, out var frameServiceProvider)) && frameServiceProvider != null)
                {
                    IntPtr pTrackSelection = IntPtr.Zero;
                    try
                    {
                        if (ErrorHandler.Succeeded(((IOleServiceProvider)frameServiceProvider).QueryService(ref trackSelectionExServiceGuid, ref trackSelecitonExGuid, out pTrackSelection)))
                        {
                            IVsTrackSelectionEx frameCtx = Marshal.GetObjectForIUnknown(pTrackSelection) as IVsTrackSelectionEx;
                            if (ComUtilities.IsSameComObject(selCtx, frameCtx))
                            {
                                return(frame);
                            }
                        }
                    }
                    finally
                    {
                        if (pTrackSelection != IntPtr.Zero)
                        {
                            Marshal.Release(pTrackSelection);
                        }
                    }
                }
            }

            return(null);
        }
예제 #6
0
 public int GetProjrefOfItem(IVsHierarchy pHierarchy, uint itemid, out string pbstrProjref)
 {
     foreach (var project in _projects)
     {
         if (ComUtilities.IsSameComObject(pHierarchy, project.Value.Hierarchy))
         {
             ErrorHandler.ThrowOnFailure(project.Value.Hierarchy.GetCanonicalName(itemid, out global::System.String canonicalName));
             pbstrProjref = project.Value.ProjectGuid.ToString("B") + "|" + project.Value.Filename + "|" + canonicalName;
             return(VSConstants.S_OK);
         }
     }
     pbstrProjref = null;
     return(VSConstants.E_FAIL);
 }
        private IVsHierarchy FindSharedProject()
        {
            var              sln   = (IVsSolution)this.GetService(typeof(SVsSolution));
            Guid             empty = Guid.Empty;
            IEnumHierarchies enumHiers;

            ErrorHandler.ThrowOnFailure(sln.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref empty, out enumHiers));

            foreach (IVsHierarchy hier in ComUtilities.EnumerableFrom(enumHiers))
            {
                if (PackageUtilities.IsCapabilityMatch(hier, "SharedAssetsProject"))
                {
                    return(hier);
                }
            }

            return(null);
        }
예제 #8
0
파일: Misc.cs 프로젝트: mauroa/clide
        public void when_reopening_solution_then_vssolution_is_same()
        {
            var dte           = GlobalServices.GetService <DTE>();
            var solutionEmpty = GlobalServices.GetService <SVsSolution, IVsSolution>();

            dte.Solution.Open(new FileInfo(Constants.SingleProjectSolution).FullName);

            var solution1 = GlobalServices.GetService <SVsSolution, IVsSolution>();

            dte.Solution.Close();
            dte.Solution.Open(new FileInfo(Constants.BlankSolution).FullName);

            var solution2 = GlobalServices.GetService <SVsSolution, IVsSolution>();

            Assert.Same(solutionEmpty, solution1);
            Assert.Same(solution1, solution2);
            Assert.True(ComUtilities.IsSameComObject(solutionEmpty as IVsHierarchy, solution1 as IVsHierarchy));
            Assert.True(ComUtilities.IsSameComObject(solution1 as IVsHierarchy, solution2 as IVsHierarchy));
        }
예제 #9
0
        public void when_selection_is_item_then_active_hierarchy_is_owning_project()
        {
            var library = fixture.Solution.FindProject(x => x.Text == "CsLibrary");

            Assert.NotNull(library);

            var item = library.Nodes.OfType <IItemNode>().FirstOrDefault();

            item.Select();

            var active = explorer.Solution.ActiveProject;

            Assert.Equal(library, active);

            var selected = selection.GetSelection().FirstOrDefault();
            var identity = item.As <IVsHierarchyItem>().HierarchyIdentity;

            Assert.True(ComUtilities.IsSameComObject(selected.Hierarchy, identity.Hierarchy));
            Assert.Equal(selected.ItemID, identity.ItemID);
        }
예제 #10
0
        public void when_reopening_solution_then_vssolution_is_same()
        {
            var dte           = GlobalServices.GetService <DTE>();
            var solutionEmpty = GlobalServices.GetService <SVsSolution, IVsSolution>();

            var baseDir = Path.GetDirectoryName(GetType().Assembly.ManifestModule.FullyQualifiedName);

            dte.Solution.Open(Path.Combine(baseDir, Constants.SingleProjectSolution));

            var solution1 = GlobalServices.GetService <SVsSolution, IVsSolution>();

            dte.Solution.Close();
            dte.Solution.Open(Path.Combine(baseDir, Constants.BlankSolution));

            var solution2 = GlobalServices.GetService <SVsSolution, IVsSolution>();

            Assert.Same(solutionEmpty, solution1);
            Assert.Same(solution1, solution2);
            Assert.True(ComUtilities.IsSameComObject(solutionEmpty as IVsHierarchy, solution1 as IVsHierarchy));
            Assert.True(ComUtilities.IsSameComObject(solution1 as IVsHierarchy, solution2 as IVsHierarchy));
        }
예제 #11
0
        public void GetWorkers()
        {
            string[] progIDs =
            {
                "MicroStationDGN.Application"
            };
            List <object> results = ComUtilities.GetRunningCOMObjects(progIDs);

            if (results != null)
            {
                foreach (var result in results)
                {
                    var worker = new Worker()
                    {
                        IsEnabled     = true,
                        RunningObject = result
                    };
                    Workers.Add(worker);
                }
            }
        }
예제 #12
0
        public WindowFramesCollection(bool showDocumentWindowFrames, bool showToolWindowFrames)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();
            if (Package.GetGlobalService(typeof(SVsUIShell)) is IVsUIShell uiShell)
            {
                if (showDocumentWindowFrames)
                {
                    int hr = uiShell.GetDocumentWindowEnum(out IEnumWindowFrames enumWindowFrames);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        _vsWindowFrames = ComUtilities.EnumerableFrom(enumWindowFrames);
                    }
                }

                if (showToolWindowFrames)
                {
                    int hr = uiShell.GetToolWindowEnum(out IEnumWindowFrames enumWindowFrames);
                    if (ErrorHandler.Succeeded(hr))
                    {
                        _vsWindowFrames = _vsWindowFrames.Union(ComUtilities.EnumerableFrom(enumWindowFrames));
                    }
                }
            }
        }
예제 #13
0
        public static bool AddApplication(INetFwAuthorizedApplication application, out Exception exception)
        {
            var result     = false;
            var comObjects = new Stack <object>();

            exception = null;

            if (application == null)
            {
                throw (new ArgumentNullException("application"));
            }

            try
            {
                var type = Type.GetTypeFromProgID("HNetCfg.FwMgr", true);

                try
                {
                    var manager = (INetFwMgr)Activator.CreateInstance(type);
                    comObjects.Push(manager);

                    try
                    {
                        var policy = manager.LocalPolicy;
                        comObjects.Push(policy);

                        var profile = policy.CurrentProfile;
                        comObjects.Push(profile);

                        var applications = profile.AuthorizedApplications;
                        comObjects.Push(applications);

                        applications.Add(application);

                        result = true;
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                }
                catch (Exception e)
                {
                    exception = e;
                }
                finally
                {
                    while (comObjects.Count > 0)
                    {
                        ComUtilities.ReleaseComObject(comObjects.Pop());
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
            }

            return(result);
        }
예제 #14
0
 public IMMDeviceEnumerator()
 {
     ComUtilities.CreateComInstance(typeof(MMDeviceEnumeratorComObject).GUID, ComContext.InprocServer, typeof(IMMDeviceEnumerator).GUID, this);
 }
예제 #15
0
        public static bool RemoveApplication(string processImageFileName, out Exception exception)
        {
            var result     = false;
            var comObjects = new Stack <object>();

            exception = null;

            if (processImageFileName == null)
            {
                throw (new ArgumentNullException("processImageFileName"));
            }
            if (processImageFileName.Trim().Length == 0)
            {
                throw (new ArgumentException("The argument [processImageFileName] cannot be empty.", "processImageFileName"));
            }

            try
            {
                var type = Type.GetTypeFromProgID("HNetCfg.FwMgr", true);

                try
                {
                    var manager = (INetFwMgr)Activator.CreateInstance(type);
                    comObjects.Push(manager);

                    try
                    {
                        var policy = manager.LocalPolicy;
                        comObjects.Push(policy);

                        var profile = policy.CurrentProfile;
                        comObjects.Push(profile);

                        var applications = profile.AuthorizedApplications;
                        comObjects.Push(applications);

                        applications.Remove(processImageFileName);

                        result = true;
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                }
                catch (Exception e)
                {
                    exception = e;
                }
                finally
                {
                    while (comObjects.Count > 0)
                    {
                        ComUtilities.ReleaseComObject(comObjects.Pop());
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
            }

            return(result);
        }
예제 #16
0
        public static bool GetApplication(string processImageFileName, out INetFwAuthorizedApplication application, out Exception exception)
        {
            var result     = false;
            var comObjects = new Stack <object>();

            exception   = null;
            application = null;

            if (processImageFileName == null)
            {
                throw (new ArgumentNullException("processImageFileName"));
            }
            if (processImageFileName.Trim().Length == 0)
            {
                throw (new ArgumentException("The argument [processImageFileName] cannot be empty.", "processImageFileName"));
            }

            try
            {
                var type = Type.GetTypeFromProgID("HNetCfg.FwMgr", true);

                try
                {
                    var manager = (INetFwMgr)Activator.CreateInstance(type);
                    comObjects.Push(manager);

                    try
                    {
                        var policy = manager.LocalPolicy;
                        comObjects.Push(policy);

                        var profile = policy.CurrentProfile;
                        comObjects.Push(profile);

                        var applications = profile.AuthorizedApplications;
                        comObjects.Push(applications);

                        foreach (INetFwAuthorizedApplication app in applications)
                        {
                            comObjects.Push(app);

                            if (string.Compare(app.ProcessImageFileName, processImageFileName, true, CultureInfo.InvariantCulture) == 0)
                            {
                                result      = true;
                                application = NetFwAuthorizedApplication.FromINetFwAuthorizedApplication(app);

                                break;
                            }
                        }

                        if (!result)
                        {
                            throw (new Exception("The requested application was not found."));
                        }
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                }
                catch (Exception e)
                {
                    exception = e;
                }
                finally
                {
                    while (comObjects.Count > 0)
                    {
                        ComUtilities.ReleaseComObject(comObjects.Pop());
                    }
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
            }

            return(result);
        }
예제 #17
0
        public IXAudio2(XAudio2Flags flags, ProcessorSpecifier processorSpecifier, XAudio2Version requestedVersion = XAudio2Version.Default)
            : base(IntPtr.Zero)
        {
            var tryVersions = requestedVersion == XAudio2Version.Default
                ? new[] { XAudio2Version.Version29, XAudio2Version.Version28, XAudio2Version.Version27 }
                : new[] { requestedVersion };

            foreach (var tryVersion in tryVersions)
            {
                switch (tryVersion)
                {
                case XAudio2Version.Version27:
                    if (PlatformDetection.IsUAP)
                    {
                        throw new NotSupportedException("XAudio 2.7 is not supported on UAP platform");
                    }

                    Guid clsid = ((int)flags == 1) ? CLSID_XAudio27_Debug : CLSID_XAudio27;
                    if ((requestedVersion == XAudio2Version.Default || requestedVersion == XAudio2Version.Version27) &&
                        ComUtilities.TryCreateComInstance(clsid, ComContext.InprocServer, IID_IXAudio27, this))
                    {
                        SetupVtblFor27();
                        // Initialize XAudio2
                        Initialize(0, processorSpecifier);
                        Version = XAudio2Version.Version27;
                    }
                    break;

                case XAudio2Version.Version28:
                    try
                    {
                        NativePointer = XAudio28.XAudio2Create(0, processorSpecifier);
                        Version       = XAudio2Version.Version28;
                    }
                    catch (DllNotFoundException) { }
                    break;

                case XAudio2Version.Version29:
                    try
                    {
                        NativePointer = XAudio29.XAudio2Create(0, processorSpecifier);
                        Version       = XAudio2Version.Version29;
                    }
                    catch (DllNotFoundException) { }
                    break;
                }

                // Early exit if we found a requestedVersion
                if (Version != XAudio2Version.Default)
                {
                    break;
                }
            }

            if (Version == XAudio2Version.Default)
            {
                var versionStr = requestedVersion == XAudio2Version.Default ? "2.7, 2.8 or 2.9" : requestedVersion.ToString();
                throw new DllNotFoundException($"Unable to find XAudio2 dlls for requested versions [{versionStr}], not installed on this machine");
            }

            IXAudio2Voice.Version = Version;

            // Register engine callback
            _engineCallbackImpl = new EngineCallbackImpl(this);
            RegisterForCallbacks(_engineCallbackImpl);
        }