1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 using System;
6 using System.Runtime.CompilerServices;
7 using System.Runtime.InteropServices;
8 
9 [assembly: ImportedFromTypeLib("MockInterop")]
10 [assembly: PrimaryInteropAssembly(30303,33)]
11 [assembly: Guid("71B8C65D-7748-447A-B786-64682CBEF136")]
12 [assembly: BestFitMapping(false, ThrowOnUnmappableChar = true)]
13 
14 [assembly: AutomationProxy(false)] // not embed
15 [assembly: ClassInterface(ClassInterfaceType.AutoDual)] // not embed
16 [assembly: ComCompatibleVersion(1, 2, 3, 4)] // not embed
17 [assembly: ComConversionLoss()] // not embed
18 [assembly: ComVisible(true)] // not embed
19 [assembly: TypeLibVersion(1, 0)] // not embed
20 // [assembly: SetWin32ContextInIDispatch()]
21 // [assembly: IDispatchImpl(IDispatchImplType.CompatibleImpl)] // not embed
22 
23 namespace MockInterop01
24 {
25     // [TypeIdentifier("71B8C65D-7748-447A-B786-64682CBEF136", "MockInterop01.InteropEnum")]
26     [Flags, Serializable, Guid("EEEE0B17-2558-447D-B786-84682CBEF136")]
27     public enum InteropEnum : uint
28     {
29         None,
30         Red = 0x0001,
31         Blue = 0x0002,
32         White = 0x0004,
33         All = 0x0007
34     }
35 
36     // [TypeIdentifier("71B8C65D-7748-447A-B786-64682CBEF136", "MockInterop01.UnionStruct")]
37     [Guid("5720C751-2222-447A-B786-64682CBEF122")]
38     [StructLayout(LayoutKind.Explicit)]
39     public struct UnionStruct
40     {
41         [FieldOffset(0)]
42         [TypeLibVar(TypeLibVarFlags.FBindable), MarshalAs(UnmanagedType.I1)]
43         public sbyte field01;
44         [FieldOffset(0)]
45         [TypeLibVar(TypeLibVarFlags.FBindable), MarshalAs(UnmanagedType.U2)]
46         public ushort field02;
47         [FieldOffset(0), MarshalAs(UnmanagedType.I4)]
48         [TypeLibVar(TypeLibVarFlags.FBindable)]
49         public int field03;
50         [FieldOffset(0)]
51         [TypeLibVar(TypeLibVarFlags.FBindable), MarshalAs(UnmanagedType.U8)]
52         public ulong field04;
53     }
54 
55     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 16, Size = 8), ComConversionLoss]
56     public struct ComplexStruct
57     {
58         [StructLayout(LayoutKind.Sequential)]
59         public struct InnterStruct
60         {
61             public Int16 x;
62             public Int64 y;
63             public IntPtr z;
64         }
65         [DispId(1)]
66         public Guid GuidField;
67         [DispId(2)]
68         public Decimal DecimalField;
69         [DispId(3), ComConversionLoss, ComAliasName("MockInterop01.UnionStruct"), MarshalAs(UnmanagedType.Struct)]
70         public UnionStruct UnionField;
71     }
72 
73     [ComImport /*, TypeIdentifier*/]
74     [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
75     [Guid("5720C75D-2448-447A-B786-64682CBEF156")]
76     [TypeLibType(TypeLibTypeFlags.FAggregatable)]
77     public interface IFoo
78     {
79         [DispId(1010)]
80         InteropEnum IFooReadOnlyProp {
81             [return: MarshalAs(UnmanagedType.U4), ComConversionLoss]
82             get;
83         }
84 
85         [DispId(1011)]
86         [return: MarshalAs(UnmanagedType.Struct)]
MethodForStruct(ref UnionStruct p1, out InteropDeleWithStructArray p2)87         ComplexStruct MethodForStruct(ref UnionStruct p1, out InteropDeleWithStructArray p2);
88 
89         [DispId(1012)]
90         string this[string p, IFoo p2] {
91             [return: MarshalAs(UnmanagedType.BStr)]
92             get; set; }
93 
94         [DispId(1013)]
95         event InteropDeleWithStructArray IFooEvent;
96     }
97 
98     [ComImport, Guid("ABCDEF5D-2448-447A-B786-64682CBEF123")]
99     [TypeLibImportClass(typeof(object))]
100     public interface IBar
101     {
102         [AllowReversePInvokeCalls()]
DoSomething(params string[] ary)103         object DoSomething(params string[] ary);
104         [ComRegisterFunction()]
Register([MarshalAs(UnmanagedType.IDispatch), Optional, DefaultParameterValue(null)] ref object o)105         object Register([MarshalAs(UnmanagedType.IDispatch), Optional, DefaultParameterValue(null)] ref object o);
106         [ComUnregisterFunction()]
UnRegister([MarshalAs(UnmanagedType.IDispatch), Optional, IDispatchConstant()] object o)107         void UnRegister([MarshalAs(UnmanagedType.IDispatch), Optional, IDispatchConstant()] object o);
108         [TypeLibFunc(TypeLibFuncFlags.FDefaultBind)]
LibFunc([Optional, DecimalConstant(1, 2, (uint)3, (uint)4, (uint)5)] decimal p1, [Optional, In, Out, DateTimeConstant(123456)] DateTime p2)109         void LibFunc([Optional, DecimalConstant(1, 2, (uint)3, (uint)4, (uint)5)] decimal p1, [Optional, In, Out, DateTimeConstant(123456)] DateTime p2);
110     }
111 
112     /// <summary>
113     /// Source Interface
114     /// </summary>
115     [ComImport, Guid("904458F3-005B-4DFD-8581-E9832D7FA433")]
116     [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch), TypeLibType(TypeLibTypeFlags.FDispatchable)]
117     public interface IEventSource
118     {
119         [DispId(101), PreserveSig]
Event01(IFoo p1)120         void Event01(IFoo p1);
121         [DispId(102), PreserveSig]
Event02(InteropEnum p1)122         void Event02(InteropEnum p1);
123         [DispId(103), PreserveSig]
Event03(ComplexStruct p1)124         void Event03(ComplexStruct p1);
125     }
126 
127     /// <summary>
128     /// Event Interface
129     /// </summary>
130     [ComEventInterface(typeof(IEventSource), typeof(object))]
131     public interface IEventEvent
132     {
133         event EventDele01 OnEvent01;
134         event EventDele02 OnEvent02;
135         event EventDele03 OnEvent03;
136     }
137 
EventDele01(IFoo p)138     public delegate void EventDele01(IFoo p);
EventDele02(InteropEnum p)139     public delegate void EventDele02(InteropEnum p);
EventDele03(ComplexStruct p)140     public delegate void EventDele03(ComplexStruct p);
141 
142     // [TypeIdentifier("71B8C65D-7748-447A-B786-64682CBEF136", "MockInterop01.InteropDeleWithStructArray")]
143     [UnmanagedFunctionPointerAttribute(CallingConvention.StdCall, BestFitMapping = false, CharSet = CharSet.Auto)]
InteropDeleWithStructArray([In, Out, ComAliasName(R), MarshalAs(UnmanagedType.LPArray)] UnionStruct[] p)144     public delegate void InteropDeleWithStructArray([In, Out, ComAliasName("MockInterop01.UnionStruct"), MarshalAs(UnmanagedType.LPArray)] UnionStruct[] p);
145 }
146