130 lines
3.8 KiB
C#
130 lines
3.8 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.Remoting;
|
|
using System.Runtime.Remoting.Messaging;
|
|
using System.Runtime.Remoting.Proxies;
|
|
using System.Threading;
|
|
|
|
namespace Mono.Interop
|
|
{
|
|
// Token: 0x02000091 RID: 145
|
|
internal class ComInteropProxy : RealProxy, IRemotingTypeInfo
|
|
{
|
|
// Token: 0x06000831 RID: 2097 RVA: 0x0001E128 File Offset: 0x0001C328
|
|
private ComInteropProxy(Type t)
|
|
: base(t)
|
|
{
|
|
this.com_object = __ComObject.CreateRCW(t);
|
|
}
|
|
|
|
// Token: 0x06000832 RID: 2098 RVA: 0x0001E144 File Offset: 0x0001C344
|
|
private ComInteropProxy(IntPtr pUnk)
|
|
: this(pUnk, typeof(__ComObject))
|
|
{
|
|
}
|
|
|
|
// Token: 0x06000833 RID: 2099 RVA: 0x0001E158 File Offset: 0x0001C358
|
|
internal ComInteropProxy(IntPtr pUnk, Type t)
|
|
: base(t)
|
|
{
|
|
this.com_object = new __ComObject(pUnk);
|
|
this.CacheProxy();
|
|
}
|
|
|
|
// Token: 0x06000834 RID: 2100
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
private static extern void AddProxy(IntPtr pItf, ComInteropProxy proxy);
|
|
|
|
// Token: 0x06000835 RID: 2101
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
internal static extern ComInteropProxy FindProxy(IntPtr pItf);
|
|
|
|
// Token: 0x06000836 RID: 2102 RVA: 0x0001E188 File Offset: 0x0001C388
|
|
private void CacheProxy()
|
|
{
|
|
ComInteropProxy.AddProxy(this.com_object.IUnknown, this);
|
|
}
|
|
|
|
// Token: 0x06000837 RID: 2103 RVA: 0x0001E19C File Offset: 0x0001C39C
|
|
internal static ComInteropProxy GetProxy(IntPtr pItf, Type t)
|
|
{
|
|
Guid iid_IUnknown = __ComObject.IID_IUnknown;
|
|
IntPtr intPtr;
|
|
int num = Marshal.QueryInterface(pItf, ref iid_IUnknown, out intPtr);
|
|
Marshal.ThrowExceptionForHR(num);
|
|
ComInteropProxy comInteropProxy = ComInteropProxy.FindProxy(intPtr);
|
|
if (comInteropProxy == null)
|
|
{
|
|
Marshal.Release(pItf);
|
|
return new ComInteropProxy(intPtr);
|
|
}
|
|
Marshal.Release(pItf);
|
|
Interlocked.Increment(ref comInteropProxy.ref_count);
|
|
return comInteropProxy;
|
|
}
|
|
|
|
// Token: 0x06000838 RID: 2104 RVA: 0x0001E1F0 File Offset: 0x0001C3F0
|
|
internal static ComInteropProxy CreateProxy(Type t)
|
|
{
|
|
ComInteropProxy comInteropProxy = new ComInteropProxy(t);
|
|
comInteropProxy.com_object.Initialize(t);
|
|
ComInteropProxy comInteropProxy2 = ComInteropProxy.FindProxy(comInteropProxy.com_object.IUnknown);
|
|
if (comInteropProxy2 == null)
|
|
{
|
|
return comInteropProxy;
|
|
}
|
|
Type type = comInteropProxy2.com_object.GetType();
|
|
if (type != t)
|
|
{
|
|
throw new InvalidCastException(string.Format("Unable to cast object of type '{0}' to type '{1}'.", type, t));
|
|
}
|
|
return comInteropProxy2;
|
|
}
|
|
|
|
// Token: 0x06000839 RID: 2105 RVA: 0x0001E250 File Offset: 0x0001C450
|
|
public override IMessage Invoke(IMessage msg)
|
|
{
|
|
Console.WriteLine("Invoke");
|
|
Console.WriteLine(Environment.StackTrace);
|
|
throw new Exception("The method or operation is not implemented.");
|
|
}
|
|
|
|
// Token: 0x170000E2 RID: 226
|
|
// (get) Token: 0x0600083A RID: 2106 RVA: 0x0001E270 File Offset: 0x0001C470
|
|
// (set) Token: 0x0600083B RID: 2107 RVA: 0x0001E278 File Offset: 0x0001C478
|
|
public string TypeName
|
|
{
|
|
get
|
|
{
|
|
return this.type_name;
|
|
}
|
|
set
|
|
{
|
|
this.type_name = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600083C RID: 2108 RVA: 0x0001E284 File Offset: 0x0001C484
|
|
public bool CanCastTo(Type fromType, object o)
|
|
{
|
|
__ComObject _ComObject = o as __ComObject;
|
|
if (_ComObject == null)
|
|
{
|
|
throw new NotSupportedException("Only RCWs are currently supported");
|
|
}
|
|
return (fromType.Attributes & TypeAttributes.Import) != TypeAttributes.NotPublic && !(_ComObject.GetInterface(fromType, false) == IntPtr.Zero);
|
|
}
|
|
|
|
// Token: 0x040001A8 RID: 424
|
|
private __ComObject com_object;
|
|
|
|
// Token: 0x040001A9 RID: 425
|
|
private int ref_count = 1;
|
|
|
|
// Token: 0x040001AA RID: 426
|
|
private string type_name;
|
|
}
|
|
}
|