[Mono-dev] RE: Com Interop Patch - mcs
Paolo Molaro
lupus at ximian.com
Mon Jan 9 11:23:20 EST 2006
On 01/06/06 Jonathan S. Chambers wrote:
> Here the patch for the class libs.
> Index: class/corlib/System/ComProxy.cs
> ===================================================================
> --- mcs/class/corlib/System/ComProxy.cs (revision 0)
> +++ mcs/class/corlib/System/ComProxy.cs (revision 0)
[...]
> +namespace System
> +{
> + internal class ComProxy : System.Runtime.Remoting.Proxies.RealProxy, System.Runtime.Remoting.IRemotingTypeInfo
> + {
> + #region Sync with object-internals.h
> + private IntPtr _com_object;
> + private string _typeName;
> + #endregion
Please use TAB characters to indent the source code, not spaces.
> Index: mcs/class/corlib/System/__ComObject.cs
> ===================================================================
> --- mcs/class/corlib/System/__ComObject.cs (revision 55123)
> +++ mcs/class/corlib/System/__ComObject.cs (working copy)
> @@ -32,21 +32,106 @@
>
> namespace System
> {
> - // This is a private class that is used as a generic wrapper class
> - // for COM objects that have no specific wrapper class.
> - //
> - // It has no public methods, it's functionality is exposed trough
> - // System.Runtime.InteropServices.Marshal class and can be casted to
> - // any interface that is implemented by the wrapped COM object.
> - //
> - // This class is referenced in .NET Framework SDK Documentation so
> - // many times that obj.GetType().FullName == "System.__ComObject" and
> - // Type.GetType("System.__ComObject") may be used.
> + using System.Runtime.InteropServices;
> + // This is a private class that is used as a generic wrapper class
> + // for COM objects that have no specific wrapper class.
> + //
> + // It has no public methods, it's functionality is exposed trough
> + // System.Runtime.InteropServices.Marshal class and can be casted to
> + // any interface that is implemented by the wrapped COM object.
> + //
> + // This class is referenced in .NET Framework SDK Documentation so
> + // many times that obj.GetType().FullName == "System.__ComObject" and
> + // Type.GetType("System.__ComObject") may be used.
>
> - internal class __ComObject : MarshalByRefObject
> - {
> - private __ComObject ()
> - {
> - }
> - }
> + internal class __ComObject : MarshalByRefObject
> + {
> + private IntPtr _iunk;
> + private __ComObject()
> + {
> + }
> + }
Please, put back the correct indentation with TABs.
> + public static int AddRef(IntPtr pUnk)
> + {
> + IntPtr vtable = Marshal.ReadIntPtr(pUnk);
> + IntPtr qi = Marshal.ReadIntPtr(vtable);
> + // QueryInterface is 2st method
> + IntPtr pAddRef = (IntPtr)(qi.ToInt64() + IntPtr.Size);
> + AddRefDelegate add_ref = (AddRefDelegate)Marshal.GetDelegateForFunctionPointer(pAddRef, typeof(AddRefDelegate));
> + return add_ref(pUnk);
> + }
Moving code to the managed side is sometimes the best way to implement
some things: this method is the proof that sometimes it's an orrible
idea:-) This stuff shuld be done in the C runtime.
> - throw new NotImplementedException ();
> + object [] attrs = t.GetCustomAttributes(typeof(System.Runtime.InteropServices.InterfaceTypeAttribute), false);
> + if (attrs == null || attrs.Length == 0)
Use Attribute.IsDefined ().
> + public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
> + {
> + IntPtr vtable = Marshal.ReadIntPtr(pUnk);
> + IntPtr qi = Marshal.ReadIntPtr(vtable);
> + // QueryInterface is 1st method
> + QueryInterfaceDelegate query_interface = (QueryInterfaceDelegate)Marshal.GetDelegateForFunctionPointer(qi, typeof(QueryInterfaceDelegate));
> + return query_interface(pUnk, ref iid, out ppv);
> + }
Move to unmanaged.
> + public static int Release(IntPtr pUnk)
> + {
> + Console.WriteLine("In Marshal.Release pUnk = {0}", pUnk);
> + IntPtr vtable = Marshal.ReadIntPtr(pUnk);
> + Console.WriteLine("In Marshal.Release 1");
> + IntPtr qi = Marshal.ReadIntPtr((IntPtr)(vtable.ToInt64() + 2 * IntPtr.Size));
> + Console.WriteLine("In Marshal.Release 2");
> + // QueryInterface is 3rd method
> + IntPtr pRelease = qi;//(IntPtr)(qi.ToInt64() + 2 * IntPtr.Size);
> + Console.WriteLine("In Marshal.Release 3");
> + ReleaseDelegate release = (ReleaseDelegate)Marshal.GetDelegateForFunctionPointer(pRelease, typeof(ReleaseDelegate));
> + Console.WriteLine("In Marshal.Release 4");
> + int count = release(pUnk);
> + Console.WriteLine("In Marshal.Release 5 count = {0}", count);
> + return count;
> + }
Idem.
> Index: mcs/class/corlib/System.Runtime.InteropServices/UnmanagedFunctionPointerAttribute.cs
> ===================================================================
> --- mcs/class/corlib/System.Runtime.InteropServices/UnmanagedFunctionPointerAttribute.cs (revision 55123)
> +++ mcs/class/corlib/System.Runtime.InteropServices/UnmanagedFunctionPointerAttribute.cs (working copy)
> @@ -26,14 +26,18 @@
> // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> //
>
> -#if NET_2_0
>
> using System;
>
> namespace System.Runtime.InteropServices {
>
> [AttributeUsage (AttributeTargets.Delegate, Inherited = false)]
> +
> +#if NET_2_0
> public sealed class UnmanagedFunctionPointerAttribute: Attribute {
> +#else
> + internal sealed class UnmanagedFunctionPointerAttribute : Attribute {
> +#endif
Put only public/internal inside the ifdef, but I guess you won't neede
this after properly moving some things to the unmanaged world.
> Index: mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs
> ===================================================================
> --- mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs (revision 55123)
> +++ mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs (working copy)
> @@ -58,11 +58,10 @@
> MarshalByRefObject _server;
> int _targetDomainId = -1;
> internal string _targetUri;
> - #endregion
> -
> internal Identity _objectIdentity;
> Object _objTP;
> - object _stubData;
> + object _stubData;
> + #endregion
Please fix the indentation.
Thanks!
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list