Marshal Marshal Marshal Marshal Class

定义

提供了一个方法集合,这些方法用于分配非托管内存、复制非托管内存块、将托管类型转换为非托管类型,此外还提供了在与非托管代码交互时使用的其他杂项方法。 Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code.

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

示例

下面的示例演示如何使用各种方法由定义Marshal类。The following example shows how to use various methods defined by the Marshal class.

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
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类对使用非托管代码至关重要。The static methods defined on the Marshal class are essential to working with unmanaged code. 此类中定义的大多数方法常用的开发人员想要提供的托管和非托管编程模型之间的桥梁。Most methods defined in this class are typically used by developers who want to provide a bridge between the managed and unmanaged programming models. 例如,StringToHGlobalAnsi方法将 ANSI 字符 (中托管的堆) 的指定字符串复制到非托管堆中的缓冲区。For example, the StringToHGlobalAnsi method copies ANSI characters from a specified string (in the managed heap) to a buffer in the unmanaged heap. 它还会分配适当大小的目标堆。It also allocates the target heap of the right size.

公共语言运行时提供了特定的封送处理功能。The common language runtime provides specific marshaling capabilities. 有关封送处理行为的详细信息,请参阅互操作封送处理For details on marshaling behavior, see Interop Marshaling.

ReadWrite中的方法Marshal类支持对齐和未对齐的访问权限。The Read and Write methods in the Marshal class support both aligned and unaligned access.

字段

SystemDefaultCharSize SystemDefaultCharSize SystemDefaultCharSize SystemDefaultCharSize

表示系统上的默认字符大小;Unicode 系统上默认值为 2,ANSI 系统上默认值为 1。 Represents the default character size on the system; the default is 2 for Unicode systems and 1 for ANSI systems. 此字段为只读。 This field is read-only.

SystemMaxDBCSCharSize SystemMaxDBCSCharSize SystemMaxDBCSCharSize SystemMaxDBCSCharSize

表示用于当前操作系统的双字节字符集 (DBCS) 的最大大小(以字节为单位)。 Represents the maximum size of a double byte character set (DBCS) size, in bytes, for the current operating system. 此字段为只读。 This field is read-only.

方法

AddRef(IntPtr) AddRef(IntPtr) AddRef(IntPtr) AddRef(IntPtr)

递增指定接口上的引用计数。 Increments the reference count on the specified interface.

AllocCoTaskMem(Int32) AllocCoTaskMem(Int32) AllocCoTaskMem(Int32) AllocCoTaskMem(Int32)

从 COM 任务内存分配器分配指定大小的内存块。 Allocates a block of memory of specified size from the COM task memory allocator.

AllocHGlobal(Int32) AllocHGlobal(Int32) AllocHGlobal(Int32) AllocHGlobal(Int32)

通过使用指定的字节数,从进程的非托管内存中分配内存。 Allocates memory from the unmanaged memory of the process by using the specified number of bytes.

AllocHGlobal(IntPtr) AllocHGlobal(IntPtr) AllocHGlobal(IntPtr) AllocHGlobal(IntPtr)

通过使用指向指定字节数的指针,从进程的非托管内存中分配内存。 Allocates memory from the unmanaged memory of the process by using the pointer to the specified number of bytes.

AreComObjectsAvailableForCleanup() AreComObjectsAvailableForCleanup() AreComObjectsAvailableForCleanup() AreComObjectsAvailableForCleanup()

指示是否可以清除任何上下文中的运行时可调用包装器 (RCW)。 Indicates whether runtime callable wrappers (RCWs) from any context are available for cleanup.

BindToMoniker(String) BindToMoniker(String) BindToMoniker(String) BindToMoniker(String)

获取由指定的名字对象标识的接口指针。 Gets an interface pointer identified by the specified moniker.

BufferToBSTR(Array, Int32) BufferToBSTR(Array, Int32) BufferToBSTR(Array, Int32) BufferToBSTR(Array, Int32)
ChangeWrapperHandleStrength(Object, Boolean) ChangeWrapperHandleStrength(Object, Boolean) ChangeWrapperHandleStrength(Object, Boolean) ChangeWrapperHandleStrength(Object, Boolean)

更改对象的 COM 可调用包装器 (CCW) 句柄的强度。 Changes the strength of an object's COM Callable Wrapper (CCW) handle.

CleanupUnusedObjectsInCurrentContext() CleanupUnusedObjectsInCurrentContext() CleanupUnusedObjectsInCurrentContext() CleanupUnusedObjectsInCurrentContext()

通知运行时清理当前上下文中分配的所有运行时可调用包装器 (RCW)。 Notifies the runtime to clean up all Runtime Callable Wrappers (RCWs) allocated in the current context.

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

将数据从一维托管单精度浮点数数组复制到非托管内存指针。 Copies data from a one-dimensional, managed single-precision floating-point number array to an unmanaged memory pointer.

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

将数据从一维托管的 IntPtr 数组复制到非托管内存指针。 Copies data from a one-dimensional, managed IntPtr array to an unmanaged memory pointer.

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

将数据从非托管内存指针复制到托管单精度浮点数数组。 Copies data from an unmanaged memory pointer to a managed single-precision floating-point number array.

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

将数据从非托管内存指针复制到托管 64 位带符号整数数组。 Copies data from an unmanaged memory pointer to a managed 64-bit signed integer array.

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

将数据从非托管内存指针复制到托管 32 位带符号整数数组。 Copies data from an unmanaged memory pointer to a managed 32-bit signed integer array.

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

将数据从非托管内存指针复制到托管 16 位带符号整数数组。 Copies data from an unmanaged memory pointer to a managed 16-bit signed integer array.

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

将数据从非托管内存指针复制到托管双精度浮点数数组。 Copies data from an unmanaged memory pointer to a managed double-precision floating-point number array.

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

将数据从非托管的内存指针复制到托管的 IntPtr 数组。 Copies data from an unmanaged memory pointer to a managed IntPtr array.

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

将数据从非托管内存指针复制到托管 8 位无符号整数数组。 Copies data from an unmanaged memory pointer to a managed 8-bit unsigned integer array.

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

将数据从一维托管 64 位带符号整数数组复制到非托管内存指针。 Copies data from a one-dimensional, managed 64-bit signed integer array to an unmanaged memory pointer.

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

将数据从一维托管 32 位带符号整数数组复制到非托管内存指针。 Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointer.

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

将数据从一维托管 16 位带符号整数数组复制到非托管内存指针。 Copies data from a one-dimensional, managed 16-bit signed integer array to an unmanaged memory pointer.

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

将数据从非托管内存指针复制到托管字符数组。 Copies data from an unmanaged memory pointer to a managed character array.

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

