Add few Interop Marshal APIs (dotnet/coreclr#7742)
authorFaizur Rahman <shrah@microsoft.com>
Tue, 25 Oct 2016 04:21:29 +0000 (21:21 -0700)
committerJan Kotas <jkotas@microsoft.com>
Tue, 25 Oct 2016 04:21:29 +0000 (21:21 -0700)
Add the following interop Marshal APIs:
M:System.Runtime.InteropServices.Marshal.GenerateGuidForType(System.Type)
M:System.Runtime.InteropServices.Marshal.GenerateProgIdForType(System.Type)
M:System.Runtime.InteropServices.Marshal.GetComObjectData(System.Object,System.Object)
M:System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Module)
M:System.Runtime.InteropServices.Marshal.GetIDispatchForObject(System.Object)
M:System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(System.IntPtr,System.Type)
M:System.Runtime.InteropServices.Marshal.PtrToStringAuto(System.IntPtr)
M:System.Runtime.InteropServices.Marshal.SetComObjectData(System.Object,System.Object,System.Object)
M:System.Runtime.InteropServices.Marshal.StringToCoTaskMemAuto(System.String)
M:System.Runtime.InteropServices.Marshal.StringToHGlobalAuto(System.String)

Commit migrated from https://github.com/dotnet/coreclr/commit/3103a70d1fbe733d2b4e7ed9e2ff795b888b8b79

src/coreclr/src/mscorlib/model.xml
src/coreclr/src/mscorlib/ref/mscorlib.cs
src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs
src/coreclr/src/mscorlib/src/System/Runtime/InteropServices/NonPortable.cs
src/coreclr/src/vm/ecalllist.h

index 178ed9d..c051360 100644 (file)
       <Member Name="FinalReleaseComObject(System.Object)" />
       <Member Name="FreeHGlobal(System.IntPtr)" />
       <Member Name="FreeCoTaskMem(System.IntPtr)" />
+      <Member Name="GenerateGuidForType(System.Type)" />
+      <Member Name="GenerateProgIdForType(System.Type)" />      
       <Member Name="GetComInterfaceForObject(System.Object,System.Type)" />
       <Member Name="GetComInterfaceForObject(System.Object,System.Type,System.Runtime.InteropServices.CustomQueryInterfaceMode)" />
+      <Member Name="GetComObjectData(System.Object,System.Object)" />
       <Member Name="GetDelegateForFunctionPointer(System.IntPtr,System.Type)" />
       <Member Name="GetExceptionForHR(System.Int32)" />
       <Member Name="GetExceptionForHR(System.Int32,System.IntPtr)" />
       <Member Name="GetFunctionPointerForDelegate(System.Delegate)" />
       <Member Name="GetHRForException(System.Exception)" />
+      <Member Name="GetHINSTANCE(System.Reflection.Module)" />
+      <Member Name="GetIDispatchForObject(System.Object)" />
       <Member Name="GetIUnknownForObject(System.Object)" />
       <Member Name="GetLastWin32Error" />
       <Member Name="GetHRForLastWin32Error" />
       <Member Name="ReadIntPtr(System.IntPtr,System.Int32)" />
       <Member Name="Release(System.IntPtr)" />
       <Member Name="ReleaseComObject(System.Object)" />
+      <Member Name="SetComObjectData(System.Object,System.Object,System.Object)" />
       <Member Name="SetLastWin32Error(System.Int32)" />
       <Member Name="SizeOf(System.Object)" />
       <Member Name="SizeOf(System.Type)" />
       <Member Name="StructureToPtr(System.Object,System.IntPtr,System.Boolean)" />
       <Member Name="ThrowExceptionForHR(System.Int32)" />
       <Member Name="ThrowExceptionForHR(System.Int32,System.IntPtr)" />
+      <Member Name="GetTypedObjectForIUnknown(System.IntPtr,System.Type)" />
       <Member Name="UnsafeAddrOfPinnedArrayElement(System.Array,System.Int32)" />
       <Member Name="WriteByte(System.IntPtr,System.Byte)" />
       <Member Name="WriteByte(System.IntPtr,System.Int32,System.Byte)" />
