コード例 #1
0
        private int GetCount()
        {
            uint count;

            HResult.Try(_propertyStoreInterface.GetCount(out count));
            return((int)count);
        }
コード例 #2
0
        private                                         T[] GetSafeArray <T>()
        {
            var dimCount = (uint)HResult.Try(NativeMethods.OleAut32.SafeArrayGetDim(pointerUnion.Pointer1)).SuccessValue;

            if (dimCount > 1)
            {
                throw new NotSupportedException("Multidimensional SafeArrays are not supported.");
            }

            int lBound, uBound;

            HResult.Try(NativeMethods.OleAut32.SafeArrayGetLBound(pointerUnion.Pointer1, dimCount, out lBound));
            HResult.Try(NativeMethods.OleAut32.SafeArrayGetUBound(pointerUnion.Pointer1, dimCount, out uBound));
            var elemCount = uBound - lBound + 1;

            var result = new T[elemCount];
            var index  = new int[1];

            for (var i = 0; i < elemCount; i++)
            {
                index[0] = lBound + i;
                object element;
                HResult.Try(NativeMethods.OleAut32.SafeArrayGetElement(pointerUnion.Pointer1, index, out element));
                result[i] = (T)element;
            }

            return(result);
        }
コード例 #3
0
 public PropVariant GetValue(PropertyKey key)
 {
     if (Contains(key))
     {
         PropVariant result;
         HResult.Try(_propertyStoreInterface.GetValue(ref key, out result));
         return(result);
     }
     else
     {
         return(PropVariant.Empty);
     }
 }
コード例 #4
0
        public PropertyKey GetAt(int index)
        {
            if ((index < 0) || (index >= Count))
            {
                throw new IndexOutOfRangeException(
                          String.Format("Index must be between 0 and {0} (inclusive) for this instance.", Count - 1));
            }

            PropertyKey result;

            HResult.Try(_propertyStoreInterface.GetAt((uint)index, out result));
            return(result);
        }
コード例 #5
0
 public void SetValue(KeyValuePair <PropertyKey, PropVariant> value)
 {
     if (Contains(value.Key))
     {
         var key       = value.Key;
         var propValue = value.Value;
         HResult.Try(_propertyStoreInterface.SetValue(ref key, ref propValue));
         propValue.Dispose();
     }
     else
     {
         throw new KeyNotFoundException(String.Format("The specified key ({0}) was not found.", value.Key.ToString()));
     }
 }
コード例 #6
0
        public void Dispose()
        {
            // Free pinned managed resources
            if ((varType & VarType.Flag_FlagMask) == VarType.Flag_ByRef)
            {
                if (handleUnion.handle.IsAllocated)
                {
                    handleUnion.handle.Free();
                }
            }

            // Free native resources
            unsafe
            {
                fixed(PropVariant *thisPtr = &this)
                {
                    HResult.Try(NativeMethods.Ole32.PropVariantClear(thisPtr));
                }
            }

            // Suppress finalization
            GC.SuppressFinalize(this);
        }
コード例 #7
0
        private void SetSafeArray(Array value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (value.Rank > 1)
            {
                throw new NotSupportedException("Multidimensional arrays are not supported.");
            }

            var bounds = new SafeArrayBound[1];

            bounds[0] = new SafeArrayBound(value.GetLength(0), value.GetLowerBound(0));
            var    arrayPtr = NativeMethods.OleAut32.SafeArrayCreate(VarType.Unknown, 1, bounds);
            IntPtr arrayDataPtr;

            HResult.Try(NativeMethods.OleAut32.SafeArrayAccessData(arrayPtr, out arrayDataPtr));

            try
            {
                for (var i = bounds[0].LowerBound; i < bounds[0].LowerBound + bounds[0].NumElements; i++)
                {
                    var element    = value.GetValue(i);
                    var elementPtr = (element != null) ? Marshal.GetIUnknownForObject(element) : IntPtr.Zero;
                    Marshal.WriteIntPtr(arrayDataPtr, i * IntPtr.Size, elementPtr);
                }
            }
            finally
            {
                HResult.Try(NativeMethods.OleAut32.SafeArrayUnaccessData(arrayPtr));
            }

            varType = VarType.Flag_Array | VarType.Unknown;
            pointerUnion.Pointer1 = arrayPtr;
        }
コード例 #8
0
 public void Commit()
 {
     HResult.Try(_propertyStoreInterface.Commit());
 }