将数据从一维托管双精度浮点数数组复制到非托管内存指针。 Copies data from a one-dimensional, managed double-precision floating-point number array to an unmanaged memory pointer.

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

将数据从一维托管字符数组复制到非托管内存指针。 Copies data from a one-dimensional, managed character array to an unmanaged memory pointer.

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

将数据从一维托管 8 位无符号整数数组复制到非托管内存指针。 Copies data from a one-dimensional, managed 8-bit unsigned integer array to an unmanaged memory pointer.

CreateAggregatedObject(IntPtr, Object) CreateAggregatedObject(IntPtr, Object) CreateAggregatedObject(IntPtr, Object) CreateAggregatedObject(IntPtr, Object)

聚合托管对象和指定的 COM 对象。 Aggregates a managed object with the specified COM object.

CreateAggregatedObject<T>(IntPtr, T) CreateAggregatedObject<T>(IntPtr, T) CreateAggregatedObject<T>(IntPtr, T) CreateAggregatedObject<T>(IntPtr, T)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 聚合指定类型的托管对象和指定的 COM 对象。 Aggregates a managed object of the specified type with the specified COM object.

CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type)

在指定类型的对象中包装指定的 COM 对象。 Wraps the specified COM object in an object of the specified type.

CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 在指定类型的对象中包装指定的 COM 对象。 Wraps the specified COM object in an object of the specified type.

DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type) DestroyStructure(IntPtr, Type)

释放指定的非托管内存块所指向的所有子结构。 Frees all substructures that the specified unmanaged memory block points to.

DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr) DestroyStructure<T>(IntPtr)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 释放指定的非托管内存块所指向的所有指定类型的子结构。 Frees all substructures of a specified type that the specified unmanaged memory block points to.

FinalReleaseComObject(Object) FinalReleaseComObject(Object) FinalReleaseComObject(Object) FinalReleaseComObject(Object)

通过将运行时可调用包装器 (RCW) 的引用计数设置为 0,释放对它的所有引用。 Releases all references to a Runtime Callable Wrapper (RCW) by setting its reference count to 0.

FreeBSTR(IntPtr) FreeBSTR(IntPtr) FreeBSTR(IntPtr) FreeBSTR(IntPtr)

使用 COM SysFreeString 函数释放 BSTR Frees a BSTR using the COM SysFreeString function.

FreeCoTaskMem(IntPtr) FreeCoTaskMem(IntPtr) FreeCoTaskMem(IntPtr) FreeCoTaskMem(IntPtr)

释放由非托管 COM 任务内存分配器分配的内存块。 Frees a block of memory allocated by the unmanaged COM task memory allocator.

FreeHGlobal(IntPtr) FreeHGlobal(IntPtr) FreeHGlobal(IntPtr) FreeHGlobal(IntPtr)

释放以前从进程的非托管内存中分配的内存。 Frees memory previously allocated from the unmanaged memory of the process.

GenerateGuidForType(Type) GenerateGuidForType(Type) GenerateGuidForType(Type) GenerateGuidForType(Type)

返回指定类型的全局唯一标识符 (GUID),或使用类型库导出程序 (Tlbexp.exe) 所用的算法生成 GUID。 Returns the globally unique identifier (GUID) for the specified type, or generates a GUID using the algorithm used by the Type Library Exporter (Tlbexp.exe).

GenerateProgIdForType(Type) GenerateProgIdForType(Type) GenerateProgIdForType(Type) GenerateProgIdForType(Type)

返回指定类型的编程标识符 (ProgID)。 Returns a programmatic identifier (ProgID) for the specified type.

GetActiveObject(String) GetActiveObject(String) GetActiveObject(String) GetActiveObject(String)

从运行对象表 (ROT) 获取指定对象的运行实例。 Obtains a running instance of the specified object from the running object table (ROT).

GetComInterfaceForObject(Object, Type) GetComInterfaceForObject(Object, Type) GetComInterfaceForObject(Object, Type) GetComInterfaceForObject(Object, Type)

返回一个指向 IUnknown 接口的指针,该指针表示指定对象上的指定接口。 Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. 默认情况下,启用自定义查询接口访问。 Custom query interface access is enabled by default.

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)

返回一个指向 IUnknown 接口的指针,该指针表示指定对象上的指定接口。 Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. 自定义查询接口访问由指定的自定义模式控制。 Custom query interface access is controlled by the specified customization mode.

GetComInterfaceForObject<T,TInterface>(T) GetComInterfaceForObject<T,TInterface>(T) GetComInterfaceForObject<T,TInterface>(T) GetComInterfaceForObject<T,TInterface>(T)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 返回一个指向 IUnknown 接口的指针,该指针表示指定类型的对象上的指定接口。 Returns a pointer to an IUnknown interface that represents the specified interface on an object of the specified type. 默认情况下,启用自定义查询接口访问。 Custom query interface access is enabled by default.

GetComInterfaceForObjectInContext(Object, Type) GetComInterfaceForObjectInContext(Object, Type) GetComInterfaceForObjectInContext(Object, Type) GetComInterfaceForObjectInContext(Object, Type)

返回一个接口指针,该指针表示对象的指定接口(如果调用方与对象在同一上下文中)。 Returns an interface pointer that represents the specified interface for an object, if the caller is in the same context as that object.

GetComObjectData(Object, Object) GetComObjectData(Object, Object) GetComObjectData(Object, Object) GetComObjectData(Object, Object)

从指定的 COM 对象检索指定键所引用的数据。 Retrieves data that is referenced by the specified key from the specified COM object.

GetComSlotForMethodInfo(MemberInfo) GetComSlotForMethodInfo(MemberInfo) GetComSlotForMethodInfo(MemberInfo) GetComSlotForMethodInfo(MemberInfo)

检索指定的 MemberInfo 类型向 COM 公开时该类型的虚拟功能表(v 表或 VTBL)槽。 Retrieves the virtual function table (v-table or VTBL) slot for a specified MemberInfo type when that type is exposed to COM.

GetDelegateForFunctionPointer(IntPtr, Type) GetDelegateForFunctionPointer(IntPtr, Type) GetDelegateForFunctionPointer(IntPtr, Type) GetDelegateForFunctionPointer(IntPtr, Type)

将非托管函数指针转换为委托。 Converts an unmanaged function pointer to a delegate.

GetDelegateForFunctionPointer<TDelegate>(IntPtr) GetDelegateForFunctionPointer<TDelegate>(IntPtr) GetDelegateForFunctionPointer<TDelegate>(IntPtr) GetDelegateForFunctionPointer<TDelegate>(IntPtr)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将非托管函数指针转换为指定类型的委托。 Converts an unmanaged function pointer to a delegate of a specified type.

