// Gets the proxy of the specified COM type. If the COM type is // already known, a cached proxy will be returned. internal static ComInteropProxy CreateProxy(Type t) { IntPtr iunknown = __ComObject.CreateIUnknown(t); ComInteropProxy proxy; ComInteropProxy cachedProxy = FindProxy(iunknown); if (cachedProxy != null) { // check that the COM type of the cached proxy matches // the requested type. See 2nd part of bug #520437. Type cachedType = cachedProxy.com_object.GetType(); if (cachedType != t) { throw new InvalidCastException(String.Format("Unable to cast object of type '{0}' to type '{1}'.", cachedType, t)); } proxy = cachedProxy; Marshal.Release(iunknown); } else { proxy = new ComInteropProxy(t); proxy.com_object.Initialize(iunknown, proxy); } return(proxy); }
void CacheProxy() { // called from unmanaged code after .ctor is invoked // we need .ctor to create unmanaged object and thus IUnknown property value ComInteropProxy proxy = null; FindProxy(com_object.IUnknown, ref proxy); if (proxy == null) { var self = this; AddProxy(com_object.IUnknown, ref self); } else { System.Threading.Interlocked.Increment(ref ref_count); } }
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); }
internal static ComInteropProxy GetProxy(IntPtr pItf, Type t) { IntPtr ppv; Guid iid = __ComObject.IID_IUnknown; int hr = Marshal.QueryInterface(pItf, ref iid, out ppv); Marshal.ThrowExceptionForHR(hr); ComInteropProxy obj = FindProxy(ppv); if (obj == null) { Marshal.Release(ppv); return(new ComInteropProxy(ppv)); } else { Marshal.Release(ppv); System.Threading.Interlocked.Increment(ref obj.ref_count); return(obj); } }
internal __ComObject (IntPtr pItf, ComInteropProxy p) { proxy = p; InitializeApartmentDetails (); Guid iid = IID_IUnknown; int hr = Marshal.QueryInterface (pItf, ref iid, out iunknown); Marshal.ThrowExceptionForHR (hr); }
internal void Initialize (IntPtr pUnk, ComInteropProxy p) { proxy = p; InitializeApartmentDetails (); iunknown = pUnk; }
private extern static void AddProxy(IntPtr pItf, ComInteropProxy proxy);
public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t) { ComInteropProxy proxy = new ComInteropProxy (pUnk, t); __ComObject co = (__ComObject)proxy.GetTransparentProxy (); foreach (Type itf in t.GetInterfaces ()) { if ((itf.Attributes & TypeAttributes.Import) == TypeAttributes.Import) { if (co.GetInterface (itf) == IntPtr.Zero) return null; } } return co; }
private extern static void AddProxy (IntPtr pItf, ComInteropProxy proxy);
// Gets the proxy of the specified COM type. If the COM type is // already known, a cached proxy will be returned. internal static ComInteropProxy CreateProxy (Type t) { ComInteropProxy proxy = new ComInteropProxy (t); proxy.com_object.Initialize (t); ComInteropProxy cachedProxy = FindProxy (proxy.com_object.IUnknown); if (cachedProxy != null) { // check that the COM type of the cached proxy matches // the requested type. See 2nd part of bug #520437. Type cachedType = cachedProxy.com_object.GetType (); if (cachedType != t) throw new InvalidCastException (String.Format ("Unable to cast object of type '{0}' to type '{1}'.", cachedType, t)); return cachedProxy; } return proxy; }
internal extern static void FindProxy(IntPtr pItf, ref ComInteropProxy proxy);
private static void AddProxy(IntPtr pItf, ComInteropProxy proxy) { throw new System.NotImplementedException(); }
private static void AddProxy (IntPtr pItf, ComInteropProxy proxy) { throw new System.NotImplementedException(); }
private void CacheProxy() { ComInteropProxy.AddProxy(this.com_object.IUnknown, this); }