예제 #1
0
        public static ObjectReference <IActivationFactoryVftbl> GetActivationFactory(string runtimeClassId)
        {
            lock ( Cache )
            {
                if (Cache.TryGetValue(runtimeClassId, out var factory))
                {
                    return(factory);
                }

                var m = MarshalString.CreateMarshaler(runtimeClassId);

                try
                {
                    var instancePtr = GetActivationFactory(MarshalString.GetAbi(m));

                    factory = ObjectReference <IActivationFactoryVftbl> .Attach(ref instancePtr);

                    Cache.Add(runtimeClassId, factory);

                    return(factory);
                }
                finally
                {
                    m.Dispose();
                }
            }
        }
예제 #2
0
파일: Type.cs 프로젝트: wjk/CsWinRT
 public static Type GetAbi(Marshaler m)
 {
     return(new Type
     {
         Name = MarshalString.GetAbi(m.Name),
         Kind = m.Kind
     });
 }
        public static IAsyncOperation <UserConsentVerificationResult> RequestVerificationForWindowAsync(IntPtr hWnd, string Message)
        {
            //Use WinRT's GuidGenerator to get the correct guid
            var guid = GuidGenerator.CreateIID(typeof(IAsyncOperation <UserConsentVerificationResult>));

            //leverage winrt .As<> operator to cast winrt type to its interop interface
            IUserConsentVerifierInterop userConsentVerifierInterop = UserConsentVerifier.As <IUserConsentVerifierInterop>();

            //Handle marshalling the string to WinRT's HString
            var marshalStr = MarshalString.CreateMarshaler(Message);

            //Call the Interop api that pops a dialog, passing in the hWnd parameter
            IntPtr outPtr;

            userConsentVerifierInterop.RequestVerificationForWindowAsync(hWnd, MarshalString.GetAbi(marshalStr), ref guid, out outPtr);

            //Marshal the return object as an IAsyncOperation<>
            return((IAsyncOperation <UserConsentVerificationResult>)IInspectable.FromAbi(outPtr));
        }
예제 #4
0
            public static Cache CreateCache(Proj.NonBlittable arg)
            {
                Cache cache = new Cache();

                try
                {
                    cache.s1  = MarshalString.CreateCache(arg.s1);
                    cache.s2  = MarshalString.CreateCache(arg.s2);
                    cache.abi = new NonBlittable()
                    {
                        b  = arg.b,
                        s1 = MarshalString.GetAbi(cache.s1),
                        s2 = MarshalString.GetAbi(cache.s2)
                    };
                    return(cache);
                }
                catch (Exception) when(cache.Dispose())
                {
                    // Will never execute
                    return(default);
예제 #5
0
파일: Uri.cs 프로젝트: wjk/CsWinRT
        public unsafe IObjectReference CreateWithRelativeUri(string baseUri, string relativeUri)
        {
            MarshalString __baseUri     = default;
            MarshalString __relativeUri = default;
            IntPtr        __retval      = default;

            try
            {
                __baseUri     = MarshalString.CreateMarshaler(baseUri);
                __relativeUri = MarshalString.CreateMarshaler(relativeUri);
                global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateWithRelativeUri_1(ThisPtr, MarshalString.GetAbi(__baseUri), MarshalString.GetAbi(__relativeUri), out __retval));
                return(ObjectReference <IUnknownVftbl> .Attach(ref __retval));
            }
            finally
            {
                MarshalString.DisposeMarshaler(__baseUri);
                MarshalString.DisposeMarshaler(__relativeUri);
            }
        }
        public unsafe IObjectReference CreateInstance(string name, object baseInterface, out IObjectReference innerInterface)
        {
            MarshalString    __name           = default;
            IObjectReference __baseInterface  = default;
            IntPtr           __innerInterface = default;
            IntPtr           __retval         = default;

            try
            {
                __name          = MarshalString.CreateMarshaler(name);
                __baseInterface = MarshalInspectable.CreateMarshaler(baseInterface);
                global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateInstance_0(ThisPtr, MarshalString.GetAbi(__name), MarshalInspectable.GetAbi(__baseInterface), &__innerInterface, &__retval));
                innerInterface = ObjectReference <IUnknownVftbl> .FromAbi(__innerInterface);

                return(ObjectReference <IUnknownVftbl> .Attach(ref __retval));
            }
            finally
            {
                MarshalString.DisposeMarshaler(__name);
                MarshalInspectable.DisposeMarshaler(__baseInterface);
                MarshalInspectable.DisposeAbi(__innerInterface);
                MarshalInspectable.DisposeAbi(__retval);
            }
        }
예제 #7
0
                public unsafe new IntPtr CreateLanguage(string languageTag)
                {
                    MarshalString __languageTag = default;
                    IntPtr        __retval      = default;

                    try
                    {
                        __languageTag = MarshalString.CreateMarshaler(languageTag);
                        global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateLanguage_0(ThisPtr, MarshalString.GetAbi(__languageTag), out __retval));
                        return(__retval);
                    }
                    finally
                    {
                        MarshalString.DisposeMarshaler(__languageTag);
                    }
                }
예제 #8
0
 internal HString(string str)
 {
     this._abi = MarshalString.GetAbi(MarshalString.CreateMarshaler(str));
 }