GetEndComSlot(Type) GetEndComSlot(Type) GetEndComSlot(Type) GetEndComSlot(Type)

检索向 COM 公开时某个类型的虚拟功能表(v 表或 VTBL)中的最后一个槽。 Retrieves the last slot in the virtual function table (v-table or VTBL) of a type when exposed to COM.

GetExceptionCode() GetExceptionCode() GetExceptionCode() GetExceptionCode()

检索标识所发生异常的类型的代码。 Retrieves a code that identifies the type of the exception that occurred.

GetExceptionForHR(Int32) GetExceptionForHR(Int32) GetExceptionForHR(Int32) GetExceptionForHR(Int32)

将指定的 HRESULT 错误代码转换为对应的 Exception 对象。 Converts the specified HRESULT error code to a corresponding Exception object.

GetExceptionForHR(Int32, IntPtr) GetExceptionForHR(Int32, IntPtr) GetExceptionForHR(Int32, IntPtr) GetExceptionForHR(Int32, IntPtr)

将指定的 HRESULT 错误代码转换为对应的 Exception 对象,其中包括通过此异常对象的 IErrorInfo 接口传递的其他错误信息。 Converts the specified HRESULT error code to a corresponding Exception object, with additional error information passed in an IErrorInfo interface for the exception object.

GetExceptionPointers() GetExceptionPointers() GetExceptionPointers() GetExceptionPointers()

检索与计算机无关的异常描述,以及有关异常发生时线程的状态信息。 Retrieves a computer-independent description of an exception, and information about the state that existed for the thread when the exception occurred.

GetFunctionPointerForDelegate(Delegate) GetFunctionPointerForDelegate(Delegate) GetFunctionPointerForDelegate(Delegate) GetFunctionPointerForDelegate(Delegate)

将委托转换为可从非托管代码调用的函数指针。 Converts a delegate into a function pointer that is callable from unmanaged code.

GetFunctionPointerForDelegate<TDelegate>(TDelegate) GetFunctionPointerForDelegate<TDelegate>(TDelegate) GetFunctionPointerForDelegate<TDelegate>(TDelegate) GetFunctionPointerForDelegate<TDelegate>(TDelegate)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将指定类型的委托转换为可从非托管代码调用的函数指针。 Converts a delegate of a specified type to a function pointer that is callable from unmanaged code.

GetHINSTANCE(Module) GetHINSTANCE(Module) GetHINSTANCE(Module) GetHINSTANCE(Module)

返回指定模块的实例句柄 (HINSTANCE)。 Returns the instance handle (HINSTANCE) for the specified module.

GetHRForException(Exception) GetHRForException(Exception) GetHRForException(Exception) GetHRForException(Exception)

将指定异常转换为 HRESULT。 Converts the specified exception to an HRESULT.

GetHRForLastWin32Error() GetHRForLastWin32Error() GetHRForLastWin32Error() GetHRForLastWin32Error()

返回 HRESULT,它对应于使用 Marshal 执行的 Win32 代码引起的最后一个错误。 Returns the HRESULT corresponding to the last error incurred by Win32 code executed using Marshal.

GetIDispatchForObject(Object) GetIDispatchForObject(Object) GetIDispatchForObject(Object) GetIDispatchForObject(Object)

从托管对象返回一个 IDispatch 接口。 Returns an IDispatch interface from a managed object.

GetIDispatchForObjectInContext(Object) GetIDispatchForObjectInContext(Object) GetIDispatchForObjectInContext(Object) GetIDispatchForObjectInContext(Object)

如果调用方与托管对象在同一上下文中,则从该对象返回一个 IDispatch 接口指针。 Returns an IDispatch interface pointer from a managed object, if the caller is in the same context as that object.

GetITypeInfoForType(Type) GetITypeInfoForType(Type) GetITypeInfoForType(Type) GetITypeInfoForType(Type)

从托管类型返回一个 ITypeInfo 接口。 Returns a ITypeInfo interface from a managed type.

GetIUnknownForObject(Object) GetIUnknownForObject(Object) GetIUnknownForObject(Object) GetIUnknownForObject(Object)

从托管对象返回 IUnknown 接口。 Returns an IUnknown interface from a managed object.

GetIUnknownForObjectInContext(Object) GetIUnknownForObjectInContext(Object) GetIUnknownForObjectInContext(Object) GetIUnknownForObjectInContext(Object)

如果调用方与托管对象在同一上下文中,则从该对象返回一个 IUnknown 接口。 Returns an IUnknown interface from a managed object, if the caller is in the same context as that object.

GetLastWin32Error() GetLastWin32Error() GetLastWin32Error() GetLastWin32Error()

返回由上一个非托管函数返回的错误代码,该函数是使用设置了 SetLastError 标志的平台调用来的。 Returns the error code returned by the last unmanaged function that was called using platform invoke that has the SetLastError flag set.

GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32) GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32) GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32) GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32)

获取指向运行时生成的函数的指针,该函数将调用从托管代码封送到非托管代码。 Gets a pointer to a runtime-generated function that marshals a call from managed to unmanaged code.

GetMethodInfoForComSlot(Type, Int32, ComMemberType) GetMethodInfoForComSlot(Type, Int32, ComMemberType) GetMethodInfoForComSlot(Type, Int32, ComMemberType) GetMethodInfoForComSlot(Type, Int32, ComMemberType)

检索指定的虚拟功能表(v 表或 VTBL)槽的 MemberInfo 对象。 Retrieves a MemberInfo object for the specified virtual function table (v-table or VTBL) slot.

GetNativeVariantForObject(Object, IntPtr) GetNativeVariantForObject(Object, IntPtr) GetNativeVariantForObject(Object, IntPtr) GetNativeVariantForObject(Object, IntPtr)

将对象转换为 COM VARIANT。 Converts an object to a COM VARIANT.

GetNativeVariantForObject<T>(T, IntPtr) GetNativeVariantForObject<T>(T, IntPtr) GetNativeVariantForObject<T>(T, IntPtr) GetNativeVariantForObject<T>(T, IntPtr)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将指定类型的对象转换为 COM VARIANT。 Converts an object of a specified type to a COM VARIANT.

GetObjectForIUnknown(IntPtr) GetObjectForIUnknown(IntPtr) GetObjectForIUnknown(IntPtr) GetObjectForIUnknown(IntPtr)

返回一个类型实例,该实例通过指向 COM 对象的 IUnknown 接口的指针表示该对象。 Returns an instance of a type that represents a COM object by a pointer to its IUnknown interface.

