diff options
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs')
-rw-r--r-- | src/WixToolset.Core.WindowsInstaller/CLR/Interop/CLRInterop.cs | 147 |
1 files changed, 147 insertions, 0 deletions
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 @@ | |||
1 | // 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. | ||
2 | |||
3 | namespace WixToolset.Clr.Interop | ||
4 | { | ||
5 | using System; | ||
6 | using System.Runtime.InteropServices; | ||
7 | |||
8 | /// <summary> | ||
9 | /// Interop class for mscorwks.dll assembly name APIs. | ||
10 | /// </summary> | ||
11 | internal sealed class ClrInterop | ||
12 | { | ||
13 | private static readonly Guid referenceIdentityGuid = new Guid("6eaf5ace-7917-4f3c-b129-e046a9704766"); | ||
14 | |||
15 | /// <summary> | ||
16 | /// Protect the constructor. | ||
17 | /// </summary> | ||
18 | private ClrInterop() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | /// <summary> | ||
23 | /// Represents a reference to the unique signature of a code object. | ||
24 | /// </summary> | ||
25 | [ComImport] | ||
26 | [Guid("6eaf5ace-7917-4f3c-b129-e046a9704766")] | ||
27 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
28 | internal interface IReferenceIdentity | ||
29 | { | ||
30 | /// <summary> | ||
31 | /// Get an assembly attribute. | ||
32 | /// </summary> | ||
33 | /// <param name="attributeNamespace">Attribute namespace.</param> | ||
34 | /// <param name="attributeName">Attribute name.</param> | ||
35 | /// <returns>The assembly attribute.</returns> | ||
36 | [return: MarshalAs(UnmanagedType.LPWStr)] | ||
37 | string GetAttribute( | ||
38 | [In, MarshalAs(UnmanagedType.LPWStr)] string attributeNamespace, | ||
39 | [In, MarshalAs(UnmanagedType.LPWStr)] string attributeName); | ||
40 | |||
41 | /// <summary> | ||
42 | /// Set an assembly attribute. | ||
43 | /// </summary> | ||
44 | /// <param name="attributeNamespace">Attribute namespace.</param> | ||
45 | /// <param name="attributeName">Attribute name.</param> | ||
46 | /// <param name="attributeValue">Attribute value.</param> | ||
47 | void SetAttribute( | ||
48 | [In, MarshalAs(UnmanagedType.LPWStr)] string attributeNamespace, | ||
49 | [In, MarshalAs(UnmanagedType.LPWStr)] string attributeName, | ||
50 | [In, MarshalAs(UnmanagedType.LPWStr)] string attributeValue); | ||
51 | |||
52 | /// <summary> | ||
53 | /// Get an iterator for the assembly's attributes. | ||
54 | /// </summary> | ||
55 | /// <returns>Assembly attribute enumerator.</returns> | ||
56 | IEnumIDENTITY_ATTRIBUTE EnumAttributes(); | ||
57 | |||
58 | /// <summary> | ||
59 | /// Clone an IReferenceIdentity. | ||
60 | /// </summary> | ||
61 | /// <param name="countOfDeltas">Count of deltas.</param> | ||
62 | /// <param name="deltas">The deltas.</param> | ||
63 | /// <returns>Cloned IReferenceIdentity.</returns> | ||
64 | IReferenceIdentity Clone( | ||
65 | [In] IntPtr /*SIZE_T*/ countOfDeltas, | ||
66 | [In, MarshalAs(UnmanagedType.LPArray)] IDENTITY_ATTRIBUTE[] deltas); | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// IEnumIDENTITY_ATTRIBUTE interface. | ||
71 | /// </summary> | ||
72 | [ComImport] | ||
73 | [Guid("9cdaae75-246e-4b00-a26d-b9aec137a3eb")] | ||
74 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
75 | internal interface IEnumIDENTITY_ATTRIBUTE | ||
76 | { | ||
77 | /// <summary> | ||
78 | /// Gets the next attributes. | ||
79 | /// </summary> | ||
80 | /// <param name="celt">Count of elements.</param> | ||
81 | /// <param name="attributes">Array of attributes being returned.</param> | ||
82 | /// <returns>The next attribute.</returns> | ||
83 | uint Next( | ||
84 | [In] uint celt, | ||
85 | [Out, MarshalAs(UnmanagedType.LPArray)] IDENTITY_ATTRIBUTE[] attributes); | ||
86 | |||
87 | /// <summary> | ||
88 | /// Copy the current attribute into a buffer. | ||
89 | /// </summary> | ||
90 | /// <param name="available">Number of available bytes.</param> | ||
91 | /// <param name="data">Buffer into which attribute should be written.</param> | ||
92 | /// <returns>Pointer to buffer containing the attribute.</returns> | ||
93 | IntPtr CurrentIntoBuffer( | ||
94 | [In] IntPtr /*SIZE_T*/ available, | ||
95 | [Out, MarshalAs(UnmanagedType.LPArray)] byte[] data); | ||
96 | |||
97 | /// <summary> | ||
98 | /// Skip past a number of elements. | ||
99 | /// </summary> | ||
100 | /// <param name="celt">Count of elements to skip.</param> | ||
101 | void Skip([In] uint celt); | ||
102 | |||
103 | /// <summary> | ||
104 | /// Reset the enumeration to the beginning. | ||
105 | /// </summary> | ||
106 | void Reset(); | ||
107 | |||
108 | /// <summary> | ||
109 | /// Clone this attribute enumeration. | ||
110 | /// </summary> | ||
111 | /// <returns>Clone of a IEnumIDENTITY_ATTRIBUTE.</returns> | ||
112 | IEnumIDENTITY_ATTRIBUTE Clone(); | ||
113 | } | ||
114 | |||
115 | /// <summary> | ||
116 | /// Gets the guid. | ||
117 | /// </summary> | ||
118 | public static Guid ReferenceIdentityGuid | ||
119 | { | ||
120 | get { return referenceIdentityGuid; } | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// Gets an interface pointer to an object with the specified IID, in the assembly at the specified file path. | ||
125 | /// </summary> | ||
126 | /// <param name="wszAssemblyPath">A valid path to the requested assembly.</param> | ||
127 | /// <param name="riid">The IID of the interface to return.</param> | ||
128 | /// <param name="i">The returned interface pointer.</param> | ||
129 | /// <returns>The error code.</returns> | ||
130 | [DllImport("mscorwks.dll", CharSet = CharSet.Unicode, EntryPoint = "GetAssemblyIdentityFromFile")] | ||
131 | internal static extern uint GetAssemblyIdentityFromFile(System.String wszAssemblyPath, ref Guid riid, out IReferenceIdentity i); | ||
132 | |||
133 | /// <summary> | ||
134 | /// Assembly attributes. Contains data about an IReferenceIdentity. | ||
135 | /// </summary> | ||
136 | [StructLayout(LayoutKind.Sequential)] | ||
137 | internal struct IDENTITY_ATTRIBUTE | ||
138 | { | ||
139 | [MarshalAs(UnmanagedType.LPWStr)] | ||
140 | public string AttributeNamespace; | ||
141 | [MarshalAs(UnmanagedType.LPWStr)] | ||
142 | public string AttributeName; | ||
143 | [MarshalAs(UnmanagedType.LPWStr)] | ||
144 | public string AttributeValue; | ||
145 | } | ||
146 | } | ||
147 | } | ||