コード例 #1
0
        public static ComPtr <T> Wrap(T *ptr)
        {
            var ret = new ComPtr <T>();

            ret.Attach(ptr);

            return(ret);
        }
コード例 #2
0
        public ComPtr <U> Cast <U>() where U : unmanaged
        {
            var ret = new ComPtr <U>();

            ret.Attach((U *)ptr_);

            return(ret);
        }
コード例 #3
0
        /// <summary>Converts the current object reference to a type indicated by the given IID and assigns that to a target <see cref="ComPtr{T}"/> value.</summary>
        /// <param name="riid">The IID indicating the interface type to convert the COM object reference to.</param>
        /// <param name="other">A reference to the target <see cref="ComPtr{T}"/> value to write to.</param>
        /// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target IID.</returns>
        /// <remarks>This method will automatically release the target COM object pointed to by <paramref name="other"/>, if any.</remarks>
        public readonly int AsIID(Guid *riid, ref ComPtr <IUnknown> other)
        {
            IUnknown *ptr;
            int       result = ((IUnknown *)ptr_)->QueryInterface(riid, (void **)&ptr);

            other.Attach(ptr);
            return(result);
        }
コード例 #4
0
        /// <summary>Converts the current object reference to type <typeparamref name="U"/> and assigns that to a target <see cref="ComPtr{T}"/> value.</summary>
        /// <typeparam name="U">The interface type to use to try casting the current COM object.</typeparam>
        /// <param name="other">A reference to the target <see cref="ComPtr{T}"/> value to write to.</param>
        /// <returns>The result of <see cref="IUnknown.QueryInterface"/> for the target type <typeparamref name="U"/>.</returns>
        /// <remarks>This method will automatically release the target COM object pointed to by <paramref name="other"/>, if any.</remarks>
        public readonly int As <U>(ref ComPtr <U> other)
            where U : unmanaged
        {
            U * ptr;
            int result = ((IUnknown *)ptr_)->QueryInterface(__uuidof <U>(), (void **)&ptr);

            other.Attach(ptr);
            return(result);
        }
コード例 #5
0
 /// <summary>Increments the reference count for the current COM object, if any, and copies its address to a target <see cref="ComPtr{T}"/>.</summary>
 /// <param name="other">The target reference to copy the address of the current COM object to.</param>
 /// <returns>This method always returns <see cref="S_OK"/>.</returns>
 public readonly int CopyTo(ref ComPtr <T> other)
 {
     InternalAddRef();
     other.Attach(ptr_);
     return(S_OK);
 }