/// <summary> /// Converts the attribute store's contents to a memory buffer. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="buffer">Receives a memory buffer filled with attribute data.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetAttributesAsBlob(this IMFAttributes attributes, out MemoryBuffer buffer) { if (attributes == null) { throw new ArgumentNullException("attributes"); } buffer = null; int sizeInBytes; HResult hr = MFExtern.MFGetAttributesAsBlobSize(attributes, out sizeInBytes); if (hr.Succeeded()) { MemoryBuffer result = new MemoryBuffer((uint)sizeInBytes); hr = MFExtern.MFGetAttributesAsBlob(attributes, result.BufferPointer, (int)result.ByteLength); if (hr.Succeeded()) { buffer = result; } else { result.Dispose(); } } return(hr); }
/// <summary> /// Converts the attribute store's contents to a byte array. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="buffer">Receives a byte array filled with attribute data.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetAttributesAsBlob(this IMFAttributes attributes, out byte[] buffer) { if (attributes == null) { throw new ArgumentNullException("attributes"); } buffer = null; int sizeInBytes; HResult hr = MFExtern.MFGetAttributesAsBlobSize(attributes, out sizeInBytes); if (hr.Succeeded()) { byte[] result = new byte[sizeInBytes]; using (GCPin pin = new GCPin(result)) { hr = MFExtern.MFGetAttributesAsBlob(attributes, pin.PinnedAddress, result.Length); if (hr.Succeeded()) { buffer = result; } } } return(hr); }
public static HResult GetEnableData(this IMFContentEnabler contentEnabler, out byte[] data) { if (contentEnabler == null) { throw new ArgumentNullException("contentEnabler"); } IntPtr dataPtr; int dataLength; HResult hr = contentEnabler.GetEnableData(out dataPtr, out dataLength); if (hr.Succeeded()) { try { data = new byte[dataLength]; Marshal.Copy(dataPtr, data, 0, dataLength); } finally { Marshal.FreeCoTaskMem(dataPtr); } } else { data = null; } return(hr); }
/// <summary> /// Gets a copy of the current image being displayed by the video renderer. /// </summary> /// <param name="videoDisplayControl">A valid IMFVideoDisplayControl instance.</param> /// <param name="bih">A BitmapInfoHeader class that receives a description of the bitmap. </param> /// <param name="dib">Receives byte array that contains a packed Windows device-independent bitmap (DIB).</param> /// <param name="timeStamp">Receives the time stamp of the captured image.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetCurrentImage(this IMFVideoDisplayControl videoDisplayControl, BitmapInfoHeader bih, out byte[] dib, out TimeSpan timeStamp) { if (videoDisplayControl == null) { throw new ArgumentNullException("videoDisplayControl"); } IntPtr dibPtr; int dibLength; long time; HResult hr = videoDisplayControl.GetCurrentImage(bih, out dibPtr, out dibLength, out time); if (hr.Succeeded()) { try { dib = new byte[dibLength]; Marshal.Copy(dibPtr, dib, 0, dibLength); timeStamp = TimeSpan.FromTicks(time); } finally { Marshal.FreeCoTaskMem(dibPtr); } } else { dib = null; timeStamp = TimeSpan.MinValue; } return(hr); }
public PropertyOrigin GetThemePropertyOrigin(int partId, int stateId, int propertyId) { HResult hr = StyleNativeMethods.GetThemePropertyOrigin( theme, partId, stateId, propertyId, out PropertyOrigin origin); return(hr.Succeeded() ? origin : PropertyOrigin.NotFound); }
/// <summary> /// Retrieves an attribute at the specified index. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="index">The index to retrieve.</param> /// <param name="guidKey">The key of this attribute.</param> /// <param name="value">The value of this attribute.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetItemByIndex(this IMFAttributes attributes, int index, out Guid guidKey, out object value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } if (index < 0) { throw new ArgumentOutOfRangeException("index"); } HResult hr = 0; value = null; using (PropVariant variant = new PropVariant()) { hr = attributes.GetItemByIndex(index, out guidKey, variant); if (hr.Succeeded()) { value = variant.GetObject(); } } return(hr); }
public IntPtr?GetThemeBitmap(int partId, int stateId, int propertyId) { HResult hr = UxThemeExNativeMethods.UxGetThemeBitmap( themeFile, theme, partId, stateId, propertyId, GBF.GBF_DIRECT, out IntPtr value); return(hr.Succeeded() ? value : (IntPtr?)null); }
/// <summary> /// Retrieves a byte array associated with a key. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="guidKey">Guid that identifies which value to retrieve.</param> /// <param name="value">Receives the byte array.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetAllocatedBlob(this IMFAttributes attributes, Guid guidKey, out byte[] value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } IntPtr resultPtr; int resultLength; HResult hr = attributes.GetAllocatedBlob(guidKey, out resultPtr, out resultLength); if (hr.Succeeded()) { try { value = new byte[resultLength]; Marshal.Copy(resultPtr, value, 0, resultLength); } finally { Marshal.FreeCoTaskMem(resultPtr); } } else { value = null; } return(hr); }
public static Guid GetDteClsid(IHostPlugin serviceProvider) { try { var localRegistry4 = serviceProvider.GetService <SLocalRegistry>() as ILocalRegistry4; var pdwRegRootHandle = 0U; if (localRegistry4 != null) { string pbstrRoot; if (HResult.Succeeded(localRegistry4.GetLocalRegistryRootEx(2U, out pdwRegRootHandle, out pbstrRoot))) { switch (pdwRegRootHandle) { case 2147483649U: using (var registryKey = Registry.CurrentUser.OpenSubKey(pbstrRoot)) { if (registryKey != null) { var obj = registryKey.GetValue("ThisVersionDTECLSID"); if (obj is string) { Guid result; if (Guid.TryParse((string)obj, out result)) { return(result); } } } break; } case 2147483650U: using (var registryKey = Registry.LocalMachine.OpenSubKey(pbstrRoot)) { if (registryKey != null) { var obj = registryKey.GetValue("ThisVersionDTECLSID"); if (obj is string) { Guid result; if (Guid.TryParse((string)obj, out result)) { return(result); } } } break; } } } } } catch (Exception ex) { TeamFoundationTrace.TraceAndDebugFailException(ex); } return(new Guid()); }
public static bool IsExpanded(IVsHierarchy hierarchy, uint itemId) { object pvar; if (!HResult.Succeeded(hierarchy.GetProperty(itemId, -2035, out pvar))) { return(false); } return((bool)pvar); }
private void OnPlanComplete(object sender, PlanCompleteEventArgs e) { if (HResult.Succeeded(e.Status)) { _engine.Apply(OnUIThread(() => Application.Current.MainWindow != null ? new WindowInteropHelper(Application.Current.MainWindow).EnsureHandle() : IntPtr.Zero)); } else { _completedStepVmFactory.GetViewModelInstance().ExitCode = e.Status; _completedStepVmFactory.GetViewModelInstance().Result = Cancelled ? OperationResult.Cancelled : OperationResult.Failed; } }
private void PlanComplete(object sender, PlanCompleteEventArgs e) { if (HResult.Succeeded(e.Status)) { PreApplyState = State; State = InstallationState.Applying; App.Current.Apply(); } else { State = InstallationState.Failed; } }
public static string GetFullFriendlyName(this Type type) { if (type.IsUnknownCOMObject()) { string progID; var clsid = type.GUID; if (HResult.Succeeded(NativeMethods.ProgIDFromCLSID(ref clsid, out progID))) { return(progID); } } return(type.GetFriendlyName(GetFullRootName)); }
/// <summary> /// Retrieves the last clock time that was correlated with system time. /// </summary> /// <param name="clock">A valid IMFClock instance.</param> /// <param name="clockTime">Receives the last known clock time, in units of the clock's frequency.</param> /// <param name="systemTime">Receives the system time that corresponds to the clock time.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetCorrelatedTime(this IMFClock clock, out long clockTime, out TimeSpan systemTime) { if (clock == null) { throw new ArgumentNullException("clock"); } long tmp; HResult hr = clock.GetCorrelatedTime(0, out clockTime, out tmp); systemTime = hr.Succeeded() ? TimeSpan.FromTicks(tmp) : default(TimeSpan); return(hr); }
/// <summary> /// Creates an instance of the capture engine. /// </summary> /// <param name="factory">A valid IMFCaptureEngineClassFactory instance.</param> /// <param name="engine">Receives an instance of the capture engine.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult CreateInstance(this IMFCaptureEngineClassFactory factory, out IMFCaptureEngine engine) { if (factory == null) { throw new ArgumentNullException("factory"); } object tmp; HResult hr = factory.CreateInstance(CLSID.CLSID_MFCaptureEngine, typeof(IMFCaptureEngine).GUID, out tmp); engine = hr.Succeeded() ? tmp as IMFCaptureEngine : null; return(hr); }
/// <summary> /// Reads the next sample from the media source. /// </summary> /// <param name="sourceReader">A valid IMFSourceReader instance.</param></param></param> /// <param name="streamIndex">The stream to pull data from.</param> /// <param name="controlFlags">One or more members of the MF_SOURCE_READER_CONTROL_FLAG enumeration.</param> /// <param name="actualStreamIndex">Receives the zero-based index of the stream.</param> /// <param name="streamFlags">Receives one or more members of the MF_SOURCE_READER_FLAG enumeration.</param> /// <param name="timestamp">Receives the time stamp of the sample, or the time of the stream event indicated in <paramref name="streamFlags"/>.</param> /// <param name="sample">Receives an instance of the IMFSample interface or the value null.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult ReadSample(this IMFSourceReader sourceReader, SourceReaderStreams streamIndex, MF_SOURCE_READER_CONTROL_FLAG controlFlags, out int actualStreamIndex, out MF_SOURCE_READER_FLAG streamFlags, out TimeSpan timestamp, out IMFSample sample) { if (sourceReader == null) { throw new ArgumentNullException("sourceReader"); } long tmp = 0; HResult hr = sourceReader.ReadSample((int)streamIndex, controlFlags, out actualStreamIndex, out streamFlags, out tmp, out sample); timestamp = hr.Succeeded() ? TimeSpan.FromTicks(tmp) : default(TimeSpan); return(hr); }
/// <summary> /// Retrieves a UInt32 value associated with a key. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="guidKey">Guid that identifies which value to retrieve.</param> /// <param name="value">Receives the requested value.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetUINT32(this IMFAttributes attributes, Guid guidKey, out uint value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } int result = 0; HResult hr = attributes.GetUINT32(guidKey, out result); value = hr.Succeeded() ? (uint)result : default(uint); return(hr); }
/// <summary> /// Gets the start time for a specified time range. /// </summary> /// <param name="mediaTimeRange">A valid IMFMediaTimeRange instance.</param> /// <param name="index">The zero-based index of the time range to query.</param> /// <param name="end">Receives the start time.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetStart(this IMFMediaTimeRange mediaTimeRange, int index, TimeSpan start) { if (mediaTimeRange == null) { throw new ArgumentNullException("mediaTimeRange"); } double result; HResult hr = mediaTimeRange.GetStart(index, out result); start = hr.Succeeded() ? TimeSpan.FromSeconds(result) : default(TimeSpan); return(hr); }
/// <summary> /// Gets the latest clock time. /// </summary> /// <param name="presentationClock">A valid IMFPresentationClock instance.</param> /// <param name="clockTime">Receives the latest clock time.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetTime(this IMFPresentationClock presentationClock, out TimeSpan clockTime) { if (presentationClock == null) { throw new ArgumentNullException("presentationClock"); } long tmp; HResult hr = presentationClock.GetTime(out tmp); clockTime = hr.Succeeded() ? TimeSpan.FromTicks(tmp) : default(TimeSpan); return(hr); }
/// <summary> /// Retrieves the presentation time of the sample. /// </summary> /// <param name="sample">A valid IMFSample instance.</param> /// <param name="sampleTime">Receives the presentation time.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetSampleTime(this IMFSample sample, out TimeSpan sampleTime) { if (sample == null) { throw new ArgumentNullException("sample"); } long tmp; HResult hr = sample.GetSampleDuration(out tmp); sampleTime = hr.Succeeded() ? TimeSpan.FromTicks(tmp) : default(TimeSpan); return(hr); }
/// <summary> /// Queries the underlying Sink Writer object. /// </summary> /// <param name="captureSink">A valid IMFCaptureSink instance.</param> /// <param name="sinkStreamIndex">The zero-based index of the streamIndex to query. The index is returned in the sinkStreamIndex parameter of the <see cref="IMFCaptureSink.AddStream"/> method.</param> /// <param name="sourceReader">Receives an instance of the underlying Sink Writer.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetService(this IMFCaptureSink captureSink, int sinkStreamIndex, out IMFSinkWriter sinkWriter) { if (captureSink == null) { throw new ArgumentNullException("captureSink"); } object tmp; HResult hr = captureSink.GetService(sinkStreamIndex, Guid.Empty, typeof(IMFSinkWriterExtensions).GUID, out tmp); sinkWriter = hr.Succeeded() ? tmp as IMFSinkWriter : null; return(hr); }
/// <summary> /// Creates an instance of the sink writer, given an IMFByteStream instance. /// </summary> /// <param name="factory">A valid IMFReadWriteClassFactory instance.</param> /// <param name="mediaSink">A byte streamIndex used by the sink writer to write data.</param> /// <param name="attributes">A instance to the IMFAttributes interface. You can use this parameter to configure the sink writer.</param> /// <param name="sourceReader">Receives the sink writer.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult CreateInstanceFromObject(this IMFReadWriteClassFactory factory, IMFByteStream byteStream, IMFAttributes attributes, out IMFSinkWriter sinkWriter) { if (factory == null) { throw new ArgumentNullException("factory"); } object tmp; HResult hr = factory.CreateInstanceFromObject(CLSID.CLSID_MFSinkWriter, byteStream, attributes, typeof(IMFSinkWriterExtensions).GUID, out tmp); sinkWriter = hr.Succeeded() ? tmp as IMFSinkWriter : null; return(hr); }
/// <summary> /// Retrieves a Boolean value associated with a key. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="guidKey">Guid that identifies which value to retrieve.</param> /// <param name="value">Receives the requested value.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> /// <remarks>Media Foundation attributes don't support boolean values. This method get them as a 32-bits unsigned integer and return true for any non-zero value and false otherwise.</remarks> public static HResult GetBoolean(this IMFAttributes attributes, Guid guidKey, out bool value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } uint result; HResult hr = attributes.GetUINT32(guidKey, out result); value = hr.Succeeded() ? (result != 0) : default(bool); return(hr); }
/// <summary> /// Gets the duration of the media item. /// </summary> /// <param name="mediaItem">A valid IMFPMediaItem instance.</param> /// <param name="durationValue">Receives the duration.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetDuration(this IMFPMediaItem mediaItem, out TimeSpan durationValue) { if (mediaItem == null) { throw new ArgumentNullException("mediaItem"); } using (PropVariant result = new PropVariant()) { HResult hr = mediaItem.GetDuration(Guid.Empty, result); durationValue = hr.Succeeded() ? TimeSpan.FromTicks((long)result.GetULong()) : default(TimeSpan); return(hr); } }
/// <summary> /// Creates an instance of the source reader given a URL. /// </summary> /// <param name="factory">A valid IMFReadWriteClassFactory instance.</param> /// <param name="url">A string that specifies the input file for the source reader.</param> /// <param name="attributes">A instance to the IMFAttributes interface. You can use this parameter to configure the source reader.</param></param> /// <param name="sourceReader">Receives the source reader</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult CreateInstanceFromURL(this IMFReadWriteClassFactory factory, string url, IMFAttributes attributes, out IMFSourceReader sourceReader) { if (factory == null) { throw new ArgumentNullException("factory"); } object tmp; HResult hr = factory.CreateInstanceFromURL(CLSID.CLSID_MFSourceReader, url, attributes, typeof(IMFSourceReader).GUID, out tmp); sourceReader = hr.Succeeded() ? tmp as IMFSourceReader : null; return(hr); }
/// <summary> /// Gets a pointer to the underlying Source Reader object. /// </summary> /// <param name="captureSource">A valid IMFCaptureSource instance.</param> /// <param name="sourceReader">Receives an instance of the underlying Source Reader.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetService(this IMFCaptureSource captureSource, out IMFSourceReader sourceReader) { if (captureSource == null) { throw new ArgumentNullException("captureSource"); } object tmp; HResult hr = captureSource.GetService(Guid.Empty, typeof(IMFSourceReader).GUID, out tmp); sourceReader = hr.Succeeded() ? tmp as IMFSourceReader : null; return(hr); }
public static HResult GetObject(this IMFTopologyNode topologyNode, out IMFActivate activate) { if (topologyNode == null) { throw new ArgumentNullException("topologyNode"); } object tmp; HResult hr = topologyNode.GetObject(out tmp); activate = hr.Succeeded() ? tmp as IMFActivate : null; return(hr); }
public static HResult GetObject(this IMFTopologyNode topologyNode, out IMFStreamSink streamSink) { if (topologyNode == null) { throw new ArgumentNullException("topologyNode"); } object tmp; HResult hr = topologyNode.GetObject(out tmp); streamSink = hr.Succeeded() ? tmp as IMFStreamSink : null; return(hr); }
/// <summary> /// Retrieves a <see cref="MemoryBuffer"/> associated with a key. /// </summary> /// <param name="attributes">A valid IMFAttributes instance.</param> /// <param name="guidKey">Guid that identifies which value to retrieve.</param> /// <param name="value">Receives a MemoryBuffer wrapping the attribute content.</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult GetAllocatedBlob(this IMFAttributes attributes, Guid guidKey, out MemoryBuffer value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } IntPtr resultPtr; int resultLength; HResult hr = attributes.GetAllocatedBlob(guidKey, out resultPtr, out resultLength); value = hr.Succeeded() ? new MemoryBuffer(resultPtr, (uint)resultLength) : null; return(hr); }
public static object GetService(IServiceProvider provider, Guid serviceGuid) { var riid = VSConstants.IID_IUnknown; IntPtr ppvObject; if (!HResult.Succeeded(provider.QueryService(ref serviceGuid, ref riid, out ppvObject))) { return(null); } try { return(Marshal.GetObjectForIUnknown(ppvObject)); } finally { Marshal.Release(ppvObject); } }