Marshal 类

定义

提供了一个方法集合,这些方法用于分配非托管内存、复制非托管内存块、将托管类型转换为非托管类型,此外还提供了在与非托管代码交互时使用的其他杂项方法。

public ref class Marshal abstract sealed
public ref class Marshal sealed
public static class Marshal
public sealed class Marshal
type Marshal = class
Public Class Marshal
Public NotInheritable Class Marshal
继承
Marshal

示例

以下示例演示如何使用 由 Marshal 类定义的各种方法。

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
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.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

注解

static 类上 Marshal 定义的方法对于使用非托管代码至关重要。 此类中定义的大多数方法通常由想要在托管和非托管编程模型之间提供桥梁的开发人员使用。 例如, StringToHGlobalAnsi 方法将托管堆) 的指定字符串 (的 ANSI 字符复制到非托管堆中的缓冲区。 它还分配大小合适的目标堆。

公共语言运行时提供特定的封送处理功能。 有关封送处理行为的详细信息,请参阅 互操作封送处理

Read类中的 MarshalWrite 方法支持对齐和未对齐的访问。

字段

SystemDefaultCharSize

表示系统上的默认字符大小;Unicode 系统上默认值为 2,ANSI 系统上默认值为 1。 此字段为只读。

SystemMaxDBCSCharSize

表示用于当前操作系统的双字节字符集 (DBCS) 的最大大小(以字节为单位)。 此字段为只读。

方法

AddRef(IntPtr)

递增指定接口上的引用计数。

AllocCoTaskMem(Int32)

从 COM 任务内存分配器分配指定大小的内存块。

AllocHGlobal(Int32)

通过使用指定的字节数,从进程的非托管内存中分配内存。

AllocHGlobal(IntPtr)

通过使用指向指定字节数的指针,从进程的非托管内存中分配内存。

AreComObjectsAvailableForCleanup()

指示是否可以清除任何上下文中的运行时可调用包装器 (RCW)。

BindToMoniker(String)

获取由指定的名字对象标识的接口指针。

ChangeWrapperHandleStrength(Object, Boolean)

更改对象的 COM 可调用包装器 (CCW) 句柄的强度。

CleanupUnusedObjectsInCurrentContext()

通知运行时清理当前上下文中分配的所有运行时可调用包装器 (RCW)

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

将数据从一维托管 8 位无符号整数数组复制到非托管内存指针。

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

将数据从一维托管字符数组复制到非托管内存指针。

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

将数据从一维托管双精度浮点数数组复制到非托管内存指针。

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

将数据从一维托管 16 位带符号整数数组复制到非托管内存指针。

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

将数据从一维托管 32 位带符号整数数组复制到非托管内存指针。

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

将数据从一维托管 64 位带符号整数数组复制到非托管内存指针。

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

将数据从非托管内存指针复制到托管 8 位无符号整数数组。

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

将数据从非托管内存指针复制到托管字符数组。

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

将数据从非托管内存指针复制到托管双精度浮点数数组。

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

将数据从非托管内存指针复制到托管 16 位带符号整数数组。

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

将数据从非托管内存指针复制到托管 32 位带符号整数数组。

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

将数据从非托管内存指针复制到托管 64 位带符号整数数组。

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

将数据从非托管的内存指针复制到托管的 IntPtr 数组。

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

将数据从非托管内存指针复制到托管单精度浮点数数组。

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

将数据从一维托管的 IntPtr 数组复制到非托管内存指针。

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

将数据从一维托管单精度浮点数数组复制到非托管内存指针。

CreateAggregatedObject(IntPtr, Object)
已过时.

聚合托管对象和指定的 COM 对象。

CreateAggregatedObject<T>(IntPtr, T)

聚合指定类型的托管对象和指定的 COM 对象。

CreateWrapperOfType(Object, Type)
已过时.

在指定类型的对象中包装指定的 COM 对象。

CreateWrapperOfType<T,TWrapper>(T)

在指定类型的对象中包装指定的 COM 对象。

DestroyStructure(IntPtr, Type)
已过时.

释放指定的非托管内存块所指向的所有子结构。

DestroyStructure<T>(IntPtr)

释放指定的非托管内存块所指向的所有指定类型的子结构。

FinalReleaseComObject(Object)

通过将运行时可调用包装器 (RCW) 的引用计数设置为 0,释放对它的所有引用。

FreeBSTR(IntPtr)

使用 COM SysFreeString 函数释放 BSTR

FreeCoTaskMem(IntPtr)

释放由非托管 COM 任务内存分配器分配的内存块。

FreeHGlobal(IntPtr)

释放以前从进程的非托管内存中分配的内存。

GenerateGuidForType(Type)

返回指定类型的全局唯一标识符 (GUID),或使用类型库导出程序 (Tlbexp.exe) 所用的算法生成 GUID。

GenerateProgIdForType(Type)

返回指定类型的编程标识符 (ProgID)。

GetActiveObject(String)

从运行对象表 (ROT) 获取指定对象的运行实例。

GetComInterfaceForObject(Object, Type)
已过时.

返回一个指向 IUnknown 接口的指针,该指针表示指定对象上的指定接口。 默认情况下,启用自定义查询接口访问。

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)
已过时.

