Exemple #1
0
        protected CallableCOMWrapper(CallableCOMWrapper toClone)
        {
            if (toClone._disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            Self           = toClone.Self;
            _unknownVTable = toClone._unknownVTable;
            _library       = toClone._library;

            AddRef();
            _library.AddRef();
        }
Exemple #2
0
        private protected CallableCOMWrapper(RefCountedFreeLibrary library, ref Guid desiredInterface, IntPtr pUnknown)
        {
            _library = library;
            _library.AddRef();

            IUnknownVTable *tbl = *(IUnknownVTable **)pUnknown;

            var queryInterface = (QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(tbl->QueryInterface, typeof(QueryInterfaceDelegate));
            int hr             = queryInterface(pUnknown, ref desiredInterface, out IntPtr pCorrectUnknown);

            if (hr != 0)
            {
                GC.SuppressFinalize(this);
                throw new InvalidOperationException();
            }

            var release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(tbl->Release, typeof(ReleaseDelegate));
            int count   = release(pUnknown);

            Self           = pCorrectUnknown;
            _unknownVTable = *(IUnknownVTable **)pCorrectUnknown;
        }
        protected CallableCOMWrapper(RefCountedFreeLibrary library, ref Guid desiredInterface, IntPtr pUnknown)
        {
            _library = library;
            _library.AddRef();

            IUnknownVTable *tbl = *(IUnknownVTable **)pUnknown;

            QueryInterfaceDelegate queryInterface = (QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(tbl->QueryInterface, typeof(QueryInterfaceDelegate));
            int hr = queryInterface(pUnknown, ref desiredInterface, out IntPtr pCorrectUnknown);

            if (hr != 0)
            {
                GC.SuppressFinalize(this);
                throw new InvalidCastException($"{GetType().FullName}.QueryInterface({desiredInterface}) failed, hr=0x{hr:x}");
            }

            ReleaseDelegate release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(tbl->Release, typeof(ReleaseDelegate));
            int             count   = release(pUnknown);

            Self           = pCorrectUnknown;
            _unknownVTable = *(IUnknownVTable **)pCorrectUnknown;
        }