|
|
@@ -37,12 +37,10 @@ using System.Security;
|
|
|
using System.Reflection;
|
|
|
using System.Threading;
|
|
|
|
|
|
-#if NET_2_0
|
|
|
using System.Runtime.ConstrainedExecution;
|
|
|
#if !NET_2_1 || MONOTOUCH
|
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
|
#endif
|
|
|
-#endif
|
|
|
|
|
|
#if !NET_2_1 || MONOTOUCH
|
|
|
using Mono.Interop;
|
|
|
@@ -51,13 +49,7 @@ using Mono.Interop;
|
|
|
namespace System.Runtime.InteropServices
|
|
|
{
|
|
|
[SuppressUnmanagedCodeSecurity ()]
|
|
|
- public
|
|
|
-#if NET_2_0
|
|
|
- static
|
|
|
-#else
|
|
|
- sealed
|
|
|
-#endif
|
|
|
- class Marshal
|
|
|
+ public static class Marshal
|
|
|
{
|
|
|
/* fields */
|
|
|
public static readonly int SystemMaxDBCSCharSize = 2; // don't know what this is
|
|
|
@@ -68,10 +60,6 @@ namespace System.Runtime.InteropServices
|
|
|
SystemDefaultCharSize = Environment.OSVersion.Platform == PlatformID.Win32NT ? 2 : 1;
|
|
|
}
|
|
|
|
|
|
-#if !NET_2_0
|
|
|
- private Marshal () {}
|
|
|
-#endif
|
|
|
-
|
|
|
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
|
|
private extern static int AddRefInternal (IntPtr pUnk);
|
|
|
|
|
|
@@ -86,14 +74,10 @@ namespace System.Runtime.InteropServices
|
|
|
public extern static IntPtr AllocCoTaskMem (int cb);
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
|
|
|
-#endif
|
|
|
public extern static IntPtr AllocHGlobal (IntPtr cb);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
|
|
|
-#endif
|
|
|
public static IntPtr AllocHGlobal (int cb)
|
|
|
{
|
|
|
return AllocHGlobal ((IntPtr)cb);
|
|
|
@@ -154,12 +138,10 @@ namespace System.Runtime.InteropServices
|
|
|
copy_to_unmanaged (source, startIndex, destination, length);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
public static void Copy (IntPtr[] source, int startIndex, IntPtr destination, int length)
|
|
|
{
|
|
|
copy_to_unmanaged (source, startIndex, destination, length);
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
public static void Copy (IntPtr source, byte[] destination, int startIndex, int length)
|
|
|
{
|
|
|
@@ -196,7 +178,6 @@ namespace System.Runtime.InteropServices
|
|
|
copy_from_unmanaged (source, startIndex, destination, length);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
public static void Copy (IntPtr source, IntPtr[] destination, int startIndex, int length)
|
|
|
{
|
|
|
copy_from_unmanaged (source, startIndex, destination, length);
|
|
|
@@ -207,7 +188,6 @@ namespace System.Runtime.InteropServices
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
#if !NET_2_1 || MONOTOUCH
|
|
|
public static object CreateWrapperOfType (object o, Type t)
|
|
|
@@ -229,9 +209,7 @@ namespace System.Runtime.InteropServices
|
|
|
#endif
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
-#if NET_2_0
|
|
|
[ComVisible (true)]
|
|
|
-#endif
|
|
|
public extern static void DestroyStructure (IntPtr ptr, Type structuretype);
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
@@ -241,13 +219,9 @@ namespace System.Runtime.InteropServices
|
|
|
public extern static void FreeCoTaskMem (IntPtr ptr);
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public extern static void FreeHGlobal (IntPtr hglobal);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
-
|
|
|
static void ClearBSTR (IntPtr ptr)
|
|
|
{
|
|
|
int len = ReadInt32 (ptr, -4);
|
|
|
@@ -297,7 +271,6 @@ namespace System.Runtime.InteropServices
|
|
|
ClearUnicode (s);
|
|
|
FreeHGlobal (s);
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
#if !NET_2_1 || MONOTOUCH
|
|
|
public static Guid GenerateGuidForType (Type type)
|
|
|
@@ -335,13 +308,11 @@ namespace System.Runtime.InteropServices
|
|
|
return pItf;
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[MonoTODO]
|
|
|
public static IntPtr GetComInterfaceForObjectInContext (object o, Type t)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
[MonoNotSupportedAttribute ("MSDN states user code should never need to call this method.")]
|
|
|
public static object GetComObjectData (object obj, object key)
|
|
|
@@ -355,11 +326,7 @@ namespace System.Runtime.InteropServices
|
|
|
public static int GetComSlotForMethodInfo (MemberInfo m)
|
|
|
{
|
|
|
if (m == null)
|
|
|
-#if NET_2_0
|
|
|
throw new ArgumentNullException ("m");
|
|
|
-#else
|
|
|
- throw new ArgumentNullException (null, "Value cannot be null.");
|
|
|
-#endif
|
|
|
if (!(m is MethodInfo))
|
|
|
throw new ArgumentException ("The MemberInfo must be an interface method.", "m");
|
|
|
if (!m.DeclaringType.IsInterface)
|
|
|
@@ -380,9 +347,7 @@ namespace System.Runtime.InteropServices
|
|
|
}
|
|
|
|
|
|
[MonoTODO]
|
|
|
-#if NET_2_0
|
|
|
[ComVisible (true)]
|
|
|
-#endif
|
|
|
public static IntPtr GetExceptionPointers()
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
@@ -404,9 +369,7 @@ namespace System.Runtime.InteropServices
|
|
|
}
|
|
|
|
|
|
[MonoTODO]
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public static int GetHRForLastWin32Error()
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
@@ -423,13 +386,11 @@ namespace System.Runtime.InteropServices
|
|
|
return pUnk;
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[MonoTODO]
|
|
|
public static IntPtr GetIDispatchForObjectInContext (object o)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
[MonoTODO]
|
|
|
public static IntPtr GetITypeInfoForType (Type t)
|
|
|
@@ -448,18 +409,14 @@ namespace System.Runtime.InteropServices
|
|
|
return pUnk;
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[MonoTODO]
|
|
|
public static IntPtr GetIUnknownForObjectInContext (object o)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
[MonoTODO]
|
|
|
-#if NET_2_0
|
|
|
[Obsolete ("This method has been deprecated")]
|
|
|
-#endif
|
|
|
public static IntPtr GetManagedThunkForUnmanagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
@@ -516,9 +473,7 @@ namespace System.Runtime.InteropServices
|
|
|
}
|
|
|
|
|
|
[MonoTODO]
|
|
|
-#if NET_2_0
|
|
|
[Obsolete ("This method has been deprecated")]
|
|
|
-#endif
|
|
|
public static Thread GetThreadFromFiberCookie (int cookie)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
@@ -543,38 +498,30 @@ namespace System.Runtime.InteropServices
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[Obsolete]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static string GetTypeInfoName (UCOMITypeInfo pTI)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
public static string GetTypeInfoName (ITypeInfo typeInfo)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[Obsolete]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static Guid GetTypeLibGuid (UCOMITypeLib pTLB)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[MonoTODO]
|
|
|
public static Guid GetTypeLibGuid (ITypeLib typelib)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
[MonoTODO]
|
|
|
public static Guid GetTypeLibGuidForAssembly (Assembly asm)
|
|
|
@@ -582,33 +529,26 @@ namespace System.Runtime.InteropServices
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[Obsolete]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static int GetTypeLibLcid (UCOMITypeLib pTLB)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[MonoTODO]
|
|
|
public static int GetTypeLibLcid (ITypeLib typelib)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[Obsolete]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static string GetTypeLibName (UCOMITypeLib pTLB)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[MonoTODO]
|
|
|
public static string GetTypeLibName (ITypeLib typelib)
|
|
|
{
|
|
|
@@ -625,12 +565,9 @@ namespace System.Runtime.InteropServices
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
[MonoTODO]
|
|
|
-#if NET_2_0
|
|
|
[Obsolete ("This method has been deprecated")]
|
|
|
-#endif
|
|
|
public static IntPtr GetUnmanagedThunkForManagedMethodPtr (IntPtr pfnMethodToWrap, IntPtr pbSignature, int cbSignature)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
@@ -653,9 +590,7 @@ namespace System.Runtime.InteropServices
|
|
|
#endif // !NET_2_1
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public static extern int GetLastWin32Error();
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
@@ -695,15 +630,11 @@ namespace System.Runtime.InteropServices
|
|
|
public extern static string PtrToStringBSTR (IntPtr ptr);
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
-#if NET_2_0
|
|
|
[ComVisible (true)]
|
|
|
-#endif
|
|
|
public extern static void PtrToStructure (IntPtr ptr, object structure);
|
|
|
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
-#if NET_2_0
|
|
|
[ComVisible (true)]
|
|
|
-#endif
|
|
|
public extern static object PtrToStructure (IntPtr ptr, Type structureType);
|
|
|
|
|
|
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
|
|
@@ -744,69 +675,51 @@ namespace System.Runtime.InteropServices
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public static int ReadInt32 (IntPtr ptr)
|
|
|
{
|
|
|
return ReadInt32 (ptr, 0);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
public extern static int ReadInt32 (IntPtr ptr, int ofs);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static int ReadInt32 ([In, MarshalAs(UnmanagedType.AsAny)] object ptr, int ofs)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public static long ReadInt64 (IntPtr ptr)
|
|
|
{
|
|
|
return ReadInt64 (ptr, 0);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
public extern static long ReadInt64 (IntPtr ptr, int ofs);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static long ReadInt64 ([In, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs)
|
|
|
{
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public static IntPtr ReadIntPtr (IntPtr ptr)
|
|
|
{
|
|
|
return ReadIntPtr (ptr, 0);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
public extern static IntPtr ReadIntPtr (IntPtr ptr, int ofs);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static IntPtr ReadIntPtr ([In, MarshalAs (UnmanagedType.AsAny)] object ptr, int ofs)
|
|
|
{
|
|
|
@@ -819,15 +732,11 @@ namespace System.Runtime.InteropServices
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
public extern static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
|
|
private extern static int ReleaseInternal (IntPtr pUnk);
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
|
|
|
-#endif
|
|
|
public static int Release (IntPtr pUnk)
|
|
|
{
|
|
|
if (pUnk == IntPtr.Zero)
|
|
|
@@ -848,9 +757,7 @@ namespace System.Runtime.InteropServices
|
|
|
return ReleaseComObjectInternal (o);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[Obsolete]
|
|
|
-#endif
|
|
|
[MonoTODO]
|
|
|
public static void ReleaseThreadCache()
|
|
|
{
|
|
|
@@ -864,9 +771,7 @@ namespace System.Runtime.InteropServices
|
|
|
}
|
|
|
#endif // !NET_2_1
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ComVisible (true)]
|
|
|
-#endif
|
|
|
public static int SizeOf (object structure)
|
|
|
{
|
|
|
return SizeOf (structure.GetType ());
|
|
|
@@ -928,7 +833,7 @@ namespace System.Runtime.InteropServices
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
public extern static IntPtr StringToHGlobalUni (string s);
|
|
|
|
|
|
-#if NET_2_0 && (!NET_2_1 || MONOTOUCH)
|
|
|
+#if !NET_2_1 || MONOTOUCH
|
|
|
public static IntPtr SecureStringToBSTR (SecureString s)
|
|
|
{
|
|
|
if (s == null)
|
|
|
@@ -1018,10 +923,8 @@ namespace System.Runtime.InteropServices
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-#if NET_2_0
|
|
|
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
|
|
|
[ComVisible (true)]
|
|
|
-#endif
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
public extern static void StructureToPtr (object structure, IntPtr ptr, bool fDeleteOld);
|
|
|
|
|
|
@@ -1125,21 +1028,11 @@ namespace System.Runtime.InteropServices
|
|
|
throw new NotImplementedException ();
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
- public
|
|
|
-#else
|
|
|
- internal
|
|
|
-#endif
|
|
|
- static Exception GetExceptionForHR (int errorCode) {
|
|
|
+ public static Exception GetExceptionForHR (int errorCode) {
|
|
|
return GetExceptionForHR (errorCode, IntPtr.Zero);
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0
|
|
|
- public
|
|
|
-#else
|
|
|
- internal
|
|
|
-#endif
|
|
|
- static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo) {
|
|
|
+ public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo) {
|
|
|
|
|
|
const int E_OUTOFMEMORY = unchecked ((int)0x8007000EL);
|
|
|
const int E_INVALIDARG = unchecked ((int)0X80070057);
|
|
|
@@ -1156,14 +1049,14 @@ namespace System.Runtime.InteropServices
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-#if NET_2_0 && (!NET_2_1 || MONOTOUCH)
|
|
|
+#if !NET_2_1 || MONOTOUCH
|
|
|
public static int FinalReleaseComObject (object o)
|
|
|
{
|
|
|
while (ReleaseComObject (o) != 0);
|
|
|
return 0;
|
|
|
}
|
|
|
#endif
|
|
|
-#if NET_2_0
|
|
|
+
|
|
|
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
|
|
private static extern Delegate GetDelegateForFunctionPointerInternal (IntPtr ptr, Type t);
|
|
|
|
|
|
@@ -1189,6 +1082,5 @@ namespace System.Runtime.InteropServices
|
|
|
|
|
|
return GetFunctionPointerForDelegateInternal (d);
|
|
|
}
|
|
|
-#endif
|
|
|
}
|
|
|
}
|