返回一个指向 IUnknown 接口的指针,该指针表示指定对象上的指定接口。 自定义查询接口访问由指定的自定义模式控制。

GetComInterfaceForObject<T,TInterface>(T)

返回一个指向 IUnknown 接口的指针,该指针表示指定类型的对象上的指定接口。 默认情况下,启用自定义查询接口访问。

GetComInterfaceForObjectInContext(Object, Type)

返回一个接口指针,该指针表示对象的指定接口(如果调用方与对象在同一上下文中)。

GetComObjectData(Object, Object)

从指定的 COM 对象检索指定键所引用的数据。

GetComSlotForMethodInfo(MemberInfo)

检索指定的 MemberInfo 类型向 COM 公开时该类型的虚拟功能表(v 表或 VTBL)槽。

GetDelegateForFunctionPointer(IntPtr, Type)
已过时.

将非托管函数指针转换为委托。

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

将非托管函数指针转换为指定类型的委托。

GetEndComSlot(Type)

检索向 COM 公开时某个类型的虚拟功能表(v 表或 VTBL)中的最后一个槽。

GetExceptionCode()
已过时.

检索标识所发生异常的类型的代码。

GetExceptionForHR(Int32)

将指定的 HRESULT 错误代码转换为对应的 Exception 对象。

GetExceptionForHR(Int32, IntPtr)

将指定的 HRESULT 错误代码转换为对应的 Exception 对象,其中包括通过此异常对象的 IErrorInfo 接口传递的其他错误信息。

GetExceptionPointers()

检索与计算机无关的异常描述,以及有关异常发生时线程的状态信息。

GetFunctionPointerForDelegate(Delegate)
已过时.

将委托转换为可从非托管代码调用的函数指针。

GetFunctionPointerForDelegate<TDelegate>(TDelegate)

将指定类型的委托转换为可从非托管代码调用的函数指针。

GetHINSTANCE(Module)

返回指定模块的实例句柄 (HINSTANCE)。

GetHRForException(Exception)

将指定异常转换为 HRESULT。

GetHRForLastWin32Error()

返回 HRESULT,它对应于使用 Marshal 执行的 Win32 代码引起的最后一个错误。

GetIDispatchForObject(Object)

从托管对象返回一个 IDispatch 接口。

GetIDispatchForObjectInContext(Object)

如果调用方与托管对象在同一上下文中,则从该对象返回一个 IDispatch 接口指针。

GetITypeInfoForType(Type)

从托管类型返回一个 ITypeInfo 接口。

GetIUnknownForObject(Object)

从托管对象返回 IUnknown 接口。

GetIUnknownForObjectInContext(Object)

如果调用方与托管对象在同一上下文中,则从该对象返回一个 IUnknown 接口。

GetLastPInvokeError()

获取当前线程上最后一个平台调用错误。

GetLastPInvokeErrorMessage()

获取最后一个 PInvoke 错误代码的系统错误消息。

GetLastSystemError()

获取当前线程上的最后一个系统错误。

GetLastWin32Error()

返回由上一个非托管函数返回的错误代码,该函数是使用设置了 SetLastError 标志的平台调用来的。

GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32)
已过时.

获取指向运行时生成的函数的指针,该函数将调用从托管代码封送到非托管代码。

GetMethodInfoForComSlot(Type, Int32, ComMemberType)

检索指定的虚拟功能表(v 表或 VTBL)槽的 MemberInfo 对象。

GetNativeVariantForObject(Object, IntPtr)
已过时.

将对象转换为 COM VARIANT。

GetNativeVariantForObject<T>(T, IntPtr)
已过时.

