Ejemplo n.º 1
0
        public unsafe static ITypeInfo GetTypeInfoByName(this ITypeLib typeLib, string typeName)
        {
            // The find method is case insensitive, and will overwrite the input buffer
            // with the actual found casing.

            char *      nameBuffer = stackalloc char[typeName.Length + 1];
            Span <char> nameSpan   = new Span <char>(nameBuffer, typeName.Length);

            typeName.AsSpan().CopyTo(nameSpan);
            nameBuffer[typeName.Length] = '\0';

            IntPtr *  typeInfos = stackalloc IntPtr[1];
            MemberId *memberIds = stackalloc MemberId[1];
            ushort    found     = 1;

            typeLib.FindName(
                nameBuffer,
                lHashVal: 0,
                typeInfos,
                memberIds,
                &found).ThrowIfFailed(typeName);

            return((ITypeInfo)Marshal.GetTypedObjectForIUnknown(typeInfos[0], typeof(ITypeInfo)));
        }