Unify argument verification for Marshal.GetHINSTANCE off-Windows (#20130)
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / src / System / Runtime / InteropServices / Marshal.cs
index 74d1e6e..d7d5b0f 100644 (file)
@@ -28,14 +28,15 @@ namespace System.Runtime.InteropServices
     /// </summary>
     public static partial class Marshal
     {
+#if FEATURE_COMINTEROP
+        internal static Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");
+#endif //FEATURE_COMINTEROP
+
         private const int LMEM_FIXED = 0;
         private const int LMEM_MOVEABLE = 2;
 #if !FEATURE_PAL
         private const long HiWordMask = unchecked((long)0xffffffffffff0000L);
 #endif //!FEATURE_PAL
-#if FEATURE_COMINTEROP
-        private static Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");
-#endif //FEATURE_COMINTEROP
 
         // Win32 has the concept of Atoms, where a pointer can either be a pointer
         // or an int.  If it's less than 64K, this is guaranteed to NOT be a 
@@ -852,18 +853,12 @@ namespace System.Runtime.InteropServices
                 throw new ArgumentNullException(nameof(m));
             }
 
-            RuntimeModule rtModule = m as RuntimeModule;
-            if (rtModule == null && m is ModuleBuilder mb)
-            {
-                rtModule = mb.InternalModule;
-            }
-
-            if (rtModule == null)
+            if (m is RuntimeModule rtModule)
             {
-                throw new ArgumentNullException(nameof(m), SR.Argument_MustBeRuntimeModule);
+                return GetHINSTANCE(rtModule.GetNativeHandle());
             }
 
-            return GetHINSTANCE(rtModule.GetNativeHandle());
+            return (IntPtr)(-1);
         }
 
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
@@ -1459,6 +1454,12 @@ namespace System.Runtime.InteropServices
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern object InternalCreateWrapperOfType(object o, Type t);
 
+        /// <summary>
+        /// check if the type is visible from COM.
+        /// </summary>
+        [MethodImplAttribute(MethodImplOptions.InternalCall)]
+        public static extern bool IsTypeVisibleFromCom(Type t);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         public static extern int /* HRESULT */ QueryInterface(IntPtr /* IUnknown */ pUnk, ref Guid iid, out IntPtr ppv);
 
@@ -1507,6 +1508,12 @@ namespace System.Runtime.InteropServices
         /// </summary>
         [MethodImpl(MethodImplOptions.InternalCall)]
         public static extern int GetStartComSlot(Type t);
+
+        /// <summary>
+        /// <para>Returns the last valid COM slot that GetMethodInfoForSlot will work on. </para>
+        /// </summary>
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        public static extern int GetEndComSlot(Type t);
 #endif // FEATURE_COMINTEROP
 
         /// <summary>