将指定类型的对象转换为 COM VARIANT。

GetObjectForIUnknown(IntPtr)

返回一个类型实例,该实例通过指向 COM 对象的 IUnknown 接口的指针表示该对象。

GetObjectForNativeVariant(IntPtr)
已过时.

将 COM VARIANT 转换为对象。

GetObjectForNativeVariant<T>(IntPtr)
已过时.

将 COM VARIANT 转换为指定类型的对象。

GetObjectsForNativeVariants(IntPtr, Int32)
已过时.

将 COM VARIANT 数组转换为对象数组。

GetObjectsForNativeVariants<T>(IntPtr, Int32)
已过时.

将 COM VARIANT 数组转换为指定类型的数组。

GetPInvokeErrorMessage(Int32)

获取提供的错误代码的系统错误消息。

GetStartComSlot(Type)

获取虚拟功能表(v 表或 VTBL)中包含用户定义的方法的第一个槽。

GetThreadFromFiberCookie(Int32)
已过时.

将纤程 cookie 转换为相应的 Thread 实例。

GetTypedObjectForIUnknown(IntPtr, Type)

返回表示 COM 对象的指定类型的托管对象。

GetTypeForITypeInfo(IntPtr)

将非托管 ITypeInfo 对象转换为托管 Type 对象。

GetTypeFromCLSID(Guid)

返回与指定的类标识符 (CLSID) 关联的类型。

GetTypeInfoName(ITypeInfo)

检索由 ITypeInfo 对象表示的类型的名称。

GetTypeInfoName(UCOMITypeInfo)
已过时.

检索由 ITypeInfo 对象表示的类型的名称。

GetTypeLibGuid(ITypeLib)

检索类型库的库标识符 (LIBID)。

GetTypeLibGuid(UCOMITypeLib)
已过时.

检索类型库的库标识符 (LIBID)。

GetTypeLibGuidForAssembly(Assembly)

检索从指定程序集导出类型库时分配给该类型库的库标识符 (LIBID)。

GetTypeLibLcid(ITypeLib)

检索类型库的 LCID。

GetTypeLibLcid(UCOMITypeLib)
已过时.

检索类型库的 LCID。

GetTypeLibName(ITypeLib)

检索类型库的名称。

GetTypeLibName(UCOMITypeLib)
已过时.

检索类型库的名称。

GetTypeLibVersionForAssembly(Assembly, Int32, Int32)

检索将从指定程序集导出的类型库的版本号。

GetUniqueObjectForIUnknown(IntPtr)

为给定的 IUnknown 接口创建唯一的运行时可调用包装器 (RCW) 对象。

GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32)
已过时.

获取指向运行时生成的函数的指针,该函数将调用从非托管代码封送到托管代码。

InitHandle(SafeHandle, IntPtr)

将新创建 SafeHandle 的基础句柄初始化为提供的值。

IsComObject(Object)

指示指定对象是否表示 COM 对象。

IsTypeVisibleFromCom(Type)

指示类型对 COM 客户端是否可见。

NumParamBytes(MethodInfo)

计算在非托管内存中保存指定方法的参数所需要的字节数。

OffsetOf(Type, String)
已过时.

返回托管类的非托管形式的字段偏移量。

OffsetOf<T>(String)

返回指定托管类的非托管形式的字段偏移量。

Prelink(MethodInfo)

在不调用方法的情况下执行一次性方法设置任务。

PrelinkAll(Type)

对类上的所有方法执行预链接检查。

PtrToStringAnsi(IntPtr)

将非托管 ANSI 或 UTF-8 字符串中第一个空字符之前的所有字符复制到托管 String,并将每个字符扩展为 UTF-16 字符。

PtrToStringAnsi(IntPtr, Int32)

分配托管 String,然后从非托管 ANSI 或 UTF-8 字符串向其复制指定数目的字符,并将每个字符扩展为 UTF-16 字符。

PtrToStringAuto(IntPtr)

分配托管 String,并从非托管内存中存储的字符串向其复制第一个空字符之前的所有字符。

PtrToStringAuto(IntPtr, Int32)

分配托管 String,并从存储在非托管内存中的字符串向其复制指定数目的字符。

PtrToStringBSTR(IntPtr)

分配已托管的 String,并向其中复制非托管内存中存储的 二进制字符串 (BSTR)

PtrToStringUni(IntPtr)

