| 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.Core.Native.Msm |
| 4 | { |
| 5 | using System; |
| 6 | using System.Runtime.InteropServices; |
| 7 | |
| 8 | /// <summary> |
| 9 | /// Merge merge modules into an MSI file. |
| 10 | /// </summary> |
| 11 | [ComImport, Guid("F94985D5-29F9-4743-9805-99BC3F35B678")] |
| 12 | public class MsmMerge2 |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | /// <summary> |
| 17 | /// Defines the standard COM IClassFactory interface. |
| 18 | /// </summary> |
| 19 | [ComImport, Guid("00000001-0000-0000-C000-000000000046")] |
| 20 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] |
| 21 | public interface IClassFactory |
| 22 | { |
| 23 | /// <summary> |
| 24 | /// |
| 25 | /// </summary> |
| 26 | [return: MarshalAs(UnmanagedType.IUnknown)] |
| 27 | object CreateInstance(IntPtr unkOuter, [MarshalAs(UnmanagedType.LPStruct)] Guid iid); |
| 28 | } |
| 29 | |
| 30 | /// <summary> |
| 31 | /// Contains native methods for merge operations. |
| 32 | /// </summary> |
| 33 | public static class MsmInterop |
| 34 | { |
| 35 | [DllImport("mergemod.dll", EntryPoint = "DllGetClassObject", PreserveSig = false)] |
| 36 | [return: MarshalAs(UnmanagedType.IUnknown)] |
| 37 | private static extern object MergeModGetClassObject([MarshalAs(UnmanagedType.LPStruct)] Guid clsid, [MarshalAs(UnmanagedType.LPStruct)] Guid iid); |
| 38 | |
| 39 | /// <summary> |
| 40 | /// Load the merge object directly from a local mergemod.dll without going through COM registration. |
| 41 | /// </summary> |
| 42 | /// <returns>Merge interface.</returns> |
| 43 | public static IMsmMerge2 GetMsmMerge() |
| 44 | { |
| 45 | var classFactory = (IClassFactory)MergeModGetClassObject(typeof(MsmMerge2).GUID, typeof(IClassFactory).GUID); |
| 46 | return (IMsmMerge2)classFactory.CreateInstance(IntPtr.Zero, typeof(IMsmMerge2).GUID); |
| 47 | } |
| 48 | } |
| 49 | } |