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 <object> .CreateMarshaler(baseInterface);

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

                return(ObjectReference <IUnknownVftbl> .Attach(ref __retval));
            }
            finally
            {
                MarshalString.DisposeMarshaler(__name);
                MarshalInspectable <object> .DisposeMarshaler(__baseInterface);

                MarshalInspectable <object> .DisposeAbi(__innerInterface);

                MarshalInspectable <object> .DisposeAbi(__retval);
            }
        }
Пример #2
0
        public static Marshaler CreateMarshaler(global::System.Type value)
        {
            TypeKind kind = TypeKind.Custom;

            if (value is object)
            {
                if (value.IsPrimitive)
                {
                    kind = TypeKind.Primitive;
                }
                else if (value == typeof(object) || value == typeof(string) || value == typeof(Guid))
                {
                    kind = TypeKind.Metadata;
                }
                else if (Projections.IsTypeWindowsRuntimeType(value))
                {
                    kind = TypeKind.Metadata;
                }
            }

            return(new Marshaler
            {
                Name = MarshalString.CreateMarshaler(TypeNameSupport.GetNameForType(value, TypeNameGenerationFlags.None)),
                Kind = kind
            });
        }
Пример #3
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();
                }
            }
        }
Пример #4
0
        public static Marshaler CreateMarshaler(global::System.Type value)
        {
            var abi = ToAbi(value);

            return(new Marshaler
            {
                Name = MarshalString.CreateMarshaler(abi.Name),
                Kind = abi.Kind
            });
        }
Пример #5
0
Файл: Uri.cs Проект: wjk/CsWinRT
        public unsafe IObjectReference CreateUri(string uri)
        {
            MarshalString __uri    = default;
            IntPtr        __retval = default;

            try
            {
                __uri = MarshalString.CreateMarshaler(uri);
                global::WinRT.ExceptionHelpers.ThrowExceptionForHR(_obj.Vftbl.CreateUri_0(ThisPtr, MarshalString.GetAbi(__uri), out __retval));
                return(ObjectReference <IUnknownVftbl> .Attach(ref __retval));
            }
            finally
            {
                MarshalString.DisposeMarshaler(__uri);
            }
        }
Пример #6
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);
                    }
                }
        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));
        }
Пример #8
0
 internal HString(string str)
 {
     this._abi = MarshalString.GetAbi(MarshalString.CreateMarshaler(str));
 }