GetObjectForNativeVariant(IntPtr) GetObjectForNativeVariant(IntPtr) GetObjectForNativeVariant(IntPtr) GetObjectForNativeVariant(IntPtr)

将 COM VARIANT 转换为对象。 Converts a COM VARIANT to an object.

GetObjectForNativeVariant<T>(IntPtr) GetObjectForNativeVariant<T>(IntPtr) GetObjectForNativeVariant<T>(IntPtr) GetObjectForNativeVariant<T>(IntPtr)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将 COM VARIANT 转换为指定类型的对象。 Converts a COM VARIANT to an object of a specified type.

GetObjectsForNativeVariants(IntPtr, Int32) GetObjectsForNativeVariants(IntPtr, Int32) GetObjectsForNativeVariants(IntPtr, Int32) GetObjectsForNativeVariants(IntPtr, Int32)

将 COM VARIANT 数组转换为对象数组。 Converts an array of COM VARIANTs to an array of objects.

GetObjectsForNativeVariants<T>(IntPtr, Int32) GetObjectsForNativeVariants<T>(IntPtr, Int32) GetObjectsForNativeVariants<T>(IntPtr, Int32) GetObjectsForNativeVariants<T>(IntPtr, Int32)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将 COM VARIANT 数组转换为指定类型的数组。 Converts an array of COM VARIANTs to an array of a specified type.

GetStartComSlot(Type) GetStartComSlot(Type) GetStartComSlot(Type) GetStartComSlot(Type)

获取虚拟功能表(v 表或 VTBL)中包含用户定义的方法的第一个槽。 Gets the first slot in the virtual function table (v-table or VTBL) that contains user-defined methods.

GetThreadFromFiberCookie(Int32) GetThreadFromFiberCookie(Int32) GetThreadFromFiberCookie(Int32) GetThreadFromFiberCookie(Int32)

将纤程 cookie 转换为相应的 Thread 实例。 Converts a fiber cookie into the corresponding Thread instance.

GetTypedObjectForIUnknown(IntPtr, Type) GetTypedObjectForIUnknown(IntPtr, Type) GetTypedObjectForIUnknown(IntPtr, Type) GetTypedObjectForIUnknown(IntPtr, Type)

返回表示 COM 对象的指定类型的托管对象。 Returns a managed object of a specified type that represents a COM object.

GetTypeForITypeInfo(IntPtr) GetTypeForITypeInfo(IntPtr) GetTypeForITypeInfo(IntPtr) GetTypeForITypeInfo(IntPtr)

将非托管 ITypeInfo 对象转换为托管 Type 对象。 Converts an unmanaged ITypeInfo object into a managed Type object.

GetTypeFromCLSID(Guid) GetTypeFromCLSID(Guid) GetTypeFromCLSID(Guid) GetTypeFromCLSID(Guid)

返回与指定的类标识符 (CLSID) 关联的类型。 Returns the type associated with the specified class identifier (CLSID).

GetTypeInfoName(UCOMITypeInfo) GetTypeInfoName(UCOMITypeInfo) GetTypeInfoName(UCOMITypeInfo) GetTypeInfoName(UCOMITypeInfo)

检索由 ITypeInfo 对象表示的类型的名称。 Retrieves the name of the type represented by an ITypeInfo object.

GetTypeInfoName(ITypeInfo) GetTypeInfoName(ITypeInfo) GetTypeInfoName(ITypeInfo) GetTypeInfoName(ITypeInfo)

检索由 ITypeInfo 对象表示的类型的名称。 Retrieves the name of the type represented by an ITypeInfo object.

GetTypeLibGuid(ITypeLib) GetTypeLibGuid(ITypeLib) GetTypeLibGuid(ITypeLib) GetTypeLibGuid(ITypeLib)

检索类型库的库标识符 (LIBID)。 Retrieves the library identifier (LIBID) of a type library.

GetTypeLibGuid(UCOMITypeLib) GetTypeLibGuid(UCOMITypeLib) GetTypeLibGuid(UCOMITypeLib) GetTypeLibGuid(UCOMITypeLib)

检索类型库的库标识符 (LIBID)。 Retrieves the library identifier (LIBID) of a type library.

GetTypeLibGuidForAssembly(Assembly) GetTypeLibGuidForAssembly(Assembly) GetTypeLibGuidForAssembly(Assembly) GetTypeLibGuidForAssembly(Assembly)

检索从指定程序集导出类型库时分配给该类型库的库标识符 (LIBID)。 Retrieves the library identifier (LIBID) that is assigned to a type library when it was exported from the specified assembly.

GetTypeLibLcid(ITypeLib) GetTypeLibLcid(ITypeLib) GetTypeLibLcid(ITypeLib) GetTypeLibLcid(ITypeLib)

检索类型库的 LCID。 Retrieves the LCID of a type library.

GetTypeLibLcid(UCOMITypeLib) GetTypeLibLcid(UCOMITypeLib) GetTypeLibLcid(UCOMITypeLib) GetTypeLibLcid(UCOMITypeLib)

检索类型库的 LCID。 Retrieves the LCID of a type library.

GetTypeLibName(ITypeLib) GetTypeLibName(ITypeLib) GetTypeLibName(ITypeLib) GetTypeLibName(ITypeLib)

检索类型库的名称。 Retrieves the name of a type library.

GetTypeLibName(UCOMITypeLib) GetTypeLibName(UCOMITypeLib) GetTypeLibName(UCOMITypeLib) GetTypeLibName(UCOMITypeLib)

检索类型库的名称。 Retrieves the name of a type library.

GetTypeLibVersionForAssembly(Assembly, Int32, Int32) GetTypeLibVersionForAssembly(Assembly, Int32, Int32) GetTypeLibVersionForAssembly(Assembly, Int32, Int32) GetTypeLibVersionForAssembly(Assembly, Int32, Int32)

检索将从指定程序集导出的类型库的版本号。 Retrieves the version number of a type library that will be exported from the specified assembly.

GetUniqueObjectForIUnknown(IntPtr) GetUniqueObjectForIUnknown(IntPtr) GetUniqueObjectForIUnknown(IntPtr) GetUniqueObjectForIUnknown(IntPtr)

为给定的 IUnknown 接口创建唯一的运行时可调用包装器 (RCW) 对象。 Creates a unique Runtime Callable Wrapper (RCW) object for a given IUnknown interface.

GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32) GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32) GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32) GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32)

获取指向运行时生成的函数的指针,该函数将调用从非托管代码封送到托管代码。 Gets a pointer to a runtime-generated function that marshals a call from unmanaged to managed code.

IsComObject(Object) IsComObject(Object) IsComObject(Object) IsComObject(Object)

