Ejemplo n.º 1
0
        public static bool TryGetValue(this ID2D1Properties properties, int index, out D2D1_PROPERTY_TYPE type, out byte[] data)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            data = null;
            type = properties.GetType(index);
            if (type == D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN)
            {
                return(false);
            }

            var size = properties.GetValueSize(index);

            if (size < 0)
            {
                return(false);
            }

            var bytes = new byte[size];
            var hr    = properties.GetValue(index, type, bytes, bytes.Length);

            if (hr.IsError)
            {
                return(false);
            }

            data = bytes;
            return(true);
        }
Ejemplo n.º 2
0
        public static object GetValue(D2D1_PROPERTY_TYPE type, byte[] data, bool throwOnError = true)
        {
            if (data == null)
            {
                if (throwOnError)
                {
                    throw new ArgumentNullException(nameof(data));
                }

                return(null);
            }

            switch (type)
            {
            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL:
                return(BitConverter.ToInt32(data, 0) != 0);

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_CLSID:
                return(new Guid(data));

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_ENUM:
            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_INT32:
                return(BitConverter.ToInt32(data, 0));

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UINT32:
                return(BitConverter.ToUInt32(data, 0));

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_FLOAT:
                return(BitConverter.ToSingle(data, 0));

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_STRING:
                // buffer contains a terminating zero
                return(Encoding.Unicode.GetString(data, 0, data.Length - 2));

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_VECTOR2:
                return(data.ToStructure <D2D_VECTOR_2F>());

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_VECTOR3:
                return(data.ToStructure <D2D_VECTOR_3F>());

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_VECTOR4:
                return(data.ToStructure <D2D_VECTOR_4F>());

            case D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_MATRIX_3X2:
                return(data.ToStructure <D2D_MATRIX_3X2_F>());

            default:
                if (throwOnError)
                {
                    throw new NotSupportedException("Value of type '" + type + "' is not supported.");
                }

                return(null);
            }
        }
Ejemplo n.º 3
0
        public virtual int GetValue(
            uint index,
            D2D1_PROPERTY_TYPE type,
            out byte data,
            uint dataSize
            )
        {
            var fp = GetFunctionPointer(11);

            if (m_GetValueFunc == null)
            {
                m_GetValueFunc = (GetValueFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(GetValueFunc));
            }

            return(m_GetValueFunc(m_ptr, index, type, out data, dataSize));
        }
Ejemplo n.º 4
0
        public virtual int GetValueByName(
            ref ushort name,
            D2D1_PROPERTY_TYPE type,
            out byte data,
            uint dataSize
            )
        {
            var fp = GetFunctionPointer(10);

            if (m_GetValueByNameFunc == null)
            {
                m_GetValueByNameFunc = (GetValueByNameFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(GetValueByNameFunc));
            }

            return(m_GetValueByNameFunc(m_ptr, ref name, type, out data, dataSize));
        }
Ejemplo n.º 5
0
        public static bool TryGetValue(this ID2D1Properties properties, string name, out D2D1_PROPERTY_TYPE type, out byte[] data)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            var index = properties.GetPropertyIndex(name);

            if (index < 0)
            {
                data = null;
                type = D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN;
                return(false);
            }

            return(TryGetValue(properties, index, out type, out data));
        }
Ejemplo n.º 6
0
 public HRESULT GetValue([NativeTypeName("UINT32")] uint index, D2D1_PROPERTY_TYPE type, byte *data, [NativeTypeName("UINT32")] uint dataSize)
 {
     return(((delegate * unmanaged <ID2D1Properties *, uint, D2D1_PROPERTY_TYPE, byte *, uint, int>)(lpVtbl[11]))((ID2D1Properties *)Unsafe.AsPointer(ref this), index, type, data, dataSize));
 }
Ejemplo n.º 7
0
 public HRESULT SetValueByName([NativeTypeName("PCWSTR")] ushort *name, D2D1_PROPERTY_TYPE type, [NativeTypeName("const BYTE *")] byte *data, [NativeTypeName("UINT32")] uint dataSize)
 {
     return(((delegate * unmanaged <ID2D1Properties *, ushort *, D2D1_PROPERTY_TYPE, byte *, uint, int>)(lpVtbl[8]))((ID2D1Properties *)Unsafe.AsPointer(ref this), name, type, data, dataSize));
 }
Ejemplo n.º 8
0
 public int GetValue([NativeTypeName("UINT32")] uint index, D2D1_PROPERTY_TYPE type, [NativeTypeName("BYTE *")] byte *data, [NativeTypeName("UINT32")] uint dataSize)
 {
     return(((delegate * unmanaged <ID2D1Effect *, uint, D2D1_PROPERTY_TYPE, byte *, uint, int>)(lpVtbl[11]))((ID2D1Effect *)Unsafe.AsPointer(ref this), index, type, data, dataSize));
 }
 public int SetValue([NativeTypeName("UINT32")] uint index, D2D1_PROPERTY_TYPE type, [NativeTypeName("const BYTE *")] byte *data, [NativeTypeName("UINT32")] uint dataSize)
 {
     return(((delegate * stdcall <ID2D1Properties *, uint, D2D1_PROPERTY_TYPE, byte *, uint, int>)(lpVtbl[9]))((ID2D1Properties *)Unsafe.AsPointer(ref this), index, type, data, dataSize));
 }
 public int GetValueByName([NativeTypeName("PCWSTR")] ushort *name, D2D1_PROPERTY_TYPE type, [NativeTypeName("BYTE *")] byte *data, [NativeTypeName("UINT32")] uint dataSize)
 {
     return(((delegate * stdcall <ID2D1Properties *, ushort *, D2D1_PROPERTY_TYPE, byte *, uint, int>)(lpVtbl[10]))((ID2D1Properties *)Unsafe.AsPointer(ref this), name, type, data, dataSize));
 }
Ejemplo n.º 11
0
 public static bool TryGetValue(this IComObject <ID2D1Properties> properties, int index, out D2D1_PROPERTY_TYPE type, out byte[] data) => TryGetValue(properties?.Object, index, out type, out data);
Ejemplo n.º 12
0
        public static void SetValueByName(this ID2D1Properties properties, string name, byte[] value, D2D1_PROPERTY_TYPE type = D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            properties.SetValueByName(name, type, value, value.Length).ThrowOnError();
        }