分配托管 String,并从非托管 Unicode 字符串向其复制第一个空字符之前的所有字符。

PtrToStringUni(IntPtr, Int32)

分配托管 String,并从非托的 Unicode 字符串向其复制指定数目的字符。

PtrToStringUTF8(IntPtr)

分配托管的 String,并从非托管的 UTF-8 字符串向其复制第一个空字符之前的所有字符。

PtrToStringUTF8(IntPtr, Int32)

分配托管的 String,并从非托管的 UTF8 字符串向其复制指定数目的字符。

PtrToStructure(IntPtr, Object)
已过时.

将数据从非托管内存块封送到托管对象。

PtrToStructure(IntPtr, Type)
已过时.

将数据从非托管内存块封送到新分配的指定类型的托管对象。

PtrToStructure<T>(IntPtr)

将数据从非托管内存块封送到泛型类型参数指定的类型的新分配托管对象。

PtrToStructure<T>(IntPtr, T)

将数据从非托管内存块封送到指定类型的托管内存对象。

QueryInterface(IntPtr, Guid, IntPtr)

从 COM 对象请求指向指定接口的指针。

ReadByte(IntPtr)

从非托管内存读取单个字节。

ReadByte(IntPtr, Int32)

从非托管内存按给定的偏移量(或索引)读取单个字节。

ReadByte(Object, Int32)
已过时.

从非托管内存按给定的偏移量(或索引)读取单个字节。

ReadInt16(IntPtr)

从非托管内存中读取一个 16 位带符号整数。

ReadInt16(IntPtr, Int32)

从非托管内存按给定的偏移量读取一个 16 位带符号整数。

ReadInt16(Object, Int32)
已过时.

从非托管内存按给定的偏移量读取一个 16 位带符号整数。

ReadInt32(IntPtr)

从非托管内存中读取一个 32 位带符号整数。

ReadInt32(IntPtr, Int32)

从非托管内存按给定的偏移量读取一个 32 位带符号整数。

ReadInt32(Object, Int32)
已过时.

从非托管内存按给定的偏移量读取一个 32 位带符号整数。

ReadInt64(IntPtr)

从非托管内存中读取一个 64 位带符号整数。

ReadInt64(IntPtr, Int32)

从非托管内存按给定的偏移量读取一个 64 位带符号整数。

ReadInt64(Object, Int32)
已过时.

从非托管内存按给定的偏移量读取一个 64 位带符号整数。

ReadIntPtr(IntPtr)

从非托管内存读取处理器本机大小的整数。

ReadIntPtr(IntPtr, Int32)

从非托管内存按给定的偏移量读取处理器本机大小的整数。

ReadIntPtr(Object, Int32)
已过时.

从非托管内存读取处理器本机大小的整数。

ReAllocCoTaskMem(IntPtr, Int32)

调整之前用 AllocCoTaskMem(Int32) 分配的内存块的大小。

ReAllocHGlobal(IntPtr, IntPtr)

调整之前用 AllocHGlobal(IntPtr) 分配的内存块的大小。

Release(IntPtr)

递减指定接口上的引用计数。

ReleaseComObject(Object)

递减与指定的 COM 对象关联的运行时可调用包装器 (RCW) 的引用计数。

ReleaseThreadCache()
已过时.

释放线程缓存。

SecureStringToBSTR(SecureString)

分配非托管二进制字符串 (BSTR)并将托管 SecureString 对象的内容复制到其中。

SecureStringToCoTaskMemAnsi(SecureString)

将托管 SecureString 对象的内容复制到从非托管 COM 任务分配器分配的内存块。

SecureStringToCoTaskMemUnicode(SecureString)

将托管 SecureString 对象的内容复制到从非托管 COM 任务分配器分配的内存块。

SecureStringToGlobalAllocAnsi(SecureString)

将托管 SecureString 的内容复制到非托管内存,并在复制时转换为 ANSI 格式。

SecureStringToGlobalAllocUnicode(SecureString)

将托管 SecureString 对象的内容复制到非托管内存中。

SetComObjectData(Object, Object, Object)

设置由指定 COM 对象中的指定键引用的数据。

SetLastPInvokeError(Int32)

设置当前线程上的最后一个平台调用错误。

SetLastSystemError(Int32)

设置当前线程上的最后一个系统错误。

SizeOf(Object)
已过时.

返回对象的非托管大小(以字节为单位)。

SizeOf(Type)
已过时.

返回非托管类型的大小(以字节为单位)。

