Compartir a través de


Clase Marshal

 

Publicado: octubre de 2016

Proporciona una colección de métodos para asignar memoria no administrada, copiar bloques de memoria no administrados y convertir los tipos administrados en no administrados, así como otros métodos diversos que se utilizan al interactuar con código no administrado.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Jerarquía de herencia

System.Object
  System.Runtime.InteropServices.Marshal

Sintaxis

public static class Marshal
public ref class Marshal abstract sealed 
[<AbstractClass>]
[<Sealed>]
type Marshal = class end
Public NotInheritable Class Marshal

Métodos

Nombre Descripción
System_CAPS_pubmethodSystem_CAPS_static AddRef(IntPtr)

Incrementa el contador de referencia en la interfaz especificada.

System_CAPS_pubmethodSystem_CAPS_static AllocCoTaskMem(Int32)

Asigna un bloque de memoria de un tamaño especificado del asignador de memoria de tareas COM.

System_CAPS_pubmethodSystem_CAPS_static AllocHGlobal(Int32)

Asigna memoria de la memoria no administrada del proceso utilizando el número especificado de bytes.

System_CAPS_pubmethodSystem_CAPS_static AllocHGlobal(IntPtr)

Asigna memoria de la memoria no administrada del proceso utilizando el puntero al número especificado de bytes.

System_CAPS_pubmethodSystem_CAPS_static AreComObjectsAvailableForCleanup()

Indica si hay contenedores RCW de cualquier contexto disponibles para la limpieza.

System_CAPS_pubmethodSystem_CAPS_static BindToMoniker(String)

Obtiene un puntero de interfaz identificado por el moniker especificado.

System_CAPS_pubmethodSystem_CAPS_static ChangeWrapperHandleStrength(Object, Boolean)

Cambia la intensidad del controlador del contenedor CCW COM Callable Wrapper de un objeto.

System_CAPS_pubmethodSystem_CAPS_static CleanupUnusedObjectsInCurrentContext()

Notifica al tiempo de ejecución que debe limpiar todos los contenedores RCW (Runtime Callable Wrappers) asignados en el contexto actual.

System_CAPS_pubmethodSystem_CAPS_static Copy(Byte[], Int32, IntPtr, Int32)

Copia datos de una matriz unidimensional y administrada de enteros de 8 bits sin signo a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(Char[], Int32, IntPtr, Int32)

Copia datos de una matriz de caracteres unidimensional y administrada a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(Double[], Int32, IntPtr, Int32)

Copia datos de una matriz unidimensional y administrada de números de punto flotante de precisión doble a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(Int16[], Int32, IntPtr, Int32)

Copia datos de una matriz unidimensional administrada de enteros de 16 bits con signo a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(Int32[], Int32, IntPtr, Int32)

Copia datos de una matriz unidimensional administrada de enteros de 32 bits con signo a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(Int64[], Int32, IntPtr, Int32)

