internal static ComInteropProxy GetProxy(IntPtr pItf, Type t) { Guid iid_IUnknown = __ComObject.IID_IUnknown; IntPtr intPtr; int errorCode = Marshal.QueryInterface(pItf, ref iid_IUnknown, out intPtr); Marshal.ThrowExceptionForHR(errorCode); 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); }
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); }