SizeOf<T>()

返回非托管类型的大小(以字节为单位)。

SizeOf<T>(T)

返回指定类型的对象的非托管大小(以字节为单位)。

StringToBSTR(String)

分配 BSTR 并向其复制托管 String 的内容。

StringToCoTaskMemAnsi(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。

StringToCoTaskMemAuto(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。

StringToCoTaskMemUni(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。

StringToCoTaskMemUTF8(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。

StringToHGlobalAnsi(String)

将托管 String 的内容复制到非托管内存,并在复制时转换为 ANSI 格式。

StringToHGlobalAuto(String)

将托管 String 的内容复制到非托管内存,并在需要时转换为 ANSI 格式。

StringToHGlobalUni(String)

将托管 String 的内容复制到非托管内存。

StructureToPtr(Object, IntPtr, Boolean)
已过时.

将数据从托管对象封送到非托管内存块。

StructureToPtr<T>(T, IntPtr, Boolean)

将数据从指定类型的托管对象封送到非托管内存块。

ThrowExceptionForHR(Int32)

用特定的失败 HRESULT 值引发异常。

ThrowExceptionForHR(Int32, IntPtr)

基于指定的 IErrorInfo 接口,用特定的失败 HRESULT 引发异常。

UnsafeAddrOfPinnedArrayElement(Array, Int32)
已过时.

获取指定数组中指定索引处的元素的地址。

UnsafeAddrOfPinnedArrayElement<T>(T[], Int32)

获取指定类型的数组中指定索引处的元素地址。

WriteByte(IntPtr, Byte)

将单个字节值写入到非托管内存。

WriteByte(IntPtr, Int32, Byte)

按指定偏移量将单字节值写入非托管内存。

WriteByte(Object, Int32, Byte)
已过时.

按指定偏移量将单字节值写入非托管内存。

WriteInt16(IntPtr, Char)

将一个字符作为 16 位整数值写入非托管内存。

WriteInt16(IntPtr, Int16)

将 16 位整数值写入非托管内存。

WriteInt16(IntPtr, Int32, Char)

按指定偏移量将 16 位带符号整数值写入非托管内存。

WriteInt16(IntPtr, Int32, Int16)

按指定偏移量将 16 位带符号整数值写入非托管内存。

WriteInt16(Object, Int32, Char)
已过时.

按指定偏移量将 16 位带符号整数值写入非托管内存。

WriteInt16(Object, Int32, Int16)
已过时.

按指定偏移量将 16 位带符号整数值写入非托管内存。

WriteInt32(IntPtr, Int32)

将 32 位带符号整数值写入非托管内存。

WriteInt32(IntPtr, Int32, Int32)

按指定偏移量将 32 位带符号整数值写入非托管内存。

WriteInt32(Object, Int32, Int32)
已过时.

按指定偏移量将 32 位带符号整数值写入非托管内存。

WriteInt64(IntPtr, Int32, Int64)

按指定偏移量将 64 位带符号整数值写入非托管内存。

WriteInt64(IntPtr, Int64)

将 64 位带符号整数值写入非托管内存。

WriteInt64(Object, Int32, Int64)
已过时.

按指定偏移量将 64 位带符号整数值写入非托管内存。

WriteIntPtr(IntPtr, Int32, IntPtr)

按指定的偏移量将一个处理器本机大小的整数值写入非托管内存。

WriteIntPtr(IntPtr, IntPtr)

将一个处理器本机大小的整数值写入非托管内存。

WriteIntPtr(Object, Int32, IntPtr)
已过时.

将一个处理器本机大小的整数值写入非托管内存。

ZeroFreeBSTR(IntPtr)

释放 BSTR 指针,该指针是使用 SecureStringToBSTR(SecureString) 方法分配的。

ZeroFreeCoTaskMemAnsi(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToCoTaskMemAnsi(SecureString) 方法分配的。

ZeroFreeCoTaskMemUnicode(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToCoTaskMemUnicode(SecureString) 方法分配的。

ZeroFreeCoTaskMemUTF8(IntPtr)

释放非托管字符串指针,该指针是使用 StringToCoTaskMemUTF8(String) 方法分配的。

ZeroFreeGlobalAllocAnsi(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToGlobalAllocAnsi(SecureString) 方法分配的。

ZeroFreeGlobalAllocUnicode(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToGlobalAllocUnicode(SecureString) 方法分配的。

适用于