/// <summary> /// Get a Type object representing the named type, along with a boolean indicating if the type /// definition is from a WinMD file. /// </summary> internal Type GetTypeFromName(string name, ref bool isWinRT) { if (m_interfaceNameMap != null) { int i = m_interfaceNameMap.FindString(name); if (i >= 0) { isWinRT = m_interfaceData[i].IsIInspectableOrDelegate; return(InteropExtensions.GetTypeFromHandle(m_interfaceData[i].ItfType)); } } if (m_classNameMap != null) { int i = m_classNameMap.FindString(name); if (i >= 0) { isWinRT = (m_classData[i].Flags & McgClassFlags.IsWinRT) != 0; return(InteropExtensions.GetTypeFromHandle(m_classData[i].ClassType)); } } return(null); }
/// <summary> /// Search this module's m_additionalClassData table for information on the requested type. /// This function returns true if and only if it is able to locate a non-null RuntimeTypeHandle /// record for the requested type. /// </summary> internal bool TryGetClassFromNameInAdditionalClassData(string name, out RuntimeTypeHandle classType) { if (m_additionalClassNameMap != null) { // // Search in additional class data for the closest match (for example, for MyButton, the // closest match is probably Button) // int i = m_additionalClassNameMap.FindString(name); if (i >= 0) { // // We've found a match. The matching row points to the "next best" strongly-typed RCW // type that we should create (in place of the original class) // For example, if native code is passing MatrixTransform, and MCG only knows about its // base class DependencyObject, we should hand out DependencyObject // int classDataIndex = m_additionalClassData[i].ClassDataIndex; RuntimeTypeHandle typeHandle = m_additionalClassData[i].ClassType; if (classDataIndex >= 0) { // // This module's m_additionalClassData table points to a m_classData row which describes // the nearest available base class of the requested type. This row can be immediately used // to compute the RuntimeTypeHandle that best describes the type. // classType = ComputeClosestClassForClassIndex(classDataIndex); if (!classType.Equals(default(RuntimeTypeHandle))) { return(true); } } else { // // This module's m_additionalClassData table lists a RuntimeTypeHandle which describes // the nearest available base class of the requested type. If this nearest base class was // not reduced away, then use it to locate RuntimeTypeHandle describing this "next best" type. // if (!typeHandle.Equals(s_DependencyReductionTypeRemovedTypeHandle)) { classType = typeHandle; if (!classType.Equals(default(RuntimeTypeHandle))) { return(true); } } } } } classType = default(RuntimeTypeHandle); return(false); }
/// <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); }
/// <summary> /// Unbox the WinRT boxed IReference<T>/IReferenceArray<T> and box it into Object so that managed /// code can unbox it later into the real T /// </summary> internal bool TryGetUnboxingStub(string className, out IntPtr unboxingStub) { unboxingStub = default(IntPtr); if (m_boxingData == null) { return(false); } Debug.Assert(!String.IsNullOrEmpty(className)); // // Avoid searching for null/empty name. BoxingData has null name entries // int slot = m_boxingDataNameMap.FindString(className); if (slot >= 0) { unboxingStub = m_boxingData[slot].UnboxingStub; return(true); } return(false); }