Exemple #1
0
        /// <summary>
        /// Return the unmanaged C++ pointer from a <see cref="ICallbackable"/> instance.
        /// </summary>
        /// <typeparam name="TCallback">The type of the callback.</typeparam>
        /// <param name="callback">The callback.</param>
        /// <returns>A pointer to the unmanaged C++ object of the callback</returns>
        public static IntPtr ToCallbackPtr <TCallback>(ICallbackable callback)
            where TCallback : ICallbackable
        {
            // If callback is null, then return a null pointer
            if (callback == null)
            {
                return(IntPtr.Zero);
            }

            // If callback is CppObject
            if (callback is CppObject)
            {
                return(((CppObject)callback).NativePointer);
            }

            // Setup the shadow container in order to support multiple inheritance
            var shadowContainer = callback.Shadow;

            if (shadowContainer == null)
            {
                shadowContainer = new ShadowContainer();
                shadowContainer.Initialize(callback);
            }

            return(shadowContainer.Find(typeof(TCallback)));
        }
Exemple #2
0
            private static unsafe int GetIids(IntPtr thisPtr, int *iidCount, IntPtr *iids)
            {
                try
                {
                    InspectableShadow shadow   = ToShadow <InspectableShadow>(thisPtr);
                    IInspectable      callback = (IInspectable)shadow.Callback;

                    ShadowContainer container = callback.Shadow;

                    int countGuids = container.Guids.Length;

                    // Copy GUIDs deduced from Callback
                    iids = (IntPtr *)Marshal.AllocCoTaskMem(IntPtr.Size * countGuids);
                    *iidCount = countGuids;

                    MemoryHelpers.CopyMemory((IntPtr)iids, new ReadOnlySpan <IntPtr>(container.Guids));
                }
                catch (Exception exception)
                {
                    return((int)Result.GetResultFromException(exception));
                }
                return(Result.Ok.Code);
            }
Exemple #3
0
 static Guid GetCallbackTypeGuid() => ShadowContainer.GuidFromType(typeof(TCallback));