指示指定对象是否表示 COM 对象。 Indicates whether a specified object represents a COM object.

IsTypeVisibleFromCom(Type) IsTypeVisibleFromCom(Type) IsTypeVisibleFromCom(Type) IsTypeVisibleFromCom(Type)

指示类型对 COM 客户端是否可见。 Indicates whether a type is visible to COM clients.

NumParamBytes(MethodInfo) NumParamBytes(MethodInfo) NumParamBytes(MethodInfo) NumParamBytes(MethodInfo)

计算在非托管内存中保存指定方法的参数所需要的字节数。 Calculates the number of bytes in unmanaged memory that are required to hold the parameters for the specified method.

OffsetOf(Type, String) OffsetOf(Type, String) OffsetOf(Type, String) OffsetOf(Type, String)

返回托管类的非托管形式的字段偏移量。 Returns the field offset of the unmanaged form of the managed class.

OffsetOf<T>(String) OffsetOf<T>(String) OffsetOf<T>(String) OffsetOf<T>(String)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 返回指定托管类的非托管形式的字段偏移量。 Returns the field offset of the unmanaged form of a specified managed class.

Prelink(MethodInfo) Prelink(MethodInfo) Prelink(MethodInfo) Prelink(MethodInfo)

在不调用方法的情况下执行一次性方法设置任务。 Executes one-time method setup tasks without calling the method.

PrelinkAll(Type) PrelinkAll(Type) PrelinkAll(Type) PrelinkAll(Type)

对类上的所有方法执行预链接检查。 Performs a pre-link check for all methods on a class.

PtrToStringAnsi(IntPtr) PtrToStringAnsi(IntPtr) PtrToStringAnsi(IntPtr) PtrToStringAnsi(IntPtr)

将非托管 ANSI 字符串中第一个空字符之前的所有字符复制到托管 String,并将每个 ANSI 字符扩展为 Unicode 字符。 Copies all characters up to the first null character from an unmanaged ANSI string to a managed String, and widens each ANSI character to Unicode.

PtrToStringAnsi(IntPtr, Int32) PtrToStringAnsi(IntPtr, Int32) PtrToStringAnsi(IntPtr, Int32) PtrToStringAnsi(IntPtr, Int32)

分配托管 String,然后从非托管 ANSI 字符串向其复制指定数目的字符,并将每个 ANSI 字符扩展为 Unicode 字符。 Allocates a managed String, copies a specified number of characters from an unmanaged ANSI string into it, and widens each ANSI character to Unicode.

PtrToStringAuto(IntPtr) PtrToStringAuto(IntPtr) PtrToStringAuto(IntPtr) PtrToStringAuto(IntPtr)

分配托管 String,并从非托管内存中存储的字符串向其复制第一个空字符之前的所有字符。 Allocates a managed String and copies all characters up to the first null character from a string stored in unmanaged memory into it.

PtrToStringAuto(IntPtr, Int32) PtrToStringAuto(IntPtr, Int32) PtrToStringAuto(IntPtr, Int32) PtrToStringAuto(IntPtr, Int32)

分配托管 String,并从存储在非托管内存中的字符串向其复制指定数目的字符。 Allocates a managed String and copies the specified number of characters from a string stored in unmanaged memory into it.

PtrToStringBSTR(IntPtr) PtrToStringBSTR(IntPtr) PtrToStringBSTR(IntPtr) PtrToStringBSTR(IntPtr)

分配已托管的 String,并向其中复制非托管内存中存储的 二进制字符串 (BSTR) Allocates a managed String and copies a binary string (BSTR) stored in unmanaged memory into it.

PtrToStringUni(IntPtr) PtrToStringUni(IntPtr) PtrToStringUni(IntPtr) PtrToStringUni(IntPtr)

分配托管 String,并从非托管 Unicode 字符串向其复制第一个空字符之前的所有字符。 Allocates a managed String and copies all characters up to the first null character from an unmanaged Unicode string into it.

PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32) PtrToStringUni(IntPtr, Int32)

分配托管 String,并从非托的 Unicode 字符串向其复制指定数目的字符。 Allocates a managed String and copies a specified number of characters from an unmanaged Unicode string into it.

PtrToStringUTF8(IntPtr) PtrToStringUTF8(IntPtr) PtrToStringUTF8(IntPtr) PtrToStringUTF8(IntPtr)
PtrToStringUTF8(IntPtr, Int32) PtrToStringUTF8(IntPtr, Int32) PtrToStringUTF8(IntPtr, Int32) PtrToStringUTF8(IntPtr, Int32)
PtrToStructure(IntPtr, Object) PtrToStructure(IntPtr, Object) PtrToStructure(IntPtr, Object) PtrToStructure(IntPtr, Object)

将数据从非托管内存块封送到托管对象。 Marshals data from an unmanaged block of memory to a managed object.

PtrToStructure(IntPtr, Type) PtrToStructure(IntPtr, Type) PtrToStructure(IntPtr, Type) PtrToStructure(IntPtr, Type)

将数据从非托管内存块封送到新分配的指定类型的托管对象。 Marshals data from an unmanaged block of memory to a newly allocated managed object of the specified type.

PtrToStructure<T>(IntPtr) PtrToStructure<T>(IntPtr) PtrToStructure<T>(IntPtr) PtrToStructure<T>(IntPtr)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将数据从非托管内存块封送到泛型类型参数指定的类型的新分配托管对象。 Marshals data from an unmanaged block of memory to a newly allocated managed object of the type specified by a generic type parameter.

PtrToStructure<T>(IntPtr, T) PtrToStructure<T>(IntPtr, T) PtrToStructure<T>(IntPtr, T) PtrToStructure<T>(IntPtr, T)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将数据从非托管内存块封送到指定类型的托管内存对象。 Marshals data from an unmanaged block of memory to a managed object of the specified type.

QueryInterface(IntPtr, Guid, IntPtr) QueryInterface(IntPtr, Guid, IntPtr) QueryInterface(IntPtr, Guid, IntPtr) QueryInterface(IntPtr, Guid, IntPtr)

从 COM 对象请求指向指定接口的指针。 Requests a pointer to a specified interface from a COM object.

ReadByte(IntPtr, Int32) ReadByte(IntPtr, Int32) ReadByte(IntPtr, Int32) ReadByte(IntPtr, Int32)

从非托管内存按给定的偏移量(或索引)读取单个字节。 Reads a single byte at a given offset (or index) from unmanaged memory.

ReadByte(Object, Int32) ReadByte(Object, Int32) ReadByte(Object, Int32) ReadByte(Object, Int32)