index 994a62f..6524f55 100644 (file)
@@ -10802,11 +10802,17 @@ namespace System.Runtime.InteropServices
         [System.Security.SecurityCriticalAttribute]
         public static void FreeHGlobal(System.IntPtr hglobal) { }
         [System.Security.SecurityCriticalAttribute]
+        public static Guid GenerateGuidForType(System.Type type) { throw null; }
+        [System.Security.SecurityCritical]
+        public static string GenerateProgIdForType(System.Type type) { throw null; }        
+        [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr GetComInterfaceForObject(object o, System.Type T) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr GetComInterfaceForObject(object o, System.Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr GetComInterfaceForObject<T, TInterface>(T o) { throw null; }
+        [System.Security.SecurityCritical]
+        public static object GetComObjectData(object obj, object key) { throw null; }        
         [System.Security.SecurityCriticalAttribute]
         public static System.Delegate GetDelegateForFunctionPointer(System.IntPtr ptr, System.Type t) { throw null; }
         [System.Security.SecurityCriticalAttribute]
@@ -10821,10 +10827,14 @@ namespace System.Runtime.InteropServices
         public static System.IntPtr GetFunctionPointerForDelegate(System.Delegate d) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) { throw null; }
+        [System.Security.SecurityCritical]
+        public static System.IntPtr GetHINSTANCE(System.Reflection.Module m) { throw null; }
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)][System.Security.SecurityCriticalAttribute]
         public static int GetHRForException(System.Exception e) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static int GetHRForLastWin32Error() { throw null; }
+        [System.Security.SecurityCritical]
+        public static System.IntPtr GetIDispatchForObject(object o) { throw null; }        
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr GetIUnknownForObject(object o) { throw null; }
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)][System.Security.SecurityCriticalAttribute]
@@ -10845,6 +10855,8 @@ namespace System.Runtime.InteropServices
         public static T[] GetObjectsForNativeVariants<T>(System.IntPtr aSrcNativeVariant, int cVars) { throw null; }
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)][System.Security.SecurityCriticalAttribute]
         public static int GetStartComSlot(System.Type t) { throw null; }
+        [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)][System.Security.SecurityCritical]
+        public static object GetTypedObjectForIUnknown(System.IntPtr pUnk, System.Type t) { throw null; }        
         public static System.Type GetTypeFromCLSID(System.Guid clsid) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static string GetTypeInfoName(System.Runtime.InteropServices.ComTypes.ITypeInfo typeInfo) { throw null; }
@@ -10861,6 +10873,8 @@ namespace System.Runtime.InteropServices
         public static string PtrToStringAnsi(System.IntPtr ptr) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static string PtrToStringAnsi(System.IntPtr ptr, int len) { throw null; }
+        [System.Security.SecurityCritical]
+        public static string PtrToStringAuto(System.IntPtr ptr) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static string PtrToStringBSTR(System.IntPtr ptr) { throw null; }
         [System.Security.SecurityCriticalAttribute]
@@ -10921,6 +10935,8 @@ namespace System.Runtime.InteropServices
         public static int Release(System.IntPtr pUnk) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static int ReleaseComObject(object o) { throw null; }
+        [System.Security.SecurityCritical]
+        public static bool SetComObjectData(object obj, object key, object data) { throw null; }        
         [System.Runtime.InteropServices.ComVisibleAttribute(true)]
         public static int SizeOf(object structure) { throw null; }
         public static int SizeOf(System.Type t) { throw null; }
@@ -10930,12 +10946,16 @@ namespace System.Runtime.InteropServices
         public static System.IntPtr StringToBSTR(string s) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr StringToCoTaskMemAnsi(string s) { throw null; }
+        [System.Security.SecurityCritical]
+        public static System.IntPtr StringToCoTaskMemAuto(string s) { throw null; }        
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr StringToCoTaskMemUni(string s) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr StringToCoTaskMemUTF8(string s) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr StringToHGlobalAnsi(string s) { throw null; }
+        [System.Security.SecurityCritical]
+        public static System.IntPtr StringToHGlobalAuto(string s) { throw null; }
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr StringToHGlobalUni(string s) { throw null; }
         [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)][System.Runtime.InteropServices.ComVisibleAttribute(true)]
index 86e8830..7497c24 100644 (file)
@@ -1072,6 +1072,7 @@ namespace System.Runtime.InteropServices
             DestroyStructure(ptr, typeof(T));
         }
 
