[Mono-dev] [PATCH] Implement Marshal.GetHINSTANCE

Rodrigo Kumpera kumpera at gmail.com
Wed Jun 18 19:47:47 EDT 2008


This patch looks fine to be commited.



2008/6/18 Kornél Pál <kornelpal at gmail.com>:

> Hi,
>
> This patch implements GetHINSTANCE:
> Returns HINSTANCE (same as HMODULE) for modules loaded using LoadLibrary,
> otherwise returns -1. As a result -1 is returned on non-Windows platforms.
>
> If you like the patch please approve it.
>
> Kornél
>
> Index: mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
> ===================================================================
> --- mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs  (revision
> 106149)
> +++ mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs  (working
> copy)
> @@ -377,10 +377,12 @@
>                        throw new NotImplementedException ();
>                }
>
> -               [MonoTODO]
>                public static IntPtr GetHINSTANCE (Module m)
>                {
> -                       throw new NotImplementedException ();
> +                       if (m == null)
> +                               throw new ArgumentNullException ("m");
> +
> +                       return m.GetHINSTANCE ();
>                }
>
>                [MonoTODO ("SetErrorInfo")]
> Index: mcs/class/corlib/System.Reflection/Module.cs
> ===================================================================
> --- mcs/class/corlib/System.Reflection/Module.cs        (revision 106149)
> +++ mcs/class/corlib/System.Reflection/Module.cs        (working copy)
> @@ -446,6 +446,9 @@
>                }
>
>                [MethodImplAttribute (MethodImplOptions.InternalCall)]
> +               internal extern IntPtr GetHINSTANCE ();
> +
> +               [MethodImplAttribute (MethodImplOptions.InternalCall)]
>                private extern string GetGuidInternal ();
>
>                [MethodImplAttribute (MethodImplOptions.InternalCall)]
> Index: mono/mono/metadata/icall-def.h
> ===================================================================
> --- mono/mono/metadata/icall-def.h      (revision 106149)
> +++ mono/mono/metadata/icall-def.h      (working copy)
> @@ -523,6 +523,7 @@
>  ICALL(MODULE_1, "Close", ves_icall_System_Reflection_Module_Close)
>  ICALL(MODULE_2, "GetGlobalType",
> ves_icall_System_Reflection_Module_GetGlobalType)
>  ICALL(MODULE_3, "GetGuidInternal",
> ves_icall_System_Reflection_Module_GetGuidInternal)
> +ICALL(MODULE_14, "GetHINSTANCE",
> ves_icall_System_Reflection_Module_GetHINSTANCE)
>  ICALL(MODULE_4, "GetMDStreamVersion",
> ves_icall_System_Reflection_Module_GetMDStreamVersion)
>  ICALL(MODULE_5, "GetPEKind", ves_icall_System_Reflection_Module_GetPEKind)
>  ICALL(MODULE_6, "InternalGetTypes",
> ves_icall_System_Reflection_Module_InternalGetTypes)
> Index: mono/mono/metadata/icall.c
> ===================================================================
> --- mono/mono/metadata/icall.c  (revision 106149)
> +++ mono/mono/metadata/icall.c  (working copy)
> @@ -5210,6 +5210,17 @@
>        return mono_string_new (domain, module->image->guid);
>  }
>
> +static gpointer
> +ves_icall_System_Reflection_Module_GetHINSTANCE (MonoReflectionModule
> *module)
> +{
> +#ifdef PLATFORM_WIN32
> +       if (module->image && module->image->is_module_handle)
> +               return module->image->raw_data;
> +#endif
> +
> +       return (gpointer) (-1);
> +}
> +
>  static void
>  ves_icall_System_Reflection_Module_GetPEKind (MonoImage *image, gint32
> *pe_kind, gint32 *machine)
>  {
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080618/ba470d4a/attachment.html 


More information about the Mono-devel-list mailing list