从非托管内存按给定的偏移量(或索引)读取单个字节。 Reads a single byte at a given offset (or index) from unmanaged memory.

ReadByte(IntPtr) ReadByte(IntPtr) ReadByte(IntPtr) ReadByte(IntPtr)

从非托管内存读取单个字节。 Reads a single byte from unmanaged memory.

ReadInt16(IntPtr) ReadInt16(IntPtr) ReadInt16(IntPtr) ReadInt16(IntPtr)

从非托管内存中读取一个 16 位带符号整数。 Reads a 16-bit signed integer from unmanaged memory.

ReadInt16(IntPtr, Int32) ReadInt16(IntPtr, Int32) ReadInt16(IntPtr, Int32) ReadInt16(IntPtr, Int32)

从非托管内存按给定的偏移量读取一个 16 位带符号整数。 Reads a 16-bit signed integer at a given offset from unmanaged memory.

ReadInt16(Object, Int32) ReadInt16(Object, Int32) ReadInt16(Object, Int32) ReadInt16(Object, Int32)

从非托管内存按给定的偏移量读取一个 16 位带符号整数。 Reads a 16-bit signed integer at a given offset from unmanaged memory.

ReadInt32(IntPtr) ReadInt32(IntPtr) ReadInt32(IntPtr) ReadInt32(IntPtr)

从非托管内存中读取一个 32 位带符号整数。 Reads a 32-bit signed integer from unmanaged memory.

ReadInt32(IntPtr, Int32) ReadInt32(IntPtr, Int32) ReadInt32(IntPtr, Int32) ReadInt32(IntPtr, Int32)

从非托管内存按给定的偏移量读取一个 32 位带符号整数。 Reads a 32-bit signed integer at a given offset from unmanaged memory.

ReadInt32(Object, Int32) ReadInt32(Object, Int32) ReadInt32(Object, Int32) ReadInt32(Object, Int32)

从非托管内存按给定的偏移量读取一个 32 位带符号整数。 Reads a 32-bit signed integer at a given offset from unmanaged memory.

ReadInt64(IntPtr) ReadInt64(IntPtr) ReadInt64(IntPtr) ReadInt64(IntPtr)

从非托管内存中读取一个 64 位带符号整数。 Reads a 64-bit signed integer from unmanaged memory.

ReadInt64(IntPtr, Int32) ReadInt64(IntPtr, Int32) ReadInt64(IntPtr, Int32) ReadInt64(IntPtr, Int32)

从非托管内存按给定的偏移量读取一个 64 位带符号整数。 Reads a 64-bit signed integer at a given offset from unmanaged memory.

ReadInt64(Object, Int32) ReadInt64(Object, Int32) ReadInt64(Object, Int32) ReadInt64(Object, Int32)

从非托管内存按给定的偏移量读取一个 64 位带符号整数。 Reads a 64-bit signed integer at a given offset from unmanaged memory.

ReadIntPtr(IntPtr, Int32) ReadIntPtr(IntPtr, Int32) ReadIntPtr(IntPtr, Int32) ReadIntPtr(IntPtr, Int32)

从非托管内存按给定的偏移量读取处理器本机大小的整数。 Reads a processor native sized integer at a given offset from unmanaged memory.

ReadIntPtr(Object, Int32) ReadIntPtr(Object, Int32) ReadIntPtr(Object, Int32) ReadIntPtr(Object, Int32)

从非托管内存读取处理器本机大小的整数。 Reads a processor native sized integer from unmanaged memory.

ReadIntPtr(IntPtr) ReadIntPtr(IntPtr) ReadIntPtr(IntPtr) ReadIntPtr(IntPtr)

从非托管内存读取处理器本机大小的整数。 Reads a processor native-sized integer from unmanaged memory.

ReAllocCoTaskMem(IntPtr, Int32) ReAllocCoTaskMem(IntPtr, Int32) ReAllocCoTaskMem(IntPtr, Int32) ReAllocCoTaskMem(IntPtr, Int32)

调整之前用 AllocCoTaskMem(Int32) 分配的内存块的大小。 Resizes a block of memory previously allocated with AllocCoTaskMem(Int32).

ReAllocHGlobal(IntPtr, IntPtr) ReAllocHGlobal(IntPtr, IntPtr) ReAllocHGlobal(IntPtr, IntPtr) ReAllocHGlobal(IntPtr, IntPtr)

调整之前用 AllocHGlobal(IntPtr) 分配的内存块的大小。 Resizes a block of memory previously allocated with AllocHGlobal(IntPtr).

Release(IntPtr) Release(IntPtr) Release(IntPtr) Release(IntPtr)

递减指定接口上的引用计数。 Decrements the reference count on the specified interface.

ReleaseComObject(Object) ReleaseComObject(Object) ReleaseComObject(Object) ReleaseComObject(Object)

递减与指定的 COM 对象关联的运行时可调用包装器 (RCW) 的引用计数。 Decrements the reference count of the Runtime Callable Wrapper (RCW) associated with the specified COM object.

ReleaseThreadCache() ReleaseThreadCache() ReleaseThreadCache() ReleaseThreadCache()

释放线程缓存。 Releases the thread cache.

SecureStringToBSTR(SecureString) SecureStringToBSTR(SecureString) SecureStringToBSTR(SecureString) SecureStringToBSTR(SecureString)

分配非托管二进制字符串 (BSTR)并将托管 SecureString 对象的内容复制到其中。 Allocates an unmanaged binary string (BSTR) and copies the contents of a managed SecureString object into it.

SecureStringToCoTaskMemAnsi(SecureString) SecureStringToCoTaskMemAnsi(SecureString) SecureStringToCoTaskMemAnsi(SecureString) SecureStringToCoTaskMemAnsi(SecureString)

将托管 SecureString 对象的内容复制到从非托管 COM 任务分配器分配的内存块。 Copies the contents of a managed SecureString object to a block of memory allocated from the unmanaged COM task allocator.

SecureStringToCoTaskMemUnicode(SecureString) SecureStringToCoTaskMemUnicode(SecureString) SecureStringToCoTaskMemUnicode(SecureString) SecureStringToCoTaskMemUnicode(SecureString)

将托管 SecureString 对象的内容复制到从非托管 COM 任务分配器分配的内存块。 Copies the contents of a managed SecureString object to a block of memory allocated from the unmanaged COM task allocator.

SecureStringToGlobalAllocAnsi(SecureString) SecureStringToGlobalAllocAnsi(SecureString) SecureStringToGlobalAllocAnsi(SecureString) SecureStringToGlobalAllocAnsi(SecureString)

