/// <summary> /// Given a GUID, retrieve the corresponding RuntimeTypeHandle /// @TODO: we should switch everything to RuntimeTypeHandle instead of relying on Guid /// </summary> unsafe internal RuntimeTypeHandle GetTypeFromGuid(ref Guid guid) { if (m_interfaceData != null) { if (m_guidMap == null) { int size = m_interfaceData.Length; FixedHashTable map = new FixedHashTable(size); for (int i = 0; i < size; i++) { map.Add(m_interfaceData[i].ItfGuid.GetHashCode(), i); } Interlocked.CompareExchange(ref m_guidMap, map, null); } int hash = guid.GetHashCode(); // Search hash table for (int slot = m_guidMap.GetFirst(hash); slot >= 0; slot = m_guidMap.GetNext(slot)) { if (InteropExtensions.GuidEquals(ref guid, ref m_interfaceData[slot].ItfGuid)) { return(m_interfaceData[slot].ItfType); } } } return(default(RuntimeTypeHandle)); }
/// <summary> /// Returns whether the IUnknown* is a free-threaded COM object /// </summary> /// <param name="pUnknown"></param> internal static unsafe bool IsFreeThreaded(IntPtr pUnknown) { // // Does it support IAgileObject? // IntPtr pAgileObject = McgMarshal.ComQueryInterfaceNoThrow(pUnknown, ref Interop.COM.IID_IAgileObject); if (pAgileObject != default(IntPtr)) { // Anything that implements IAgileObject is considered to be free-threaded // NOTE: This doesn't necessarily mean that the object is free-threaded - it only means // we BELIEVE it is free-threaded McgMarshal.ComRelease_StdCall(pAgileObject); return(true); } IntPtr pMarshal = McgMarshal.ComQueryInterfaceNoThrow(pUnknown, ref Interop.COM.IID_IMarshal); if (pMarshal == default(IntPtr)) { return(false); } try { // // Check the un-marshaler // Interop.COM.__IMarshal *pIMarshalNativePtr = (Interop.COM.__IMarshal *)(void *) pMarshal; fixed(Guid *pGuid = &Interop.COM.IID_IUnknown) { Guid clsid; int hr = CalliIntrinsics.StdCall__int( pIMarshalNativePtr->vtbl->pfnGetUnmarshalClass, new IntPtr(pIMarshalNativePtr), pGuid, default(IntPtr), (uint)Interop.COM.MSHCTX.MSHCTX_INPROC, default(IntPtr), (uint)Interop.COM.MSHLFLAGS.MSHLFLAGS_NORMAL, &clsid); if (hr >= 0 && InteropExtensions.GuidEquals(ref clsid, ref Interop.COM.CLSID_InProcFreeMarshaler)) { // The un-marshaller is indeed the unmarshaler for the FTM so this object // is free threaded. return(true); } } return(false); } finally { McgMarshal.ComRelease_StdCall(pMarshal); } }
public static bool GuidEquals(ref Guid left, ref Guid right) { return(InteropExtensions.GuidEquals(ref left, ref right)); }