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); } }
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 }); }
private static unsafe int Do_Abi_GetIndexedProperty_1(IntPtr thisPtr, IntPtr name, global::ABI.System.Type type, IntPtr *result) { global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; try { string _name = MarshalString.FromAbi(name); object target = global::WinRT.ComWrappersSupport.FindObject <object>(thisPtr); PropertyInfo propertyInfo = target.GetType().GetProperty( _name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, null, // default binder null, // ignore return type new Type[] { global::ABI.System.Type.FromAbi(type) }, // indexed parameter type null // ignore type modifier ); if (propertyInfo is object) { __result = new ManagedCustomProperty(propertyInfo); } *result = MarshalInterface <global::Microsoft.UI.Xaml.Data.ICustomProperty> .FromManaged(__result); } catch (Exception __exception__) { global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__)); } return(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(); } } }
private static unsafe int Do_Abi_GetCustomProperty_0(IntPtr thisPtr, IntPtr name, IntPtr *result) { global::Microsoft.UI.Xaml.Data.ICustomProperty __result = default; try { string _name = MarshalString.FromAbi(name); object target = global::WinRT.ComWrappersSupport.FindObject <object>(thisPtr); PropertyInfo propertyInfo = target.GetType().GetProperty( _name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public); if (propertyInfo is object) { __result = new ManagedCustomProperty(propertyInfo); } *result = MarshalInterface <global::Microsoft.UI.Xaml.Data.ICustomProperty> .FromManaged(__result); } catch (Exception __exception__) { global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__)); } return(0); }
public static unsafe int GetActivationFactory(IntPtr hstrTargetAssembly, IntPtr hstrRuntimeClassId, IntPtr *activationFactory) { *activationFactory = IntPtr.Zero; var targetAssembly = MarshalString.FromAbi(hstrTargetAssembly); var runtimeClassId = MarshalString.FromAbi(hstrRuntimeClassId); try { var assembly = ActivationLoader.LoadAssembly(targetAssembly); var type = assembly.GetType("WinRT.Module"); if (type == null) { return(REGDB_E_CLASSNOTREG); } var GetActivationFactory = type.GetMethod("GetActivationFactory"); if (GetActivationFactory == null) { return(REGDB_E_READREGDB); } IntPtr factory = (IntPtr)GetActivationFactory.Invoke(null, new object[] { runtimeClassId }); if (factory == IntPtr.Zero) { return(E_NOINTERFACE); } *activationFactory = factory; return(S_OK); } catch (Exception e) { global::WinRT.ExceptionHelpers.SetErrorInfo(e); return(global::WinRT.ExceptionHelpers.GetHRForException(e)); } }
public static Type GetAbi(Marshaler m) { return(new Type { Name = MarshalString.GetAbi(m.Name), Kind = m.Kind }); }
public static global::System.Type FromAbi(Type value) { string name = MarshalString.FromAbi(value.Name); if (string.IsNullOrEmpty(name)) { return(null); } return(TypeNameSupport.FindTypeByName(name.AsSpan()).type); }
public static Type FromManaged(global::System.Type value) { var abi = ToAbi(value); return(new Type { Name = MarshalString.FromManaged(abi.Name), Kind = abi.Kind }); }
public static Marshaler CreateMarshaler(global::System.Type value) { var abi = ToAbi(value); return(new Marshaler { Name = MarshalString.CreateMarshaler(abi.Name), Kind = abi.Kind }); }
/// <summary> /// 获取Tcp Client连接信息的对端IP /// </summary> /// <param name="mk_sock_info"></param> /// <returns></returns> internal static Task <string> GetTcpClientPeerIp(IntPtr mk_tcp_Client) { return(Task.Run(() => { using (var buffer = new MarshalString(ZLMediaKitConst.IpStringLength)) { PInvoke.ZLMediaKitMethod.mk_tcp_client_peer_ip(mk_tcp_Client, buffer.Value); return Marshal.PtrToStringAnsi(buffer.Value); } }).ContinueWith(GeneralTask.WriteFaultedLog, TaskContinuationOptions.OnlyOnFaulted)); }
/// <summary> /// 获取基础连接信息的本地IP地址 /// </summary> /// <param name="mk_sock_info"></param> /// <returns></returns> internal static Task <string> GetSockLocalIp(IntPtr mk_sock_info) { return(Task.Run(() => { using (var buffer = new MarshalString(ZLMediaKitConst.IpStringLength)) { PInvoke.ZLMediaKitMethod.mk_sock_info_local_ip(mk_sock_info, buffer.Value); return Marshal.PtrToStringAnsi(buffer.Value); } }).ContinueWith(GeneralTask.WriteFaultedLog)); }
private static unsafe int Do_Abi_ToString_0(IntPtr thisPtr, out IntPtr value) { value = default; try { string __value = global::WinRT.ComWrappersSupport.FindObject <object>(thisPtr).ToString(); value = MarshalString.FromManaged(__value); } catch (Exception __exception__) { global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__)); } return(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 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); } }
public void Utf8NotNullTest(string text) { IntPtr pointer = MarshalString.StringToUtf8(text); try { Assert.NotEqual(IntPtr.Zero, pointer); } finally { if (pointer != IntPtr.Zero) { Marshal.FreeHGlobal(pointer); } } }
private static unsafe int Do_Abi_GetStringRepresentation_2(IntPtr thisPtr, IntPtr *result) { string __result = default; try { __result = global::WinRT.ComWrappersSupport.FindObject <object>(thisPtr).ToString(); *result = MarshalString.FromManaged(__result); } catch (Exception __exception__) { global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__)); } return(0); }
private static unsafe int Do_Abi_get_Name_1(IntPtr thisPtr, IntPtr *value) { string __value = default; try { __value = global::WinRT.ComWrappersSupport.FindObject <global::Microsoft.UI.Xaml.Data.ICustomProperty>(thisPtr).Name; *value = MarshalString.FromManaged(__value); } catch (Exception __exception__) { global::WinRT.ExceptionHelpers.SetErrorInfo(__exception__); return(global::WinRT.ExceptionHelpers.GetHRForException(__exception__)); } return(0); }
public void Utf8MarshalTest(string text) { IntPtr pointer = MarshalString.StringToUtf8(text); string marshalled; try { marshalled = MarshalString.Utf8ToString(pointer); } finally { if (pointer != IntPtr.Zero) { Marshal.FreeHGlobal(pointer); } } Assert.Equal(text, marshalled); }
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)); }
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);
public static global::System.Uri FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return(null); } using var uri = ObjectReference <ABI.Windows.Foundation.IUriRuntimeClassVftbl> .FromAbi(ptr); IntPtr rawUri = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(uri.Vftbl.get_RawUri_10(uri.ThisPtr, out rawUri)); return(new global::System.Uri(MarshalString.FromAbi(rawUri))); } finally { MarshalString.DisposeAbi(rawUri); } }
public static global::System.ComponentModel.PropertyChangedEventArgs FromAbi(IntPtr ptr) { if (ptr == IntPtr.Zero) { return(null); } using var args = ObjectReference <ABI.Microsoft.UI.Xaml.Data.IPropertyChangedEventArgsVftbl> .FromAbi(ptr); IntPtr propertyName = IntPtr.Zero; try { ExceptionHelpers.ThrowExceptionForHR(args.Vftbl.get_PropertyName_0(args.ThisPtr, &propertyName)); return(new global::System.ComponentModel.PropertyChangedEventArgs(MarshalString.FromAbi(propertyName))); } finally { MarshalString.DisposeAbi(propertyName); } }
internal HString(string str) { this._abi = MarshalString.GetAbi(MarshalString.CreateMarshaler(str)); }
public static HSTRING FromString(string str) => new HSTRING(MarshalString.FromManaged(str));
public void Delete() { MarshalString.DisposeAbi(handle); }
public override string ToString() { return(MarshalString.FromAbi(handle)); }
internal void Dispose() { MarshalString.DisposeMarshaler(Name); }
internal string GetError() { return(MarshalString.NativeToString(ErrorBuffer)); }
public bool Dispose() { MarshalString.DisposeCache(s1); MarshalString.DisposeCache(s2); return(false); }