Пример #1
0
        protected byte GetByteValue(Guid guidPropSet, uint propId)
        {
            Guid           propertyGuid    = guidPropSet;
            IKsPropertySet propertySet     = captureFilter as IKsPropertySet;
            uint           IsTypeSupported = 0;
            uint           uiSize;

            if (propertySet == null)
            {
                //throw new ApplicationException("GetByteValue() properySet=null");
                return(0);
            }
            int hr = propertySet.QuerySupported(ref propertyGuid, propId, out IsTypeSupported);

            if (hr != 0 || (IsTypeSupported & (uint)KsPropertySupport.Get) == 0)
            {
                //throw new ApplicationException("GetByteValue() property is not supported");
                return(0);
            }

            byte           returnValue      = 0;
            KSPROPERTYByte propByte         = new KSPROPERTYByte();
            KSPROPERTY     prop             = new KSPROPERTY();
            int            sizeProperty     = Marshal.SizeOf(prop);
            int            sizeByteProperty = Marshal.SizeOf(propByte);

            KSPROPERTYByte newByteValue  = new KSPROPERTYByte();
            IntPtr         pDataReturned = Marshal.AllocCoTaskMem(100);

            Marshal.StructureToPtr(newByteValue, pDataReturned, true);

            int    adress  = pDataReturned.ToInt32() + sizeProperty;
            IntPtr ptrData = new IntPtr(adress);

            hr = propertySet.RemoteGet(ref propertyGuid,
                                       propId,
                                       ptrData,
                                       (uint)(sizeByteProperty - sizeProperty),
                                       pDataReturned,
                                       (uint)sizeByteProperty,
                                       out uiSize);
            if (hr == 0 && uiSize == 1)
            {
                returnValue = Marshal.ReadByte(ptrData);
            }
            Marshal.FreeCoTaskMem(pDataReturned);

            if (hr != 0)
            {
                //throw new ApplicationException("GetByteValue() failed 0x{0:X}", hr);
            }
            return(returnValue);
        }
Пример #2
0
        protected void SetByteValue(Guid guidPropSet, uint propId, byte byteValue)
        {
            Guid           propertyGuid = guidPropSet;
            IKsPropertySet propertySet  = captureFilter as IKsPropertySet;

            if (propertySet == null)
            {
                //throw new ApplicationException("GetByteValue() properySet=null");
                return;
            }
            uint IsTypeSupported = 0;

            int hr = propertySet.QuerySupported(ref propertyGuid, propId, out IsTypeSupported);

            if (hr != 0 || (IsTypeSupported & (uint)KsPropertySupport.Set) == 0)
            {
                // throw new ApplicationException("SetByteValue() property is not supported");
                return;
            }

            KSPROPERTYByte KsProperty = new KSPROPERTYByte();

            KsProperty.byData = byteValue;
            IntPtr pDataReturned = Marshal.AllocCoTaskMem(100);

            Marshal.StructureToPtr(KsProperty, pDataReturned, false);
            hr = propertySet.RemoteSet(ref propertyGuid,
                                       propId,
                                       pDataReturned,
                                       1,
                                       pDataReturned,
                                       (uint)Marshal.SizeOf(KsProperty));
            Marshal.FreeCoTaskMem(pDataReturned);

            if (hr != 0)
            {
                //throw new ApplicationException("SetByteValue() failed 0x{0:X}", hr);
            }
        }