/// <summary>
        /// Creates a collection of activated Parts for the specified interface.
        /// </summary>
        /// <typeparam name="T">The type of the interface.</typeparam>
        /// <param name="comIId">The COM interface ID.</param>
        /// <returns>A collection of PartActivation objects using the specified interface.</returns>
        public static IEnumerable <PartActivation <T> > CreatePartActivationCollection <T>(string comIId)
        {
            object objInstance;
            var    iid            = new Guid(comIId);
            var    activationList = new List <PartActivation <T> >();
            var    partList       = CreateIPartCollection();

            foreach (var part in partList)
            {
                var result = part.Activate((uint)CLSCTX.CLSCTX_INPROC_SERVER, ref iid, out objInstance);
                if ((uint)result == HRESULTS.E_NOINTERFACE)
                {
                    continue;
                }

                AssertCoreAudio.IsHResultOk(result);
                activationList.Add(new PartActivation <T>
                {
                    Part            = part,
                    ActiveInterface = (T)objInstance
                });
            }

            if (!activationList.Any())
            {
                Assert.Inconclusive("The test may not have run properly. No interface instances were found for the specified type.");
            }

            return(activationList);
        }
        /// <summary>
        /// Creates a collection of activated MMDevices for the specified interface.
        /// </summary>
        /// <typeparam name="T">The type of the interface.</typeparam>
        /// <param name="comIId">The COM interface ID.</param>
        /// <returns>A collection of DeviceActivation objects using the specified interface.</returns>
        public static IEnumerable <DeviceActivation <T> > CreateDeviceActivationCollection <T>(string comIId)
        {
            object objInstance;
            var    iid            = new Guid(comIId);
            var    activationList = new List <DeviceActivation <T> >();
            var    activeDevices  = CreateIMMDeviceCollection(EDataFlow.eAll, DEVICE_STATE_XXX.DEVICE_STATE_ACTIVE);

            foreach (var device in activeDevices)
            {
                var result = device.Activate(iid, (uint)CLSCTX.CLSCTX_INPROC_SERVER, IntPtr.Zero, out objInstance);
                AssertCoreAudio.IsHResultOk(result);

                if (objInstance != null)
                {
                    activationList.Add(new DeviceActivation <T>
                    {
                        MMDevice        = device,
                        ActiveInterface = (T)objInstance
                    });
                }
            }

            if (!activationList.Any())
            {
                Assert.Inconclusive("The test cannot be run properly. No interface instances were found for the specified type.");
            }

            return(activationList);
        }
        /// <summary>
        /// Creates a collection of the given interface via the IAudioClient GetService method.
        /// </summary>
        /// <typeparam name="T">The type of the interface.</typeparam>
        /// <param name="comIId">The COM interface ID.</param>
        /// <param name="exclusiveMode">A value indicating whether or not to use exclusive mode.</param>
        /// <param name="streamFlags">The stream initialization flags.</param>
        /// <returns>A collection of audio clients with services implementing the specified interface.</returns>
        public static IEnumerable <AudioClientService <T> > CreateAudioClientServiceCollection <T>(string comIId, bool exclusiveMode, UInt32 streamFlags)
        {
            object objInstance;
            var    iid           = new Guid(comIId);
            var    interfaceList = new List <AudioClientService <T> >();
            var    audioClients  = ActivateFromIMMDevice <IAudioClient>(ComIIDs.IAudioClientIID);

            foreach (var ac in audioClients)
            {
                var shareMode = exclusiveMode ? AUDCLNT_SHAREMODE.AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE.AUDCLNT_SHAREMODE_SHARED;
                var formatPtr = GetFormatPointer(ac, shareMode);
                if (formatPtr == IntPtr.Zero)
                {
                    continue;
                }

                var context = Guid.NewGuid();
                var result  = ac.Initialize(shareMode, streamFlags, 5000000, 0, formatPtr, context);
                if (IsWasapiError(result))
                {
                    continue;
                }
                AssertCoreAudio.IsHResultOk(result);

                result = ac.GetService(iid, out objInstance);
                if ((uint)result == HRESULTS.E_NOINTERFACE)
                {
                    continue;
                }
                if (IsWasapiError(result))
                {
                    continue;
                }
                AssertCoreAudio.IsHResultOk(result);

                interfaceList.Add(new AudioClientService <T>
                {
                    AudioClient      = ac,
                    ServiceInterface = (T)objInstance,
                    EventContext     = context,
                    ShareMode        = shareMode
                });
            }

            if (!interfaceList.Any())
            {
                Assert.Inconclusive("The test may not have run properly. No interface instances were found for the specified type.");
            }

            return(interfaceList);
        }