将托管 SecureString 的内容复制到非托管内存,并在复制时转换为 ANSI 格式。 Copies the contents of a managed SecureString into unmanaged memory, converting into ANSI format as it copies.

SecureStringToGlobalAllocUnicode(SecureString) SecureStringToGlobalAllocUnicode(SecureString) SecureStringToGlobalAllocUnicode(SecureString) SecureStringToGlobalAllocUnicode(SecureString)

将托管 SecureString 对象的内容复制到非托管内存中。 Copies the contents of a managed SecureString object into unmanaged memory.

SetComObjectData(Object, Object, Object) SetComObjectData(Object, Object, Object) SetComObjectData(Object, Object, Object) SetComObjectData(Object, Object, Object)

设置由指定 COM 对象中的指定键引用的数据。 Sets data referenced by the specified key in the specified COM object.

SizeOf(Object) SizeOf(Object) SizeOf(Object) SizeOf(Object)

返回对象的非托管大小(以字节为单位)。 Returns the unmanaged size of an object in bytes.

SizeOf(Type) SizeOf(Type) SizeOf(Type) SizeOf(Type)

返回非托管类型的大小(以字节为单位)。 Returns the size of an unmanaged type in bytes.

SizeOf<T>() SizeOf<T>() SizeOf<T>() SizeOf<T>()

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 返回非托管类型的大小(以字节为单位)。 Returns the size of an unmanaged type in bytes.

SizeOf<T>(T) SizeOf<T>(T) SizeOf<T>(T) SizeOf<T>(T)

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 返回指定类型的对象的非托管大小(以字节为单位)。 Returns the unmanaged size of an object of a specified type in bytes.

StringToBSTR(String) StringToBSTR(String) StringToBSTR(String) StringToBSTR(String)

分配 BSTR 并向其复制托管 String 的内容。 Allocates a BSTR and copies the contents of a managed String into it.

