// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset.Clr.Interop
{
using System;
using System.Runtime.InteropServices;
///
/// Interop class for mscorwks.dll assembly name APIs.
///
internal sealed class ClrInterop
{
private static readonly Guid referenceIdentityGuid = new Guid("6eaf5ace-7917-4f3c-b129-e046a9704766");
///
/// Protect the constructor.
///
private ClrInterop()
{
}
///
/// Represents a reference to the unique signature of a code object.
///
[ComImport]
[Guid("6eaf5ace-7917-4f3c-b129-e046a9704766")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IReferenceIdentity
{
///
/// Get an assembly attribute.
///
/// Attribute namespace.
/// Attribute name.
/// The assembly attribute.
[return: MarshalAs(UnmanagedType.LPWStr)]
string GetAttribute(
[In, MarshalAs(UnmanagedType.LPWStr)] string attributeNamespace,
[In, MarshalAs(UnmanagedType.LPWStr)] string attributeName);
///
/// Set an assembly attribute.
///
/// Attribute namespace.
/// Attribute name.
/// Attribute value.
void SetAttribute(
[In, MarshalAs(UnmanagedType.LPWStr)] string attributeNamespace,
[In, MarshalAs(UnmanagedType.LPWStr)] string attributeName,
[In, MarshalAs(UnmanagedType.LPWStr)] string attributeValue);
///
/// Get an iterator for the assembly's attributes.
///
/// Assembly attribute enumerator.
IEnumIDENTITY_ATTRIBUTE EnumAttributes();
///
/// Clone an IReferenceIdentity.
///
/// Count of deltas.
/// The deltas.
/// Cloned IReferenceIdentity.
IReferenceIdentity Clone(
[In] IntPtr /*SIZE_T*/ countOfDeltas,
[In, MarshalAs(UnmanagedType.LPArray)] IDENTITY_ATTRIBUTE[] deltas);
}
///
/// IEnumIDENTITY_ATTRIBUTE interface.
///
[ComImport]
[Guid("9cdaae75-246e-4b00-a26d-b9aec137a3eb")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IEnumIDENTITY_ATTRIBUTE
{
///
/// Gets the next attributes.
///
/// Count of elements.
/// Array of attributes being returned.
/// The next attribute.
uint Next(
[In] uint celt,
[Out, MarshalAs(UnmanagedType.LPArray)] IDENTITY_ATTRIBUTE[] attributes);
///
/// Copy the current attribute into a buffer.
///
/// Number of available bytes.
/// Buffer into which attribute should be written.
/// Pointer to buffer containing the attribute.
IntPtr CurrentIntoBuffer(
[In] IntPtr /*SIZE_T*/ available,
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] data);
///
/// Skip past a number of elements.
///
/// Count of elements to skip.
void Skip([In] uint celt);
///
/// Reset the enumeration to the beginning.
///
void Reset();
///
/// Clone this attribute enumeration.
///
/// Clone of a IEnumIDENTITY_ATTRIBUTE.
IEnumIDENTITY_ATTRIBUTE Clone();
}
///
/// Gets the guid.
///
public static Guid ReferenceIdentityGuid
{
get { return referenceIdentityGuid; }
}
///
/// Gets an interface pointer to an object with the specified IID, in the assembly at the specified file path.
///
/// A valid path to the requested assembly.
/// The IID of the interface to return.
/// The returned interface pointer.
/// The error code.
[DllImport("mscorwks.dll", CharSet = CharSet.Unicode, EntryPoint = "GetAssemblyIdentityFromFile")]
internal static extern uint GetAssemblyIdentityFromFile(System.String wszAssemblyPath, ref Guid riid, out IReferenceIdentity i);
///
/// Assembly attributes. Contains data about an IReferenceIdentity.
///
[StructLayout(LayoutKind.Sequential)]
internal struct IDENTITY_ATTRIBUTE
{
[MarshalAs(UnmanagedType.LPWStr)]
public string AttributeNamespace;
[MarshalAs(UnmanagedType.LPWStr)]
public string AttributeName;
[MarshalAs(UnmanagedType.LPWStr)]
public string AttributeValue;
}
}
}