예제 #1
0
            /// <summary>
            /// Given a <see cref="System.IntPtr"/> from a generated Vtable, convert to the target type.
            /// </summary>
            /// <typeparam name="T">Desired type.</typeparam>
            /// <param name="dispatchPtr">Pointer supplied to Vtable function entry.</param>
            /// <returns>Instance of type associated with dispatched function call.</returns>
            public static unsafe T GetInstance <T>(ComInterfaceDispatch *dispatchPtr) where T : class
            {
                // See the dispatch section in the runtime for details on the masking below.
                const long DispatchThisPtrMask = ~0xfL;
                var        comInstance         = *(ComInterfaceInstance **)(((long)dispatchPtr) & DispatchThisPtrMask);

                return(Unsafe.As <T>(GCHandle.InternalGet(comInstance->GcHandle)));
            }
 public static unsafe T GetInstance <T>(ComInterfaceDispatch *dispatchPtr) where T : class
 {
     throw new PlatformNotSupportedException();
 }
예제 #3
0
 internal static unsafe ManagedObjectWrapper *ToManagedObjectWrapper(ComInterfaceDispatch *dispatchPtr)
 {
     return(((InternalComInterfaceDispatch *)dispatchPtr)->_thisPtr);
 }
예제 #4
0
            /// <summary>
            /// Given a <see cref="System.IntPtr"/> from a generated Vtable, convert to the target type.
            /// </summary>
            /// <typeparam name="T">Desired type.</typeparam>
            /// <param name="dispatchPtr">Pointer supplied to Vtable function entry.</param>
            /// <returns>Instance of type associated with dispatched function call.</returns>
            public static unsafe T GetInstance <T>(ComInterfaceDispatch *dispatchPtr) where T : class
            {
                ManagedObjectWrapper *comInstance = ToManagedObjectWrapper(dispatchPtr);

                return(Unsafe.As <T>(RuntimeImports.RhHandleGet(comInstance->Target)));
            }