Copia datos de una matriz unidimensional administrada de enteros de 64 bits con signo a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Byte[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz administrada de enteros de 8 bits sin signo.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Char[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz de caracteres administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Double[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz administrada de números de punto flotante de precisión doble.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Int16[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz administrada de enteros de 16 bits con signo.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Int32[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz administrada de enteros de 32 bits con signo.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Int64[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz administrada de enteros de 64 bits con signo.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, IntPtr[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz IntPtr administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr, Single[], Int32, Int32)

Copia datos de un puntero de memoria no administrada a una matriz administrada de números de punto flotante de precisión sencilla.

System_CAPS_pubmethodSystem_CAPS_static Copy(IntPtr[], Int32, IntPtr, Int32)

Copia datos de una matriz IntPtr unidimensional y administrada a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static Copy(Single[], Int32, IntPtr, Int32)

Copia datos de una matriz unidimensional y administrada de números de punto flotante de precisión sencilla a un puntero de memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static CreateAggregatedObject(IntPtr, Object)

Agrega un objeto administrado al objeto COM especificado.

System_CAPS_pubmethodSystem_CAPS_static CreateAggregatedObject<T>(IntPtr, T)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Agrega un objeto administrado del tipo especificado con el objeto COM especificado.

System_CAPS_pubmethodSystem_CAPS_static CreateWrapperOfType(Object, Type)

Ajusta el objeto COM especificado en un objeto del tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static CreateWrapperOfType<T, TWrapper>(T)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Ajusta el objeto COM especificado en un objeto del tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static DestroyStructure(IntPtr, Type)

Libera todas las subestructuras a las que apunta el bloque de memoria no administrada especificado.

System_CAPS_pubmethodSystem_CAPS_static DestroyStructure<T>(IntPtr)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Libera todas las subestructuras de un tipo especificado a las que apunta el bloque de memoria no administrada especificado.

System_CAPS_pubmethodSystem_CAPS_static FinalReleaseComObject(Object)

Libera todas las referencias a un contenedor RCW Runtime Callable Wrapper estableciendo su recuento de referencias en 0.

System_CAPS_pubmethodSystem_CAPS_static FreeBSTR(IntPtr)

Libera un BSTR utilizando COM SysFreeString (función).

System_CAPS_pubmethodSystem_CAPS_static FreeCoTaskMem(IntPtr)

Libera un bloque de memoria asignado por el asignador de memoria de tareas COM no administrada.

System_CAPS_pubmethodSystem_CAPS_static FreeHGlobal(IntPtr)

Libera memoria previamente asignada de la memoria no administrada del proceso.

System_CAPS_pubmethodSystem_CAPS_static GenerateGuidForType(Type)

Devuelve el identificador único global (GUID) del tipo especificado o genera un GUID mediante el algoritmo que utiliza la herramienta Exportador de la biblioteca de tipos (Tlbexp.exe).

System_CAPS_pubmethodSystem_CAPS_static GenerateProgIdForType(Type)

Devuelve un identificador de programación (ProgID) para el tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static GetActiveObject(String)

Obtiene una instancia en ejecución del objeto especificado de la tabla de objetos de ejecución (ROT).

System_CAPS_pubmethodSystem_CAPS_static GetComInterfaceForObject(Object, Type)

Devuelve un puntero a un IUnknown interfaz que representa la interfaz especificada en el objeto especificado. El acceso a la interfaz de consulta personalizada está habilitado de forma predeterminada.

System_CAPS_pubmethodSystem_CAPS_static GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)

Devuelve un puntero a un IUnknown interfaz que representa la interfaz especificada en el objeto especificado. El modo de personalización especificado controla el acceso a la interfaz de consulta personalizada.

System_CAPS_pubmethodSystem_CAPS_static GetComInterfaceForObject<T, TInterface>(T)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Devuelve un puntero a un IUnknown interfaz que representa la interfaz especificada en un objeto del tipo especificado. El acceso a la interfaz de consulta personalizada está habilitado de forma predeterminada.

System_CAPS_pubmethodSystem_CAPS_static GetComInterfaceForObjectInContext(Object, Type)

Devuelve un puntero de interfaz que representa la interfaz especificada para un objeto, si el llamador está en el mismo contexto que ese objeto.

System_CAPS_pubmethodSystem_CAPS_static GetComObjectData(Object, Object)

Recupera datos a los que hace referencia la clave especificada desde el objeto COM especificado.

System_CAPS_pubmethodSystem_CAPS_static GetComSlotForMethodInfo(MemberInfo)

Recupera la ranura de tabla de funciones virtuales (v-table o VTBL) para un tipo System.Reflection.MemberInfo especificado cuando ese tipo se expone a COM.

System_CAPS_pubmethodSystem_CAPS_static GetDelegateForFunctionPointer(IntPtr, Type)

Convierte un puntero a función no administrada en un delegado.

System_CAPS_pubmethodSystem_CAPS_static GetDelegateForFunctionPointer<TDelegate>(IntPtr)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Convierte un puntero a función no administrada en un delegado de un tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static GetEndComSlot(Type)

Recupera la última ranura de la tabla de funciones virtuales (v-table o VTBL) de un tipo cuando se expone a COM.

System_CAPS_pubmethodSystem_CAPS_static GetExceptionCode()

Devuelve el código que identifica el tipo de excepción que ocurrió.

System_CAPS_pubmethodSystem_CAPS_static GetExceptionForHR(Int32)

Convierte el código de error HRESULT especificado en un objeto Exception correspondiente.

System_CAPS_pubmethodSystem_CAPS_static GetExceptionForHR(Int32, IntPtr)

Convierte el código de error HRESULT especificado en un objeto Exception correspondiente, con información de error adicional pasada en una interfaz IErrorInfo para el objeto de excepción.

System_CAPS_pubmethodSystem_CAPS_static GetExceptionPointers()

Recupera una descripción de la excepción independiente del equipo así como información sobre el estado del subproceso cuando ocurrió la excepción.

System_CAPS_pubmethodSystem_CAPS_static GetFunctionPointerForDelegate(Delegate)

Convierte un delegado en un puntero a función invocable desde código no administrado.

System_CAPS_pubmethodSystem_CAPS_static GetFunctionPointerForDelegate<TDelegate>(TDelegate)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Convierte un delegado de un tipo especificado en un puntero a función invocable desde código no administrado.

System_CAPS_pubmethodSystem_CAPS_static GetHINSTANCE(Module)

Devuelve el identificador de instancia (HINSTANCE) para el módulo especificado.

System_CAPS_pubmethodSystem_CAPS_static GetHRForException(Exception)

Convierte la excepción especificada en HRESULT.

System_CAPS_pubmethodSystem_CAPS_static GetHRForLastWin32Error()

Devuelve el HRESULT correspondiente al último error producido en código Win32 ejecutado mediante Marshal.

System_CAPS_pubmethodSystem_CAPS_static GetIDispatchForObject(Object)

Devuelve una interfaz IDispatch de un objeto administrado.

System_CAPS_pubmethodSystem_CAPS_static GetIDispatchForObjectInContext(Object)

Devuelve un puntero de interfaz IDispatch desde un objeto administrado si el llamador está en el mismo contexto que ese objeto.

System_CAPS_pubmethodSystem_CAPS_static GetITypeInfoForType(Type)

Devuelve una interfaz System.Runtime.InteropServices.ComTypes.ITypeInfo de un tipo administrado.

System_CAPS_pubmethodSystem_CAPS_static GetIUnknownForObject(Object)

Devuelve un IUnknown interfaz desde un objeto administrado.

System_CAPS_pubmethodSystem_CAPS_static GetIUnknownForObjectInContext(Object)

Devuelve un IUnknown de interfaz de un objeto administrado, si el llamador está en el mismo contexto que ese objeto.

System_CAPS_pubmethodSystem_CAPS_static GetLastWin32Error()

Devuelve el código de error devuelto por la última función no administrada a la que se llamó mediante la invocación de plataforma que tiene la marca DllImportAttribute.SetLastError activada.

System_CAPS_pubmethodSystem_CAPS_static GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32)

Obsoleto. Obtiene un puntero a una función generada en tiempo de ejecución que calcula las referencias a una llamada de código administrado a código no administrado.

System_CAPS_pubmethodSystem_CAPS_static GetMethodInfoForComSlot(Type, Int32, ComMemberType)

Recupera un objeto MemberInfo para la ranura de la tabla de funciones virtuales (v-table o VTBL) especificada.

System_CAPS_pubmethodSystem_CAPS_static GetNativeVariantForObject(Object, IntPtr)

Convierte un objeto en un COM VARIANT.

System_CAPS_pubmethodSystem_CAPS_static GetNativeVariantForObject<T>(T, IntPtr)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Convierte un objeto de un tipo especificado en un objeto COM VARIANT.

System_CAPS_pubmethodSystem_CAPS_static GetObjectForIUnknown(IntPtr)

Devuelve una instancia de un tipo que representa un objeto COM por un puntero a su IUnknown interfaz.

System_CAPS_pubmethodSystem_CAPS_static GetObjectForNativeVariant(IntPtr)

Convierte un COM VARIANT en un objeto.

System_CAPS_pubmethodSystem_CAPS_static GetObjectForNativeVariant<T>(IntPtr)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Convierte un objeto COM VARIANT en un objeto de un tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static GetObjectsForNativeVariants(IntPtr, Int32)

Convierte una matriz de COM VARIANTs a una matriz de objetos.

System_CAPS_pubmethodSystem_CAPS_static GetObjectsForNativeVariants<T>(IntPtr, Int32)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Convierte una matriz de elementos COM VARIANT en una matriz de un tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static GetStartComSlot(Type)

Obtiene la primera ranura de la tabla de funciones virtuales (v-table o VTBL) que contiene métodos definidos por el usuario.

System_CAPS_pubmethodSystem_CAPS_static GetThreadFromFiberCookie(Int32)

Obsoleto. Convierte una cookie de fibra en la correspondiente instancia System.Threading.Thread.

System_CAPS_pubmethodSystem_CAPS_static GetTypedObjectForIUnknown(IntPtr, Type)

Devuelve un objeto administrado de un tipo especificado que representa un objeto COM.

System_CAPS_pubmethodSystem_CAPS_static GetTypeForITypeInfo(IntPtr)

Convierte un objeto ITypeInfo no administrado en un objeto System.Type administrado.

System_CAPS_pubmethodSystem_CAPS_static GetTypeFromCLSID(Guid)

Devuelve el tipo asociado al identificador de clase especificado (CLSID).

System_CAPS_pubmethodSystem_CAPS_static GetTypeInfoName(ITypeInfo)

Recupera el nombre del tipo representado por un objeto ITypeInfo.

System_CAPS_pubmethodSystem_CAPS_static GetTypeInfoName(UCOMITypeInfo)

Obsoleto. Recupera el nombre del tipo representado por un objeto ITypeInfo.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibGuid(ITypeLib)

Recupera el identificador de biblioteca (LIBID) de una biblioteca de tipos.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibGuid(UCOMITypeLib)

Obsoleto. Recupera el identificador de biblioteca (LIBID) de una biblioteca de tipos.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibGuidForAssembly(Assembly)

Recupera el identificador de biblioteca (LIBID) asignado a una biblioteca de tipos cuando se exportó del ensamblado especificado.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibLcid(ITypeLib)

Recupera el LCID de una biblioteca de tipos.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibLcid(UCOMITypeLib)

Obsoleto. Recupera el LCID de una biblioteca de tipos.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibName(ITypeLib)

Recupera el nombre de una biblioteca de tipos.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibName(UCOMITypeLib)

Obsoleto. Recupera el nombre de una biblioteca de tipos.

System_CAPS_pubmethodSystem_CAPS_static GetTypeLibVersionForAssembly(Assembly, Int32, Int32)

Recupera el número de versión de la biblioteca de tipos que se exportará del ensamblado especificado.

System_CAPS_pubmethodSystem_CAPS_static GetUniqueObjectForIUnknown(IntPtr)

Crea un único Runtime Callable Wrapper objeto (RCW) para un determinado IUnknown interfaz.

System_CAPS_pubmethodSystem_CAPS_static GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32)

Obsoleto. Obtiene un puntero a una función generada en tiempo de ejecución que calcula las referencias a una llamada de código no administrado a código administrado.

System_CAPS_pubmethodSystem_CAPS_static IsComObject(Object)

Indica si un objeto especificado representa un objeto COM.

System_CAPS_pubmethodSystem_CAPS_static IsTypeVisibleFromCom(Type)

Indica si un tipo es visible a clientes COM.

System_CAPS_pubmethodSystem_CAPS_static NumParamBytes(MethodInfo)

Calcula el número de bytes de la memoria no administrada que se necesitan para contener los parámetros del método especificado.

System_CAPS_pubmethodSystem_CAPS_static OffsetOf(Type, String)

Devuelve el desplazamiento de campo del formato no administrado de la clase administrada.

System_CAPS_pubmethodSystem_CAPS_static OffsetOf<T>(String)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Devuelve el desplazamiento de campo del formato no administrado de una clase administrada específica.

System_CAPS_pubmethodSystem_CAPS_static Prelink(MethodInfo)

Ejecuta tareas únicas de configuración de método sin llamar al método.

System_CAPS_pubmethodSystem_CAPS_static PrelinkAll(Type)

Realiza una comprobación anterior al vínculo de todos los métodos de una clase.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringAnsi(IntPtr)

Copia todos los caracteres hasta el primer carácter nulo de una cadena ANSI no administrada a un String, administrado y ensancha cada carácter ANSI a Unicode.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringAnsi(IntPtr, Int32)

Asigna un String, administrado, copia en él un número especificado de caracteres de una cadena ANSI no administrada y ensancha cada carácter ANSI a Unicode.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringAuto(IntPtr)

Asigna un String administrado y copia en él todos los caracteres hasta el primer carácter nulo de una cadena almacenada en memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringAuto(IntPtr, Int32)

Asigna un String administrado y copia en él el número de caracteres especificado de una cadena almacenada en memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringBSTR(IntPtr)

Asigna un administrado String y copia un binary string (BSTR) almacenada en memoria no administrada en él.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringUni(IntPtr)

Asigna un String administrado y copia en él todos los caracteres hasta el primer carácter nulo de una cadena Unicode no administrada.

System_CAPS_pubmethodSystem_CAPS_static PtrToStringUni(IntPtr, Int32)

Asigna un String administrado y copia en él un número de caracteres especificado de una cadena Unicode no administrada.

System_CAPS_pubmethodSystem_CAPS_static PtrToStructure(IntPtr, Object)

Calcula las referencias a los datos desde un bloque de memoria no administrada a un objeto administrado.

System_CAPS_pubmethodSystem_CAPS_static PtrToStructure(IntPtr, Type)

Calcula las referencias a los datos desde un bloque de memoria no administrado a un objeto administrado y recién asignado del tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static PtrToStructure<T>(IntPtr)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Calcula las referencias a los datos desde un bloque de memoria no administrado a un objeto administrado y recién asignado del tipo especificado por un parámetro de tipo genérico.

System_CAPS_pubmethodSystem_CAPS_static PtrToStructure<T>(IntPtr, T)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Calcula las referencias desde un bloque de memoria no administrado a un objeto administrado de un tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static QueryInterface(IntPtr, Guid, IntPtr)

Solicita un puntero a una interfaz especificada de un objeto COM.

System_CAPS_pubmethodSystem_CAPS_static ReadByte(IntPtr)

Lee un único byte desde la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadByte(IntPtr, Int32)

Lee un único byte en un desplazamiento (o índice) dado desde la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadByte(Object, Int32)

Lee un único byte en un desplazamiento (o índice) dado desde la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt16(IntPtr)

Lee un entero de 16 bits con signo de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt16(IntPtr, Int32)

Lee un entero de 16 bits con signo en un desplazamiento dado de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt16(Object, Int32)

Lee un entero de 16 bits con signo en un desplazamiento dado de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt32(IntPtr)

Lee un entero de 32 bits con signo de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt32(IntPtr, Int32)

Lee un entero de 32 bits con signo en un desplazamiento dado de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt32(Object, Int32)

Lee un entero de 32 bits con signo en un desplazamiento dado de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt64(IntPtr)

Lee un entero de 64 bits con signo de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt64(IntPtr, Int32)

Lee un entero de 64 bits con signo en un desplazamiento dado de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadInt64(Object, Int32)

Lee un entero de 64 bits con signo en un desplazamiento dado de la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static ReadIntPtr(IntPtr)

Lee de la memoria no administrada un entero cuyo tamaño es propio del procesador nativo.

System_CAPS_pubmethodSystem_CAPS_static ReadIntPtr(IntPtr, Int32)

Lee de la memoria no administrada un valor de tipo entero cuyo tamaño en bytes es propio del procesador nativo en un desplazamiento dado.

System_CAPS_pubmethodSystem_CAPS_static ReadIntPtr(Object, Int32)

Lee de la memoria no administrada un valor de tipo entero cuyo tamaño en bytes es propio del procesador nativo.

System_CAPS_pubmethodSystem_CAPS_static ReAllocCoTaskMem(IntPtr, Int32)

Cambia el tamaño de un bloque de memoria asignado previamente con AllocCoTaskMem.

System_CAPS_pubmethodSystem_CAPS_static ReAllocHGlobal(IntPtr, IntPtr)

Cambia el tamaño de un bloque de memoria asignado previamente con AllocHGlobal.

System_CAPS_pubmethodSystem_CAPS_static Release(IntPtr)

Disminuye el contador de referencia de la interfaz especificada.

System_CAPS_pubmethodSystem_CAPS_static ReleaseComObject(Object)

Disminuye el recuento de referencias del contenedor Runtime Callable Wrapper (RCW) asociado al objeto COM indicado.

System_CAPS_pubmethodSystem_CAPS_static ReleaseThreadCache()

Obsoleto. Libera la memoria caché del subproceso.

System_CAPS_pubmethodSystem_CAPS_static SecureStringToBSTR(SecureString)

Asigna no administrado binary string (BSTR) y copia el contenido de una clase administrada SecureString objeto en él.

System_CAPS_pubmethodSystem_CAPS_static SecureStringToCoTaskMemAnsi(SecureString)

Copia el contenido de un objeto SecureString administrado en un bloque de memoria asignado desde el asignador de tareas COM no administrado.

System_CAPS_pubmethodSystem_CAPS_static SecureStringToCoTaskMemUnicode(SecureString)

Copia el contenido de un objeto SecureString administrado en un bloque de memoria asignado desde el asignador de tareas COM no administrado.

System_CAPS_pubmethodSystem_CAPS_static SecureStringToGlobalAllocAnsi(SecureString)

Copia el contenido de un SecureString administrado en la memoria no administrada, convirtiéndolo en formato ANSI mientras realiza la copia.

System_CAPS_pubmethodSystem_CAPS_static SecureStringToGlobalAllocUnicode(SecureString)

Copia el contenido de un objeto SecureString administrado en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static SetComObjectData(Object, Object, Object)

Establece los datos a los que hace referencia la clave especificada desde el objeto COM especificado.

System_CAPS_pubmethodSystem_CAPS_static SizeOf(Object)

Devuelve el tamaño no administrado de un objeto en bytes.

System_CAPS_pubmethodSystem_CAPS_static SizeOf(Type)

Devuelve el tamaño, expresado en bytes, de un tipo no administrado.

System_CAPS_pubmethodSystem_CAPS_static SizeOf<T>()

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Devuelve el tamaño, expresado en bytes, de un tipo no administrado.

System_CAPS_pubmethodSystem_CAPS_static SizeOf<T>(T)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Devuelve el tamaño no administrado de un objeto de un tipo especificado en bytes.

System_CAPS_pubmethodSystem_CAPS_static StringToBSTR(String)

Asigna un BSTR y copia el contenido de una clase administrada String en él.

System_CAPS_pubmethodSystem_CAPS_static StringToCoTaskMemAnsi(String)

Copia el contenido de un String administrado en un bloque de memoria asignado desde el asignador de tareas COM no administrado.

System_CAPS_pubmethodSystem_CAPS_static StringToCoTaskMemAuto(String)

Copia el contenido de un String administrado en un bloque de memoria asignado desde el asignador de tareas COM no administrado.

System_CAPS_pubmethodSystem_CAPS_static StringToCoTaskMemUni(String)

Copia el contenido de un String administrado en un bloque de memoria asignado desde el asignador de tareas COM no administrado.

System_CAPS_pubmethodSystem_CAPS_static StringToHGlobalAnsi(String)

Copia el contenido de un String administrado en la memoria no administrada, convirtiéndolo en formato ANSI mientras realiza la copia.

System_CAPS_pubmethodSystem_CAPS_static StringToHGlobalAuto(String)

Copia el contenido de un String administrado en la memoria no administrada, convirtiéndolo en formato ANSI si es necesario.

System_CAPS_pubmethodSystem_CAPS_static StringToHGlobalUni(String)

Copia el contenido de un String administrado en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static StructureToPtr(Object, IntPtr, Boolean)

Calcula las referencias a los datos desde un objeto administrado a un bloque de memoria no administrado.

System_CAPS_pubmethodSystem_CAPS_static StructureToPtr<T>(T, IntPtr, Boolean)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Calcula las referencias de un objeto administrado de un tipo especificado a un bloque de memoria no administrado.

System_CAPS_pubmethodSystem_CAPS_static ThrowExceptionForHR(Int32)

Se produce una excepción con un valor HRESULT de error específico.

System_CAPS_pubmethodSystem_CAPS_static ThrowExceptionForHR(Int32, IntPtr)

Inicia una excepción con un HRESULT de error específico en función del IErrorInfo interfaz.

System_CAPS_pubmethodSystem_CAPS_static UnsafeAddrOfPinnedArrayElement(Array, Int32)

Obtiene la dirección del elemento en el índice especificado dentro de la matriz especificada.

System_CAPS_pubmethodSystem_CAPS_static UnsafeAddrOfPinnedArrayElement<T>(T[], Int32)

[Compatible con .NET Framework 4.5.1 y versiones posteriores]

Obtiene la dirección del elemento en el índice especificado en una matriz de tipo especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteByte(IntPtr, Byte)

Escribe un único byte en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static WriteByte(IntPtr, Int32, Byte)

Escribe un valor de un solo byte en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteByte(Object, Int32, Byte)

Escribe un valor de un solo byte en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt16(IntPtr, Char)

Escribe un carácter como un valor entero de 16 bits en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static WriteInt16(IntPtr, Int16)

Escribe un valor entero de 16 bits en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static WriteInt16(IntPtr, Int32, Char)

Escribe un valor entero de 16 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt16(IntPtr, Int32, Int16)

Escribe un valor entero de 16 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt16(Object, Int32, Char)

Escribe un valor entero de 16 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt16(Object, Int32, Int16)

Escribe un valor entero de 16 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt32(IntPtr, Int32)

Escribe un valor entero de 32 bits con signo en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static WriteInt32(IntPtr, Int32, Int32)

Escribe un valor entero de 32 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt32(Object, Int32, Int32)

Escribe un valor entero de 32 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt64(IntPtr, Int32, Int64)

Escribe un valor entero de 64 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteInt64(IntPtr, Int64)

Escribe un valor entero de 64 bits con signo en la memoria no administrada.

System_CAPS_pubmethodSystem_CAPS_static WriteInt64(Object, Int32, Int64)

Escribe un valor entero de 64 bits con signo en la memoria no administrada en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteIntPtr(IntPtr, Int32, IntPtr)

Escribe en la memoria no administrada un valor de tipo entero cuyo tamaño en bytes es propio del procesador nativo en un desplazamiento especificado.

System_CAPS_pubmethodSystem_CAPS_static WriteIntPtr(IntPtr, IntPtr)

Escribe en la memoria no administrada un valor de tipo entero cuyo tamaño en bytes es propio del procesador nativo.

System_CAPS_pubmethodSystem_CAPS_static WriteIntPtr(Object, Int32, IntPtr)

Escribe en la memoria no administrada un valor de tipo entero cuyo tamaño en bytes es propio del procesador nativo.

System_CAPS_pubmethodSystem_CAPS_static ZeroFreeBSTR(IntPtr)

Libera un BSTR puntero que se ha asignado con el SecureStringToBSTR método.

System_CAPS_pubmethodSystem_CAPS_static ZeroFreeCoTaskMemAnsi(IntPtr)

Libera un puntero a una cadena no administrada que se ha asignado con el método SecureStringToCoTaskMemAnsi.

System_CAPS_pubmethodSystem_CAPS_static ZeroFreeCoTaskMemUnicode(IntPtr)

Libera un puntero a una cadena no administrada que se ha asignado con el método SecureStringToCoTaskMemUnicode.

System_CAPS_pubmethodSystem_CAPS_static ZeroFreeGlobalAllocAnsi(IntPtr)

Libera un puntero a una cadena no administrada que se ha asignado con el método SecureStringToGlobalAllocAnsi.

System_CAPS_pubmethodSystem_CAPS_static ZeroFreeGlobalAllocUnicode(IntPtr)

Libera un puntero a una cadena no administrada que se ha asignado con el método SecureStringToGlobalAllocUnicode.

Campos

Nombre Descripción
System_CAPS_pubfieldSystem_CAPS_static SystemDefaultCharSize

Representa el tamaño de carácter predeterminado del sistema; el valor predeterminado es 2 para los sistemas Unicode y 1 para los sistemas ANSI. Este campo es de solo lectura.

System_CAPS_pubfieldSystem_CAPS_static SystemMaxDBCSCharSize

Representa el tamaño máximo de un juego de caracteres de doble byte (DBCS), expresado en bytes, para el actual sistema operativo. Este campo es de solo lectura.

Comentarios

El static métodos definidos en la Marshal clase son fundamentales para trabajar con código no administrado. Mayoría de los métodos definida en esta clase se utiliza normalmente los desarrolladores que desean proporcionar un puente entre los administrados y modelos de programación. Por ejemplo, el StringToHGlobalAnsi método copia los caracteres ANSI de una cadena determinada (del montón administrado) en un búfer del montón no administrado. También asigna el montón de destino del tamaño correcto.

Common language runtime proporciona capacidades de cálculo de referencias específicas. Para obtener más información sobre el cálculo de referencias, consulte Interop Marshaling.

El Read y Write métodos en la Marshal clase admiten el acceso alineado y desalineado.

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar distintos métodos definidos por el Marshal clase.

using System;
using System.Text;
using System.Runtime.InteropServices;

public struct Point
{
    public Int32 x, y;
}


public sealed class App
{
    static void Main()
    {
        // Demonstrate the use of public static fields of the Marshal class.
        Console.WriteLine("SystemDefaultCharSize={0}, SystemMaxDBCSCharSize={1}",
            Marshal.SystemDefaultCharSize, Marshal.SystemMaxDBCSCharSize);

        // Demonstrate the use of the SizeOf method of the Marshal class.
        Console.WriteLine("Number of bytes needed by a Point object: {0}", 
            Marshal.SizeOf(typeof(Point)));
        Point p = new Point();
        Console.WriteLine("Number of bytes needed by a Point object: {0}",
            Marshal.SizeOf(p));

        // Demonstrate how to call GlobalAlloc and 
        // GlobalFree using the Marshal class.
        IntPtr hglobal = Marshal.AllocHGlobal(100);
        Marshal.FreeHGlobal(hglobal);

        // Demonstrate how to use the Marshal class to get the Win32 error 
        // code when a Win32 method fails.
        Boolean f = CloseHandle(new IntPtr(-1));
        if (!f)
        {
            Console.WriteLine("CloseHandle call failed with an error code of: {0}", 
                Marshal.GetLastWin32Error());
        }  
    }

    // This is a platform invoke prototype. SetLastError is true, which allows 
    // the GetLastWin32Error method of the Marshal class to work correctly.    
    [DllImport("Kernel32", ExactSpelling = true, SetLastError = true)]
    static extern Boolean CloseHandle(IntPtr h);

}

// This code produces the following output.
// 
// SystemDefaultCharSize=2, SystemMaxDBCSCharSize=1
// Number of bytes needed by a Point object: 8
// Number of bytes needed by a Point object: 8
// CloseHandle call failed with an error code of: 6
Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Security.Permissions



Public Structure Point
    Public x, y As Int32
End Structure



Public NotInheritable Class App

    <SecurityPermission(SecurityAction.LinkDemand, Unrestricted:=True)> _
    Shared Sub Main()
        ' Demonstrate the use of public static fields of the Marshal class.
        Console.WriteLine("SystemDefaultCharSize={0}, SystemMaxDBCSCharSize={1}", Marshal.SystemDefaultCharSize, Marshal.SystemMaxDBCSCharSize)
        ' Demonstrate the use of the SizeOf method of the Marshal class.
        Console.WriteLine("Number of bytes needed by a Point object: {0}", Marshal.SizeOf(GetType(Point)))
        Dim p As New Point()
        Console.WriteLine("Number of bytes needed by a Point object: {0}", Marshal.SizeOf(p))
        ' Demonstrate how to call GlobalAlloc and 
        ' GlobalFree using the Marshal class.
        Dim hglobal As IntPtr = Marshal.AllocHGlobal(100)
        Marshal.FreeHGlobal(hglobal)
        ' Demonstrate how to use the Marshal class to get the Win32 error 
        ' code when a Win32 method fails.
        Dim f As [Boolean] = CloseHandle(New IntPtr(-1))
        If Not f Then
            Console.WriteLine("CloseHandle call failed with an error code of: {0}", Marshal.GetLastWin32Error())
        End If

    End Sub


    ' This is a platform invoke prototype. SetLastError is true, which allows 
    ' the GetLastWin32Error method of the Marshal class to work correctly.    
    <DllImport("Kernel32", ExactSpelling:=True, SetLastError:=True)> _
    Shared Function CloseHandle(ByVal h As IntPtr) As [Boolean]

    End Function
End Class


' This code produces the following output.
' 
' SystemDefaultCharSize=2, SystemMaxDBCSCharSize=1
' Number of bytes needed by a Point object: 8
' Number of bytes needed by a Point object: 8
' CloseHandle call failed with an error code of: 6
using namespace System;
using namespace System::Runtime::InteropServices;

public value struct Point
{
public:
    property int X;
    property int Y;
};
extern bool CloseHandle(IntPtr h);

int main()
{
    // Demonstrate the use of public static fields of the Marshal
    // class.
    Console::WriteLine(
        "SystemDefaultCharSize={0},SystemMaxDBCSCharSize={1}",
        Marshal::SystemDefaultCharSize,
        Marshal::SystemMaxDBCSCharSize);

    // Demonstrate the use of the SizeOf method of the Marshal
    // class.
    Console::WriteLine("Number of bytes needed by a Point object: {0}",
        Marshal::SizeOf(Point::typeid));
    Point point;
    Console::WriteLine("Number of bytes needed by a Point object: {0}",
        Marshal::SizeOf(point));

    // Demonstrate how to call GlobalAlloc and 
    // GlobalFree using the Marshal class.
    IntPtr hglobal = Marshal::AllocHGlobal(100);
    Marshal::FreeHGlobal(hglobal);

    // Demonstrate how to use the Marshal class to get the Win32
    // error code when a Win32 method fails.
    bool isCloseHandleSuccess = CloseHandle(IntPtr(-1));
    if (!isCloseHandleSuccess)
    {
        Console::WriteLine(
            "CloseHandle call failed with an error code of: {0}",
            Marshal::GetLastWin32Error());
    }
};

// This is a platform invoke prototype. SetLastError is true,
// which allows the GetLastWin32Error method of the Marshal class
// to work correctly.    
[DllImport("Kernel32", ExactSpelling = true, SetLastError = true)]
extern bool CloseHandle(IntPtr h);

// This code produces the following output.
// 
// SystemDefaultCharSize=2, SystemMaxDBCSCharSize=1
// Number of bytes needed by a Point object: 8
// Number of bytes needed by a Point object: 8
// CloseHandle call failed with an error code of: 6

Información de versión

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1

Seguridad para subprocesos

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Ver también

Espacio de nombres System.Runtime.InteropServices

Volver al principio