/// <summary> /// Returns runtime class name for a specific WinRT interface /// </summary> internal static string GetRuntimeClassName(IntPtr pWinRTItf) { #if ENABLE_MIN_WINRT void *unsafe_hstring = null; try { int hr = CalliIntrinsics.StdCall__int( ((__com_IInspectable *)(void *)pWinRTItf)->pVtable->pfnGetRuntimeClassName, pWinRTItf, &unsafe_hstring); // Don't throw if the call fails if (hr < 0) { return(String.Empty); } return(McgMarshal.HStringToString(new IntPtr(unsafe_hstring))); } finally { if (unsafe_hstring != null) { McgMarshal.FreeHString(new IntPtr(unsafe_hstring)); } } #else throw new PlatformNotSupportedException("GetRuntimeClassName(IntPtr)"); #endif }
/// <summary> /// Returns the requested interface pointer specified by itfType from the CCWActivationFactory /// object instance. Typically the requested interface is the /// System.Runtime.InteropServices.WindowsRuntime.IActivationFactory interface. /// </summary> public unsafe int GetCCWActivationFactory(HSTRING activatableClassId, RuntimeTypeHandle itfType, IntPtr *factoryOut) { try { string classId = McgMarshal.HStringToString(activatableClassId); if (classId == null) { return(Interop.COM.E_INVALIDARG); } RuntimeTypeHandle factoryTypeHandle = default(RuntimeTypeHandle); if (m_ccwFactoriesNameMap != null) { int slot = m_ccwFactoriesNameMap.FindString(classId); if (slot >= 0) { factoryTypeHandle = m_ccwFactories[slot].FactoryType; } } if (factoryTypeHandle.IsNull()) { return(Interop.COM.E_NOINTERFACE); } object factory = InteropExtensions.RuntimeNewObject(factoryTypeHandle); *factoryOut = McgMarshal.ObjectToComInterface( factory, itfType); } catch (Exception ex) { *factoryOut = default(IntPtr); return(McgMarshal.GetHRForExceptionWinRT(ex)); } return(Interop.COM.S_OK); }