From dbde9e7104b907bbbaea17e21247d8cafc8b3a4c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 14 Oct 2017 16:12:07 -0700 Subject: Massive refactoring to introduce the concept of IBackend --- .../CLR/Interop/CLRInterop.cs | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs (limited to 'src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs') diff --git a/src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs b/src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs new file mode 100644 index 00000000..4157f23a --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs @@ -0,0 +1,147 @@ +// 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; + } + } +} -- cgit v1.2.3-55-g6feb