public static void SetFormat(this IAMStreamConfig cfg, AmMediaType media) { int size = Marshal.SizeOf(media); IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(media.GetType())); Marshal.StructureToPtr(media, ptr, false); uint hresult = (uint)cfg.SetFormat(ptr); if (0x8007000E == hresult) throw new OutOfMemoryException(); else if (0x80040209 == hresult) throw new Exception("The input pin is not connected."); Marshal.FreeCoTaskMem(ptr); }
public static AmMediaType GetFormat(this IAMStreamConfig cfg) { AmMediaType mtype = new AmMediaType(); IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(mtype)); uint hresult = (uint)cfg.GetFormat(ptr); if (0x8007000E == hresult) throw new OutOfMemoryException(); else if (0x80040209 == hresult) throw new Exception("The input pin is not connected."); Marshal.PtrToStructure(ptr, mtype); Marshal.FreeCoTaskMem(ptr); return mtype; }