+#if FEATURE_COMINTEROP
         //====================================================================
         // Returns the HInstance for this module.  Returns -1 if the module 
         // doesn't have an HInstance.  In Memory (Dynamic) Modules won't have 
@@ -1103,6 +1104,7 @@ namespace System.Runtime.InteropServices
         [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
         private extern static IntPtr GetHINSTANCE(RuntimeModule m);
 
+#endif // FEATURE_COMINTEROP
         //====================================================================
         // Throws a CLR exception based on the HRESULT.
         //====================================================================
@@ -1737,6 +1739,7 @@ namespace System.Runtime.InteropServices
         //====================================================================
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
         internal static extern IntPtr /* IUnknown* */ GetRawIUnknownForComObjectNoAddRef(Object o);
+#endif // FEATURE_COMINTEROP
 
         //====================================================================
         // return the IDispatch* for an Object
@@ -1744,9 +1747,14 @@ namespace System.Runtime.InteropServices
         [System.Security.SecurityCritical]  // auto-generated_required
         public static IntPtr /* IDispatch */ GetIDispatchForObject(Object o)
         {
+#if FEATURE_CORECLR
+            throw new PlatformNotSupportedException();
+#else         
             return GetIDispatchForObjectNative(o, false);
+#endif // FEATURE_CORECLR            
         }
-
+        
+#if FEATURE_COMINTEROP
         //====================================================================
         // return the IDispatch* for an Object if the current context
         // is the one where the RCW was first seen. Will return null 
@@ -2083,6 +2091,7 @@ namespace System.Runtime.InteropServices
 
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
         internal static extern void InternalFinalReleaseComObject(Object o);
+#endif // FEATURE_COMINTEROP
 
         //====================================================================
         // This method retrieves data from the COM object.
@@ -2090,6 +2099,9 @@ namespace System.Runtime.InteropServices
         [System.Security.SecurityCritical]  // auto-generated_required
         public static Object GetComObjectData(Object obj, Object key)
         {
+#if FEATURE_CORECLR
+            throw new PlatformNotSupportedException();
+#else        
             // Validate that the arguments aren't null.
             if (obj == null)
                 throw new ArgumentNullException("obj");
@@ -2116,6 +2128,7 @@ namespace System.Runtime.InteropServices
 
             // Retrieve the data from the __ComObject.
             return comObj.GetData(key);
+#endif // FEATURE_CORECLR            
         }
 
         //====================================================================
@@ -2127,6 +2140,9 @@ namespace System.Runtime.InteropServices
         [System.Security.SecurityCritical]  // auto-generated_required
         public static bool SetComObjectData(Object obj, Object key, Object data)
         {
+#if FEATURE_CORECLR
+            throw new PlatformNotSupportedException();
+#else          
             // Validate that the arguments aren't null. The data can validly be null.
             if (obj == null)
                 throw new ArgumentNullException("obj");
@@ -2153,8 +2169,10 @@ namespace System.Runtime.InteropServices
 
             // Retrieve the data from the __ComObject.
             return comObj.SetData(key, data);
+#endif // FEATURE_CORECLR            
         }
 
+#if FEATURE_COMINTEROP
         //====================================================================
         // This method takes the given COM object and wraps it in an object
         // of the specified type. The type must be derived from __ComObject.
@@ -2340,6 +2358,7 @@ namespace System.Runtime.InteropServices
 
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
         private static extern int InternalGetComSlotForMethodInfo(IRuntimeMethodInfo m);
+#endif // FEATURE_COMINTEROP
 
         //====================================================================
         // This method generates a GUID for the specified type. If the type
@@ -2350,6 +2369,10 @@ namespace System.Runtime.InteropServices
         [System.Security.SecurityCritical]  // auto-generated_required
         public static Guid GenerateGuidForType(Type type)
         {
+#if FEATURE_CORECLR
+            throw new PlatformNotSupportedException();
+        }
+#else
             Guid result = new Guid ();
             FCallGenerateGuidForType (ref result, type);
             return result;
@@ -2358,6 +2381,7 @@ namespace System.Runtime.InteropServices
         // The full assembly name is used to compute the GUID, so this should be SxS-safe
         [MethodImplAttribute(MethodImplOptions.InternalCall)]
         private static extern void FCallGenerateGuidForType(ref Guid result, Type type);
+#endif // FEATURE_CORECLR            
 
         //====================================================================
         // This method generates a PROGID for the specified type. If the type
@@ -2368,6 +2392,9 @@ namespace System.Runtime.InteropServices
         [System.Security.SecurityCritical]  // auto-generated_required
         public static String GenerateProgIdForType(Type type)
         {
+#if FEATURE_CORECLR
+            throw new PlatformNotSupportedException();
+#else
             if (type == null)
                 throw new ArgumentNullException("type");
             if (type.IsImport)
@@ -2402,8 +2429,10 @@ namespace System.Runtime.InteropServices
 
             // If there is no prog ID attribute then use the full name of the type as the prog id.
             return type.FullName;
+#endif // FEATURE_CORECLR            
         }
 
+#if FEATURE_COMINTEROP
         //====================================================================
         // This method binds to the specified moniker.
         //====================================================================
index 408f56c..e9ea076 100644 (file)
@@ -31,6 +31,18 @@ namespace System.Runtime.InteropServices
         {
             throw new PlatformNotSupportedException();
         }
+        
+        [System.Security.SecurityCriticalAttribute]
+        public static Object GetTypedObjectForIUnknown(System.IntPtr pUnk, System.Type t)
+        {
+            throw new PlatformNotSupportedException();
+        }
+
+        [System.Security.SecurityCritical]  // auto-generated_required
+        public static System.IntPtr GetHINSTANCE(System.Reflection.Module m)
+        {
+            return (System.IntPtr) (-1);
+        }           
 
         [System.Security.SecurityCriticalAttribute]
         public static System.IntPtr CreateAggregatedObject<T>(System.IntPtr pOuter, T o)
index 935d717..5c8834e 100644 (file)
@@ -1603,10 +1603,10 @@ FCFuncStart(gInteropMarshalFuncs)
     FCFuncElement("DestroyStructure", MarshalNative::DestroyStructure)
     FCFuncElement("UnsafeAddrOfPinnedArrayElement", MarshalNative::FCUnsafeAddrOfPinnedArrayElement)
     FCFuncElement("GetExceptionCode", ExceptionNative::GetExceptionCode)
+    QCFuncElement("GetHINSTANCE", COMModule::GetHINSTANCE)
 #ifndef FEATURE_CORECLR
     QCFuncElement("InternalNumParamBytes", MarshalNative::NumParamBytes)
     FCFuncElement("GetExceptionPointers", ExceptionNative::GetExceptionPointers)
-    QCFuncElement("GetHINSTANCE", COMModule::GetHINSTANCE)
     FCFuncElement("GetUnmanagedThunkForManagedMethodPtr", MarshalNative::GetUnmanagedThunkForManagedMethodPtr)
     FCFuncElement("GetManagedThunkForUnmanagedMethodPtr", MarshalNative::GetManagedThunkForUnmanagedMethodPtr)
     FCFuncElement("InternalGetThreadFromFiberCookie", MarshalNative::GetThreadFromFiberCookie)
@@ -1651,10 +1651,10 @@ FCFuncStart(gInteropMarshalFuncs)
     FCFuncElement("InternalReleaseComObject", MarshalNative::ReleaseComObject)
     FCFuncElement("Release", MarshalNative::Release)
     FCFuncElement("InitializeWrapperForWinRT", MarshalNative::InitializeWrapperForWinRT)
+    FCFuncElement("GetTypedObjectForIUnknown", MarshalNative::GetTypedObjectForIUnknown)    
 #ifndef FEATURE_CORECLR
     FCFuncElement("GetLoadedTypeForGUID", MarshalNative::GetLoadedTypeForGUID)
     FCFuncElement("GetITypeInfoForType", MarshalNative::GetITypeInfoForType)
-    FCFuncElement("GetTypedObjectForIUnknown", MarshalNative::GetTypedObjectForIUnknown)
     FCFuncElement("CleanupUnusedObjectsInCurrentContext", MarshalNative::CleanupUnusedObjectsInCurrentContext)
     FCFuncElement("IsTypeVisibleFromCom", MarshalNative::IsTypeVisibleFromCom)
     FCFuncElement("FCallGenerateGuidForType", MarshalNative::DoGenerateGuidForType)