Exemplo n.º 1
0
 private static void Main(string[] args)
 {
     ComWrappersSupport.InitializeComWrappers();
     Application.Start(p => { DispatcherQueueSyncContext.SetForCurrentThread(); new App(); });
 }
Exemplo n.º 2
0
 public DataProtectionProvider() : this((ActivationFactory <DataProtectionProvider> .ActivateInstance <IUnknownVftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
     ComWrappersHelper.Init(_inner, false);
 }
        public static unsafe global::System.Collections.Specialized.NotifyCollectionChangedEventHandler FromAbi(IntPtr nativeDelegate)
        {
            var abiDelegate = ObjectReference <IDelegateVftbl> .FromAbi(nativeDelegate);

            return(abiDelegate is null ? null : (global::System.Collections.Specialized.NotifyCollectionChangedEventHandler)ComWrappersSupport.TryRegisterObjectForInterface(new global::System.Collections.Specialized.NotifyCollectionChangedEventHandler(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate));
        }
Exemplo n.º 4
0
 public static IObjectReference CreateMarshaler(global::System.Collections.Generic.IReadOnlyList <T> obj) =>
 obj is null ? null : ComWrappersSupport.CreateCCWForObject(obj).As <Vftbl>(GuidGenerator.GetIID(typeof(IReadOnlyList <T>)));
Exemplo n.º 5
0
        private void Complete(IAsyncInfo asyncInfo, Func <IAsyncInfo, TResult> getResultsFunction, AsyncStatus asyncStatus)
        {
            if (asyncInfo == null)
            {
                throw new ArgumentNullException(nameof(asyncInfo));
            }

            // TODO: AsyncCausality?

            try
            {
                Debug.Assert(asyncInfo.Status == asyncStatus, "asyncInfo.Status does not match asyncStatus; are we dealing with a faulty IAsyncInfo implementation?");
                if (Task.IsCompleted)
                {
                    Debug.Fail("Expected the task to not yet be completed.");
                    throw new InvalidOperationException("The asynchronous operation could not be completed.");
                }

                // Clean up our registration with the cancellation token, noting that we're now in the process of cleaning up.
                CancellationTokenRegistration ctr;
                lock (this)
                {
                    _completing = true;
                    ctr         = _ctr;
                    _ctr        = default;
                }
                ctr.Dispose();

                try
                {
                    if (asyncStatus != AsyncStatus.Completed && asyncStatus != AsyncStatus.Canceled && asyncStatus != AsyncStatus.Error)
                    {
                        Debug.Fail("The async operation should be in a terminal state.");
                        throw new InvalidOperationException("The asynchronous operation could not be completed.");
                    }

                    TResult   result = default(TResult);
                    Exception error  = null;
                    if (asyncStatus == AsyncStatus.Error)
                    {
                        error = asyncInfo.ErrorCode;

                        // Defend against a faulty IAsyncInfo implementation
                        if (error is null)
                        {
                            Debug.Fail("IAsyncInfo.Status == Error, but ErrorCode returns a null Exception (implying S_OK).");
                            error = new InvalidOperationException("The asynchronous operation could not be completed.");
                        }
                    }
                    else if (asyncStatus == AsyncStatus.Completed && getResultsFunction != null)
                    {
                        try
                        {
                            result = getResultsFunction(asyncInfo);
                        }
                        catch (Exception resultsEx)
                        {
                            // According to the WinRT team, this can happen in some egde cases, such as marshalling errors in GetResults.
                            error       = resultsEx;
                            asyncStatus = AsyncStatus.Error;
                        }
                    }

                    // Complete the task based on the previously retrieved results:
                    bool success = false;
                    switch (asyncStatus)
                    {
                    case AsyncStatus.Completed:
                        // TODO: AsyncCausality?
                        success = base.TrySetResult(result);
                        break;

                    case AsyncStatus.Error:
                        Debug.Assert(error != null, "The error should have been retrieved previously.");
                        success = base.TrySetException(error);
                        break;

                    case AsyncStatus.Canceled:
                        success = base.TrySetCanceled(_ct.IsCancellationRequested ? _ct : new CancellationToken(true));
                        break;
                    }

                    Debug.Assert(success, "Expected the outcome to be successfully transfered to the task.");
                }
                catch (Exception exc)
                {
                    Debug.Fail($"Unexpected exception in Complete: {exc}");

                    // TODO: AsyncCausality

                    if (!base.TrySetException(exc))
                    {
                        Debug.Fail("The task was already completed and thus the exception couldn't be stored.");
                        throw;
                    }
                }
            }
            finally
            {
                // We may be called on an STA thread which we don't own, so make sure that the RCW is released right
                // away. Otherwise, if we leave it up to the finalizer, the apartment may already be gone.
                if (ComWrappersSupport.TryUnwrapObject(asyncInfo, out var objRef))
                {
                    objRef.Dispose();
                }
            }
        }
Exemplo n.º 6
0
 private static void Main(string[] args)
 {
     ComWrappersSupport.InitializeComWrappers();
     CoreApplication.Run(new App());
 }
Exemplo n.º 7
0
 public IObjectReference Resolve(Guid riid)
 {
     ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.Resolve(ThisPtr, ref riid, out IntPtr objRef));
     return(ComWrappersSupport.GetObjectReferenceForInterface(objRef));
 }
Exemplo n.º 8
0
 public EasClientDeviceInformation() : this((ActivationFactory <EasClientDeviceInformation> .ActivateInstance <IUnknownVftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
     ComWrappersHelper.Init(_inner, false);
 }
Exemplo n.º 9
0
 public Language(string languageTag) : this(((Func <global::MS.Internal.WindowsRuntime.ABI.Windows.Globalization.ILanguage>)(() => {
     IntPtr ptr = (_ILanguageFactory.Instance.CreateLanguage(languageTag));
     try
     {
         return(new global::MS.Internal.WindowsRuntime.ABI.Windows.Globalization.ILanguage(ComWrappersSupport.GetObjectReferenceForInterface(ptr)));
     }
     finally
     {
         MarshalInspectable.DisposeAbi(ptr);
     }
 }))())
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
 }
 public CompositorController() : this((ActivationFactory <CompositorController> .ActivateInstance <IUnknownVftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
     ComWrappersHelper.Init(_inner, false);
 }
 public DisplayRequest() : this((ActivationFactory <DisplayRequest> .ActivateInstance <IUnknownVftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
     ComWrappersHelper.Init(_inner, false);
 }
Exemplo n.º 12
0
 public SimpleMath() : this(new global::ABI.SimpleMathComponent.ISimpleMath(ActivationFactory <SimpleMath> .ActivateInstance <global::ABI.SimpleMathComponent.ISimpleMath.Vftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
 }
 public PlatformTelemetryRegistrationSettings() : this((ActivationFactory <PlatformTelemetryRegistrationSettings> .ActivateInstance <IUnknownVftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
     ComWrappersHelper.Init(_inner, false);
 }
Exemplo n.º 14
0
 public static unsafe IObjectReference CreateMarshaler(global::System.EventHandler managedDelegate) =>
 managedDelegate is null ? null : ComWrappersSupport.CreateCCWForObject(managedDelegate).As <global::WinRT.Interop.IDelegateVftbl>(GuidGenerator.GetIID(typeof(CanExecuteChangedEventHandler)));
Exemplo n.º 15
0
            private static int Do_Abi_GetWeakReference(IntPtr thisPtr, out IntPtr weakReference)
            {
                weakReference = default;

                try
                {
                    weakReference = ComWrappersSupport.CreateCCWForObject(new global::WinRT.Interop.ManagedWeakReference(ComWrappersSupport.FindObject <object>(thisPtr))).As <ABI.WinRT.Interop.IWeakReference.Vftbl>().GetRef();
                }
                catch (Exception __exception__)
                {
                    return(__exception__.HResult);
                }
                return(0);
            }
Exemplo n.º 16
0
        public static unsafe global::System.EventHandler FromAbi(IntPtr nativeDelegate)
        {
            var abiDelegate = ObjectReference <IDelegateVftbl> .FromAbi(nativeDelegate);

            return((global::System.EventHandler)ComWrappersSupport.TryRegisterObjectForInterface(new global::System.EventHandler(new NativeDelegateWrapper(abiDelegate).Invoke), nativeDelegate));
        }
Exemplo n.º 17
0
 public SceneLightingEffect() : this((ActivationFactory <SceneLightingEffect> .ActivateInstance <IUnknownVftbl>()))
 {
     ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
     ComWrappersHelper.Init(_inner, false);
 }