public static IEnumerable <IMFActivate> EnumerateTransforms(Guid category) { IntPtr interfacesPointer; int interfaceCount; MediaFoundationInterop.MFTEnumEx(category, _MFT_ENUM_FLAG.MFT_ENUM_FLAG_ALL, null, null, out interfacesPointer, out interfaceCount); IMFActivate[] interfaces = new IMFActivate[interfaceCount]; for (int j = 0; j < interfaceCount; j++) { IntPtr pUnk = Marshal.ReadIntPtr(new IntPtr(interfacesPointer.ToInt64() + (long)(j * Marshal.SizeOf(interfacesPointer)))); interfaces[j] = (IMFActivate)Marshal.GetObjectForIUnknown(pUnk); } foreach (IMFActivate i in interfaces) { yield return(i); } Marshal.FreeCoTaskMem(interfacesPointer); yield break; }
//#if !NETFX_CORE /// <summary> /// Enumerate the installed MediaFoundation transforms in the specified category /// </summary> /// <param name="category">A category from MediaFoundationTransformCategories</param> /// <returns></returns> public static IEnumerable <IMFActivate> EnumerateTransforms(Guid category) { MediaFoundationInterop.MFTEnumEx(category, _MFT_ENUM_FLAG.MFT_ENUM_FLAG_ALL, null, null, out var interfacesPointer, out var interfaceCount); var interfaces = new IMFActivate[interfaceCount]; for (int n = 0; n < interfaceCount; n++) { var ptr = Marshal.ReadIntPtr(new IntPtr(interfacesPointer.ToInt64() + n * Marshal.SizeOf(interfacesPointer))); interfaces[n] = (IMFActivate)Marshal.GetObjectForIUnknown(ptr); } foreach (var i in interfaces) { yield return(i); } Marshal.FreeCoTaskMem(interfacesPointer); }