StringToCoTaskMemAnsi(String) StringToCoTaskMemAnsi(String) StringToCoTaskMemAnsi(String) StringToCoTaskMemAnsi(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。 Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

StringToCoTaskMemAuto(String) StringToCoTaskMemAuto(String) StringToCoTaskMemAuto(String) StringToCoTaskMemAuto(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。 Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

StringToCoTaskMemUni(String) StringToCoTaskMemUni(String) StringToCoTaskMemUni(String) StringToCoTaskMemUni(String)

将托管 String 的内容复制到从非托管 COM 任务分配器分配的内存块。 Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.

StringToCoTaskMemUTF8(String) StringToCoTaskMemUTF8(String) StringToCoTaskMemUTF8(String) StringToCoTaskMemUTF8(String)
StringToHGlobalAnsi(String) StringToHGlobalAnsi(String) StringToHGlobalAnsi(String) StringToHGlobalAnsi(String)

将托管 String 的内容复制到非托管内存,并在复制时转换为 ANSI 格式。 Copies the contents of a managed String into unmanaged memory, converting into ANSI format as it copies.

StringToHGlobalAuto(String) StringToHGlobalAuto(String) StringToHGlobalAuto(String) StringToHGlobalAuto(String)

将托管 String 的内容复制到非托管内存,并在需要时转换为 ANSI 格式。 Copies the contents of a managed String into unmanaged memory, converting into ANSI format if required.

StringToHGlobalUni(String) StringToHGlobalUni(String) StringToHGlobalUni(String) StringToHGlobalUni(String)

将托管 String 的内容复制到非托管内存。 Copies the contents of a managed String into unmanaged memory.

StructureToPtr(Object, IntPtr, Boolean) StructureToPtr(Object, IntPtr, Boolean) StructureToPtr(Object, IntPtr, Boolean) StructureToPtr(Object, IntPtr, Boolean)

将数据从托管对象封送到非托管内存块。 Marshals data from a managed object to an unmanaged block of memory.

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

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 将数据从指定类型的托管对象封送到非托管内存块。 Marshals data from a managed object of a specified type to an unmanaged block of memory.

ThrowExceptionForHR(Int32) ThrowExceptionForHR(Int32) ThrowExceptionForHR(Int32) ThrowExceptionForHR(Int32)

用特定的失败 HRESULT 值引发异常。 Throws an exception with a specific failure HRESULT value.

ThrowExceptionForHR(Int32, IntPtr) ThrowExceptionForHR(Int32, IntPtr) ThrowExceptionForHR(Int32, IntPtr) ThrowExceptionForHR(Int32, IntPtr)

基于指定的 IErrorInfo 接口,用特定的失败 HRESULT 引发异常。 Throws an exception with a specific failure HRESULT, based on the specified IErrorInfo interface.

UnsafeAddrOfPinnedArrayElement(Array, Int32) UnsafeAddrOfPinnedArrayElement(Array, Int32) UnsafeAddrOfPinnedArrayElement(Array, Int32) UnsafeAddrOfPinnedArrayElement(Array, Int32)

获取指定数组中指定索引处的元素的地址。 Gets the address of the element at the specified index inside the specified array.

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

[在 .NET Framework 4.5.1 和更高版本中受支持] [Supported in the .NET Framework 4.5.1 and later versions] 获取指定类型的数组中指定索引处的元素地址。 Gets the address of the element at the specified index in an array of a specified type.

WriteByte(Object, Int32, Byte) WriteByte(Object, Int32, Byte) WriteByte(Object, Int32, Byte) WriteByte(Object, Int32, Byte)

按指定偏移量将单字节值写入非托管内存。 Writes a single byte value to unmanaged memory at a specified offset.

WriteByte(IntPtr, Int32, Byte) WriteByte(IntPtr, Int32, Byte) WriteByte(IntPtr, Int32, Byte) WriteByte(IntPtr, Int32, Byte)

按指定偏移量将单字节值写入非托管内存。 Writes a single byte value to unmanaged memory at a specified offset.

WriteByte(IntPtr, Byte) WriteByte(IntPtr, Byte) WriteByte(IntPtr, Byte) WriteByte(IntPtr, Byte)

将单个字节值写入到非托管内存。 Writes a single byte value to unmanaged memory.

WriteInt16(IntPtr, Char) WriteInt16(IntPtr, Char) WriteInt16(IntPtr, Char) WriteInt16(IntPtr, Char)

将一个字符作为 16 位整数值写入非托管内存。 Writes a character as a 16-bit integer value to unmanaged memory.

WriteInt16(IntPtr, Int16) WriteInt16(IntPtr, Int16) WriteInt16(IntPtr, Int16) WriteInt16(IntPtr, Int16)

将 16 位整数值写入非托管内存。 Writes a 16-bit integer value to unmanaged memory.

WriteInt16(IntPtr, Int32, Char) WriteInt16(IntPtr, Int32, Char) WriteInt16(IntPtr, Int32, Char) WriteInt16(IntPtr, Int32, Char)

按指定偏移量将 16 位带符号整数值写入非托管内存。 Writes a 16-bit signed integer value to unmanaged memory at a specified offset.

WriteInt16(IntPtr, Int32, Int16) WriteInt16(IntPtr, Int32, Int16) WriteInt16(IntPtr, Int32, Int16) WriteInt16(IntPtr, Int32, Int16)

按指定偏移量将 16 位带符号整数值写入非托管内存。 Writes a 16-bit signed integer value into unmanaged memory at a specified offset.

WriteInt16(Object, Int32, Char) WriteInt16(Object, Int32, Char) WriteInt16(Object, Int32, Char) WriteInt16(Object, Int32, Char)

按指定偏移量将 16 位带符号整数值写入非托管内存。 Writes a 16-bit signed integer value to unmanaged memory at a specified offset.

WriteInt16(Object, Int32, Int16) WriteInt16(Object, Int32, Int16) WriteInt16(Object, Int32, Int16) WriteInt16(Object, Int32, Int16)

按指定偏移量将 16 位带符号整数值写入非托管内存。 Writes a 16-bit signed integer value to unmanaged memory at a specified offset.

WriteInt32(IntPtr, Int32) WriteInt32(IntPtr, Int32) WriteInt32(IntPtr, Int32) WriteInt32(IntPtr, Int32)

将 32 位带符号整数值写入非托管内存。 Writes a 32-bit signed integer value to unmanaged memory.

WriteInt32(IntPtr, Int32, Int32) WriteInt32(IntPtr, Int32, Int32) WriteInt32(IntPtr, Int32, Int32) WriteInt32(IntPtr, Int32, Int32)

按指定偏移量将 32 位带符号整数值写入非托管内存。 Writes a 32-bit signed integer value into unmanaged memory at a specified offset.

WriteInt32(Object, Int32, Int32) WriteInt32(Object, Int32, Int32) WriteInt32(Object, Int32, Int32) WriteInt32(Object, Int32, Int32)

按指定偏移量将 32 位带符号整数值写入非托管内存。 Writes a 32-bit signed integer value to unmanaged memory at a specified offset.

WriteInt64(Object, Int32, Int64) WriteInt64(Object, Int32, Int64) WriteInt64(Object, Int32, Int64) WriteInt64(Object, Int32, Int64)

按指定偏移量将 64 位带符号整数值写入非托管内存。 Writes a 64-bit signed integer value to unmanaged memory at a specified offset.

WriteInt64(IntPtr, Int64) WriteInt64(IntPtr, Int64) WriteInt64(IntPtr, Int64) WriteInt64(IntPtr, Int64)

将 64 位带符号整数值写入非托管内存。 Writes a 64-bit signed integer value to unmanaged memory.

WriteInt64(IntPtr, Int32, Int64) WriteInt64(IntPtr, Int32, Int64) WriteInt64(IntPtr, Int32, Int64) WriteInt64(IntPtr, Int32, Int64)

按指定偏移量将 64 位带符号整数值写入非托管内存。 Writes a 64-bit signed integer value to unmanaged memory at a specified offset.

WriteIntPtr(IntPtr, IntPtr) WriteIntPtr(IntPtr, IntPtr) WriteIntPtr(IntPtr, IntPtr) WriteIntPtr(IntPtr, IntPtr)

将一个处理器本机大小的整数值写入非托管内存。 Writes a processor native sized integer value into unmanaged memory.

WriteIntPtr(IntPtr, Int32, IntPtr) WriteIntPtr(IntPtr, Int32, IntPtr) WriteIntPtr(IntPtr, Int32, IntPtr) WriteIntPtr(IntPtr, Int32, IntPtr)

按指定的偏移量将一个处理器本机大小的整数值写入非托管内存。 Writes a processor native-sized integer value to unmanaged memory at a specified offset.

WriteIntPtr(Object, Int32, IntPtr) WriteIntPtr(Object, Int32, IntPtr) WriteIntPtr(Object, Int32, IntPtr) WriteIntPtr(Object, Int32, IntPtr)

将一个处理器本机大小的整数值写入非托管内存。 Writes a processor native sized integer value to unmanaged memory.

ZeroFreeBSTR(IntPtr) ZeroFreeBSTR(IntPtr) ZeroFreeBSTR(IntPtr) ZeroFreeBSTR(IntPtr)

释放 BSTR 指针,该指针是使用 SecureStringToBSTR(SecureString) 方法分配的。 Frees a BSTR pointer that was allocated using the SecureStringToBSTR(SecureString) method.

ZeroFreeCoTaskMemAnsi(IntPtr) ZeroFreeCoTaskMemAnsi(IntPtr) ZeroFreeCoTaskMemAnsi(IntPtr) ZeroFreeCoTaskMemAnsi(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToCoTaskMemAnsi(SecureString) 方法分配的。 Frees an unmanaged string pointer that was allocated using the SecureStringToCoTaskMemAnsi(SecureString) method.

ZeroFreeCoTaskMemUnicode(IntPtr) ZeroFreeCoTaskMemUnicode(IntPtr) ZeroFreeCoTaskMemUnicode(IntPtr) ZeroFreeCoTaskMemUnicode(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToCoTaskMemUnicode(SecureString) 方法分配的。 Frees an unmanaged string pointer that was allocated using the SecureStringToCoTaskMemUnicode(SecureString) method.

ZeroFreeCoTaskMemUTF8(IntPtr) ZeroFreeCoTaskMemUTF8(IntPtr) ZeroFreeCoTaskMemUTF8(IntPtr) ZeroFreeCoTaskMemUTF8(IntPtr)
ZeroFreeGlobalAllocAnsi(IntPtr) ZeroFreeGlobalAllocAnsi(IntPtr) ZeroFreeGlobalAllocAnsi(IntPtr) ZeroFreeGlobalAllocAnsi(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToGlobalAllocAnsi(SecureString) 方法分配的。 Frees an unmanaged string pointer that was allocated using the SecureStringToGlobalAllocAnsi(SecureString) method.

ZeroFreeGlobalAllocUnicode(IntPtr) ZeroFreeGlobalAllocUnicode(IntPtr) ZeroFreeGlobalAllocUnicode(IntPtr) ZeroFreeGlobalAllocUnicode(IntPtr)

释放非托管字符串指针,该指针是使用 SecureStringToGlobalAllocUnicode(SecureString) 方法分配的。 Frees an unmanaged string pointer that was allocated using the SecureStringToGlobalAllocUnicode(SecureString) method.

适用于