Marshal 類別

定義

提供方法的集合,方法用於配置 Unmanaged 記憶體、複製 Unmanaged 記憶體區塊和將 Managed 類型轉換為 Unmanaged 類型,也包括其他和 Unmanaged 程式碼互動時使用的方法。

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 定義的方法對於使用 Unmanaged 程式碼很重要。 此類別中定義的大部分方法通常由想要在 Managed 和 Unmanaged 程式設計模型之間提供橋接器的開發人員使用。 例如,此方法會將 StringToHGlobalAnsi ANSI 字元從 Managed 堆積中指定的字串 () 複製到 Unmanaged 堆積中的緩衝區。 它也會配置大小正確的目標堆積。

Common Language Runtime 提供特定的封送處理功能。 如需封送處理行為的詳細資訊,請參閱 Interop 封送處理

類別 Read 中的 MarshalWrite 方法都支援對齊和未對齊的存取。

欄位

SystemDefaultCharSize

表示系統上的預設字元大小;Unicode 系統的預設值為 2,ANSI 系統為 1。 此欄位為唯讀。

SystemMaxDBCSCharSize

表示用於目前作業系統雙位元組字元集 (DBCS) 大小的最大值,以位元組為單位。 此欄位為唯讀。

方法

AddRef(IntPtr)

遞增指定介面的參考次數 (Reference Count)。

AllocCoTaskMem(Int32)

從 COM 工作記憶體配置器 (Allocator) 配置指定大小的記憶體區塊。

AllocHGlobal(Int32)

使用指定的位元組數目,從處理序的 Unmanaged 記憶體中配置記憶體。

AllocHGlobal(IntPtr)

使用指定數目的位元組指標,從處理序的 Unmanaged 記憶體中配置記憶體。

AreComObjectsAvailableForCleanup()

表示是否有位在任何內容中的執行階段可呼叫包裝函式 (RCW) 可以清除。

BindToMoniker(String)

取得由指定 Moniker 來識別的介面指標。

ChangeWrapperHandleStrength(Object, Boolean)

變更物件 COM 可呼叫包裝函式 (CCW) 控制代碼的強度。

CleanupUnusedObjectsInCurrentContext()

通知執行階段清除目前內容中配置的所有執行階段可呼叫包裝函式 (RCW)

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

從一維、Managed 8 位元不帶正負號的整數 (Unsigned Integer) 陣列將資料複製到 Unmanaged 記憶體指標。

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

從一維、Managed 字元陣列將資料複製到 Unmanaged 記憶體指標。

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

從一維、Managed 雙精確度浮點數陣列將資料複製到 Unmanaged 記憶體指標。

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

從一維、Managed 16 位元帶正負號的整數陣列將資料複製到 Unmanaged 記憶體指標。

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

從一維、Managed 32 位元帶正負號的整數陣列將資料複製到 Unmanaged 記憶體指標。

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

從一維、Managed 64 位元帶正負號的整數陣列將資料複製到 Unmanaged 記憶體指標。

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

從 Unmanaged 記憶體指標將資料複製到 Managed 8 位元不帶正負號的整數 (Unsigned Integer) 陣列。

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

從 Unmanaged 記憶體指標將資料複製到 Managed 字元陣列。

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

從 Unmanaged 記憶體指標將資料複製到Managed 雙精確度浮點數陣列。

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

從 Unmanaged 記憶體指標將資料複製到 Managed 16 位元帶正負號的整數陣列。

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

從 Unmanaged 記憶體指標將資料複製到 Managed 32 位元帶正負號的整數陣列。

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

從 Unmanaged 記憶體指標將資料複製到 Managed 64 位元帶正負號的整數陣列。

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

從 Unmanaged 記憶體指標,將資料複製到 Managed IntPtr 陣列。

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

從 Unmanaged 記憶體指標將資料複製到 Managed 單精確度浮點數陣列。

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

從一維、Managed IntPtr 陣列將資料複製到 Unmanaged 記憶體指標。

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

從一維、Managed 單精確度浮點數陣列將資料複製到 Unmanaged 記憶體指標。

CreateAggregatedObject(IntPtr, Object)
已淘汰.

將 Managed 物件與指定的 COM 物件進行彙總。

CreateAggregatedObject<T>(IntPtr, T)

將所指定類型的 Managed 物件與指定的 COM 物件進行彙總。

CreateWrapperOfType(Object, Type)
已淘汰.

將指定 COM 物件包裝在指定類型的物件中。

CreateWrapperOfType<T,TWrapper>(T)

將指定 COM 物件包裝在指定類型的物件中。

DestroyStructure(IntPtr, Type)
已淘汰.

釋放指定之 Unmanaged 記憶體區塊指向的所有子結構。

DestroyStructure<T>(IntPtr)

釋放指定之 Unmanaged 記憶體區塊指向的所有指定類型的子結構。

FinalReleaseComObject(Object)

執行階段可呼叫包裝函式 (RCW) 的參考計數設為 0,以釋放所有對 RCW 的參考。

FreeBSTR(IntPtr)

使用 COM SysFreeString 函式釋放 BSTR

FreeCoTaskMem(IntPtr)

釋放 Unmanaged COM 工作記憶體配置器所配置的記憶體區塊。

FreeHGlobal(IntPtr)

從處理序的 Unmanaged 記憶體釋放先前配置的記憶體。

GenerateGuidForType(Type)

傳回指定類型的全域唯一識別項 (GUID),或使用類型程式庫匯出工具 (TlbExp.exe) 使用的演算法來產生 GUID。

GenerateProgIdForType(Type)

傳回指定類型的程式設計識別項 (ProgID)。

GetActiveObject(String)

從執行物件表格 (Running Object Table,ROT) 取得指定之物件的執行中執行個體。

GetComInterfaceForObject(Object, Type)
已淘汰.

傳回 IUnknown 介面指標,表示指定物件上的指定介面。 自訂查詢介面存取預設為啟用。

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)
已淘汰.

傳回 IUnknown 介面指標,表示指定物件上的指定介面。 自訂查詢介面存取是由指定的自訂模式所控制。

GetComInterfaceForObject<T,TInterface>(T)

傳回 IUnknown 介面指標,表示指定類型的物件上的指定介面。 自訂查詢介面存取預設為啟用。

GetComInterfaceForObjectInContext(Object, Type)

傳回介面指標,表示物件的指定介面 (如果呼叫端與該物件位於相同內容的話)。

GetComObjectData(Object, Object)

從指定的 COM 物件擷取指定的索引鍵所參考的資料。

GetComSlotForMethodInfo(MemberInfo)

擷取公開給 COM 時,指定之 MemberInfo 類型的虛擬函式表 (v-table 或 VTBL) 位置。

GetDelegateForFunctionPointer(IntPtr, Type)
已淘汰.

將 Unmanaged 函式指標轉換成委派。

GetDelegateForFunctionPointer<TDelegate>(IntPtr)

將 Unmanaged 函式指標轉換成所指定類型的委派。

GetEndComSlot(Type)

擷取公開給 COM 時,類型在虛擬函式表 (v-table 或 VTBL) 中的最後一個位置。

GetExceptionCode()
已淘汰.

擷取可辨識發生的例外狀況 (Exception) 類型的代碼。

GetExceptionForHR(Int32)

將指定的 HRESULT 錯誤碼轉換成對應的 Exception 物件。

GetExceptionForHR(Int32, IntPtr)

將指定的 HRESULT 錯誤碼轉換成對應的 Exception 物件,並將其他錯誤資訊傳入此例外狀況物件的 IErrorInfo 介面。

GetExceptionPointers()

擷取與電腦無關的例外狀況描述,和例外狀況發生時為執行緒保留的狀態資訊。

GetFunctionPointerForDelegate(Delegate)
已淘汰.

將委派轉換成可從 Unmanaged 程式碼呼叫的函式指標。

GetFunctionPointerForDelegate<TDelegate>(TDelegate)

將所指定類型的委派轉換成可從 Unmanaged 程式碼呼叫的函式指標。

GetHINSTANCE(Module)

傳回指定模組的執行個體控制代碼 (HINSTANCE)。

GetHRForException(Exception)

將指定的例外狀況轉換成 HRESULT。

GetHRForLastWin32Error()

傳回 HRESULT,它對應於使用 Marshal 執行的 Win32 程式碼所引發的最後一個錯誤。

GetIDispatchForObject(Object)

從 Managed 物件傳回 IDispatch 介面。

GetIDispatchForObjectInContext(Object)

從 Managed 物件傳回 IDispatch 介面指標 (如果呼叫端與該物件位於相同內容的話)。

GetITypeInfoForType(Type)

從 Managed 型別傳回 ITypeInfo 介面。

GetIUnknownForObject(Object)

從 Managed 物件傳回 IUnknown 介面。

GetIUnknownForObjectInContext(Object)

從 Managed 物件傳回 IUnknown 介面 (如果呼叫端與該物件位於相同內容的話)。

GetLastPInvokeError()

取得目前線程上最後一個平臺叫用錯誤。

GetLastPInvokeErrorMessage()

取得最後一個 PInvoke 錯誤碼的系統錯誤訊息。

GetLastSystemError()

取得目前線程的最後一個系統錯誤。

GetLastWin32Error()

傳回使用平台叫用 (已設定 SetLastError 旗標) 來呼叫的最後 Unmanaged 函式所傳回的錯誤碼。

GetManagedThunkForUnmanagedMethodPtr(IntPtr, IntPtr, Int32)
已淘汰.

取得執行階段產生的函式指標,該函式會從 Managed 程式碼將呼叫封送處理至 Unmanaged 程式碼。

GetMethodInfoForComSlot(Type, Int32, ComMemberType)

擷取指定之虛擬函式表 (v-table 或 VTBL) 位置的 MemberInfo 物件。

GetNativeVariantForObject(Object, IntPtr)
已淘汰.

將物件轉換為 COM VARIANT。

GetNativeVariantForObject<T>(T, IntPtr)
已淘汰.

將所指定類型的物件轉換成 COM VARIANT。

GetObjectForIUnknown(IntPtr)

傳回類型的執行個體,這個執行個體透過 IUnknown 介面指標來表示 COM 物件。

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-table 或 VTBL) 中包含使用者定義之方法的第一個位置。

GetThreadFromFiberCookie(Int32)
已淘汰.

將 Fiber Cookie 轉換成對應的 Thread 執行個體。

GetTypedObjectForIUnknown(IntPtr, Type)

傳回表示 COM 物件之指定類型的 Managed 物件。

GetTypeForITypeInfo(IntPtr)

將 Unmanaged ITypeInfo 物件轉換成 Managed Type 物件。

GetTypeFromCLSID(Guid)

傳回與指定的類別識別項 (CLSID) 關聯的類型。

GetTypeInfoName(ITypeInfo)

擷取以 ITypeInfo 物件表示的類型名稱。

GetTypeInfoName(UCOMITypeInfo)
已淘汰.

擷取以 ITypeInfo 物件表示的類型名稱。

GetTypeLibGuid(ITypeLib)

擷取類型程式庫的程式庫識別項 (LIBID)。

GetTypeLibGuid(UCOMITypeLib)
已淘汰.

擷取類型程式庫的程式庫識別項 (LIBID)。

GetTypeLibGuidForAssembly(Assembly)

擷取當它從指定組件 (Assembly) 匯出時指派給類型程式庫的程式庫識別項 (LIBID)。

GetTypeLibLcid(ITypeLib)

擷取類型程式庫的 LCID。

GetTypeLibLcid(UCOMITypeLib)
已淘汰.

擷取類型程式庫的 LCID。

GetTypeLibName(ITypeLib)

擷取類型程式庫的名稱。

GetTypeLibName(UCOMITypeLib)
已淘汰.

擷取類型程式庫的名稱。

GetTypeLibVersionForAssembly(Assembly, Int32, Int32)

擷取類型程式庫的版本號碼,此程式庫將從指定的組件匯出。

GetUniqueObjectForIUnknown(IntPtr)

針對所指定 IUnknown 介面建立唯一的執行階段可呼叫包裝函式 (RCW) 物件。

GetUnmanagedThunkForManagedMethodPtr(IntPtr, IntPtr, Int32)
已淘汰.

取得執行階段產生的函式指標,該函式會從 Unmanaged 程式碼將呼叫封送處理至 Managed 程式碼。

InitHandle(SafeHandle, IntPtr)

初始化新建立 SafeHandle 至所提供值的基礎控制碼。

IsComObject(Object)

指示指定物件是否表示 COM 物件。

IsTypeVisibleFromCom(Type)

指示類型對 COM 用戶端是否為可見的。

NumParamBytes(MethodInfo)

計算要儲存指定方法的參數而在 unmanaged 記憶體中所需的位元組數目。

OffsetOf(Type, String)
已淘汰.

傳回 Managed 類別之 Unmanaged 表單的欄位位移 (Offset)。

OffsetOf<T>(String)

傳回所指定 Managed 類別之 Unmanaged 表單的欄位位移 (Offset)。

Prelink(MethodInfo)

不需呼叫方法就執行一次方法設定工作。

PrelinkAll(Type)

對類別上的方法進行連結前檢查。

PtrToStringAnsi(IntPtr)

從非受控 ANSI 或 UTF-8 字串將直到第一個 Null 字元的所有字元複製到受控 String,並將每個字元擴展為 UTF-16。

PtrToStringAnsi(IntPtr, Int32)

配置受控 String,從非受控 ANSI 或 UTF-8 字串將指定數目的字元複製到其中,並將每一個字元擴展為 UTF-16。

PtrToStringAuto(IntPtr)

配置 Managed String,並從儲存在 Unmanaged 記憶體的字串中將直到第一個 Null 字元的所有字元複製到其中。

PtrToStringAuto(IntPtr, Int32)

配置 Managed String,並且從儲存在 Unmanaged 記憶體中的字串將指定數目的字元複製到其中。

PtrToStringBSTR(IntPtr)

配置 Managed String,並將儲存在 Unmanaged 記憶體的二進位字串 (BSTR) 複製到其中。

PtrToStringUni(IntPtr)

配置 Managed String,並從 Unmanaged Unicode 字串將直到第一個 Null 字元的所有字元複製到其中。

PtrToStringUni(IntPtr, Int32)

配置 Managed String,並從 Unmanaged Unicode 字串將指定數目的字元複製到其中。

PtrToStringUTF8(IntPtr)

配置受控 String,並從非受控 UTF-8 字串將直到第一個 Null 字元的所有字元,複製到其中。

PtrToStringUTF8(IntPtr, Int32)

配置受控 String,並從非受控 UTF-8 字串將指定數目的位元組,複製到其中。

PtrToStructure(IntPtr, Object)
已淘汰.

從 Unmanaged 記憶體區塊封送處理資料到 Managed 物件。

PtrToStructure(IntPtr, Type)
已淘汰.

從 Unmanaged 記憶體區塊封送處理資料到新配置的指定類型的 Managed 物件。

PtrToStructure<T>(IntPtr)

從 Unmanaged 記憶體區塊封送處理資料到新配置的指定類型的 Managed 物件 (其類型是由泛型類型參數所指定)。

PtrToStructure<T>(IntPtr, T)

從 Unmanaged 記憶體區塊封送處理資料到指定類型的 Managed 物件。

QueryInterface(IntPtr, Guid, IntPtr)

從 COM 物件要求指定介面的指標。

ReadByte(IntPtr)

從 Unmanaged 記憶體讀取單一位元組。

ReadByte(IntPtr, Int32)

從 Unmanaged 記憶體讀取在指定位移 (或索引) 的單一位元組。

ReadByte(Object, Int32)
已淘汰.

從 Unmanaged 記憶體讀取在指定位移 (或索引) 的單一位元組。

ReadInt16(IntPtr)

從 Unmanaged 記憶體讀取 16 位元帶正負號的整數。

ReadInt16(IntPtr, Int32)

從 Unmanaged 記憶體中指定位移處讀取 16 位元帶正負號的整數。

ReadInt16(Object, Int32)
已淘汰.

從 Unmanaged 記憶體中指定位移處讀取 16 位元帶正負號的整數。

ReadInt32(IntPtr)

從 Unmanaged 記憶體讀取 32 位元帶正負號的整數。

ReadInt32(IntPtr, Int32)

從 Unmanaged 記憶體中指定位移處讀取 32 位元帶正負號的整數。

ReadInt32(Object, Int32)
已淘汰.

從 Unmanaged 記憶體中指定位移處讀取 32 位元帶正負號的整數。

ReadInt64(IntPtr)

從 Unmanaged 記憶體讀取 64 位元帶正負號的整數。

ReadInt64(IntPtr, Int32)

從 Unmanaged 記憶體中指定位移處讀取 64 位元帶正負號的整數。

ReadInt64(Object, Int32)
已淘汰.

從 Unmanaged 記憶體中指定位移處讀取 64 位元帶正負號的整數。

ReadIntPtr(IntPtr)

從 Unmanaged 記憶體讀取處理器原生大小的整數。

ReadIntPtr(IntPtr, Int32)

從 Unmanaged 記憶體中指定位移處讀取處理器原生大小的整數。

ReadIntPtr(Object, Int32)
已淘汰.

從 Unmanaged 記憶體讀取處理器原生大小的整數。

ReAllocCoTaskMem(IntPtr, Int32)

調整先前用 AllocCoTaskMem(Int32) 所配置的記憶體區塊的大小。

ReAllocHGlobal(IntPtr, IntPtr)

調整先前用 AllocHGlobal(IntPtr) 所配置的記憶體區塊的大小。

Release(IntPtr)

遞減指定介面上的參考次數。

ReleaseComObject(Object)

遞減與指定 COM 物件相關聯的執行階段可呼叫包裝函式 (RCW) 參考計數。

ReleaseThreadCache()
已淘汰.

釋放執行緒快取。

SecureStringToBSTR(SecureString)

配置 Unmanaged 二進位字串 (BSTR),並將 Managed SecureString 物件的內容複製到其中。

SecureStringToCoTaskMemAnsi(SecureString)

將 Managed SecureString 物件的內容複製到從 Unmanaged COM 工作配置器配置的記憶體區塊。

SecureStringToCoTaskMemUnicode(SecureString)

將 Managed SecureString 物件的內容複製到從 Unmanaged COM 工作配置器配置的記憶體區塊。

SecureStringToGlobalAllocAnsi(SecureString)

將 Managed SecureString 的內容複製到 Unmanaged 記憶體中,並在它複製時轉換成 ANSI 格式。

SecureStringToGlobalAllocUnicode(SecureString)

將 Managed SecureString 物件的內容複製到 Unmanaged 記憶體中。

SetComObjectData(Object, Object, Object)

設定指定COM 物件中指定索引所參考的資料。

SetLastPInvokeError(Int32)

在目前線程上設定最後一個平臺叫用錯誤。

SetLastSystemError(Int32)

設定目前線程的最後一個系統錯誤。

SizeOf(Object)
已淘汰.

傳回物件的 Unmanaged 大小 (以位元組為單位)。

SizeOf(Type)
已淘汰.

傳回 Unmanaged 類型的大小 (以位元組為單位)。

SizeOf<T>()

傳回 Unmanaged 類型的大小 (以位元組為單位)。

SizeOf<T>(T)

傳回指定類型之物件的 Unmanaged 大小,以位元組為單位。

StringToBSTR(String)

配置 BSTR,並將 Managed String 的內容複製到其中。

StringToCoTaskMemAnsi(String)

複製 Managed String 的內容到從 Unmanaged COM 工作配置器配置的記憶體區塊。

StringToCoTaskMemAuto(String)

複製 Managed String 的內容到從 Unmanaged COM 工作配置器配置的記憶體區塊。

StringToCoTaskMemUni(String)

複製 Managed String 的內容到從 Unmanaged COM 工作配置器配置的記憶體區塊。

StringToCoTaskMemUTF8(String)

複製 Managed String 的內容到從 Unmanaged COM 工作配置器配置的記憶體區塊。

StringToHGlobalAnsi(String)

將 Managed String 的內容複製到 Unmanaged 記憶體中,並在它複製時轉換成 ANSI 格式。

StringToHGlobalAuto(String)

複製 Managed String 的內容到 Unmanaged 記憶體中,如有需要則轉換成 ANSI 格式。

StringToHGlobalUni(String)

將 Managed String 的內容複製到 Unmanaged 記憶體。

StructureToPtr(Object, IntPtr, Boolean)
已淘汰.

從 Managed 物件封送處理資料到 Unmanaged 記憶體區塊。

StructureToPtr<T>(T, IntPtr, Boolean)

從指定類型的 Managed 物件封送處理資料到 Unmanaged 記憶體區塊。

ThrowExceptionForHR(Int32)

擲回具有特定錯誤 HRESULT 值的例外狀況。

ThrowExceptionForHR(Int32, IntPtr)

根據指定的 IErrorInfo 介面,擲回具有特定失敗 HRESULT 的例外狀況。

UnsafeAddrOfPinnedArrayElement(Array, Int32)
已淘汰.

取得指定陣列內指定索引處的元素的位址。

UnsafeAddrOfPinnedArrayElement<T>(T[], Int32)

在指定類型的陣列中取得位於指定索引處的元素的位址。

WriteByte(IntPtr, Byte)

將單一位元組值寫入 Unmanaged 記憶體。

WriteByte(IntPtr, Int32, Byte)

將單一位元組值寫入 Unmanaged 記憶體中的指定位移。

WriteByte(Object, Int32, Byte)
已淘汰.

將單一位元組值寫入 Unmanaged 記憶體中的指定位移。

WriteInt16(IntPtr, Char)

將字元當做 16 位元整數值寫入 Unmanaged 記憶體中。

WriteInt16(IntPtr, Int16)

將 16 位元整數值寫入 Unmanaged 記憶體中。

WriteInt16(IntPtr, Int32, Char)

在指定的位移,將 16 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt16(IntPtr, Int32, Int16)

將 16 位元帶正負號的整數值寫入 Unmanaged 記憶體中的指定位移。

WriteInt16(Object, Int32, Char)
已淘汰.

在指定的位移,將 16 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt16(Object, Int32, Int16)
已淘汰.

在指定的位移,將 16 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt32(IntPtr, Int32)

將 32 位元帶正負號的整數值寫入 Unmanaged 記憶體中。

WriteInt32(IntPtr, Int32, Int32)

將 32 位元帶正負號的整數值寫入 Unmanaged 記憶體中的指定位移。

WriteInt32(Object, Int32, Int32)
已淘汰.

在指定的位移,將 32 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt64(IntPtr, Int32, Int64)

在指定的位移,將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteInt64(IntPtr, Int64)

將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體中。

WriteInt64(Object, Int32, Int64)
已淘汰.

在指定的位移,將 64 位元帶正負號的整數值寫入 Unmanaged 記憶體。

WriteIntPtr(IntPtr, Int32, IntPtr)

將處理器原生大小的整數值寫入 Unmanaged 記憶體中的指定位移。

WriteIntPtr(IntPtr, IntPtr)

將處理器原來大小的整數值寫入 Unmanaged 記憶體。

WriteIntPtr(Object, Int32, IntPtr)
已淘汰.

將處理器原來大小的整數值寫入 Unmanaged 記憶體。

ZeroFreeBSTR(IntPtr)

釋放之前使用 SecureStringToBSTR(SecureString) 方法配置的 BSTR 指標。

ZeroFreeCoTaskMemAnsi(IntPtr)

釋放之前使用 SecureStringToCoTaskMemAnsi(SecureString) 方法配置的 Unmanaged 字串指標。

ZeroFreeCoTaskMemUnicode(IntPtr)

釋放之前使用 SecureStringToCoTaskMemUnicode(SecureString) 方法配置的 Unmanaged 字串指標。

ZeroFreeCoTaskMemUTF8(IntPtr)

釋放之前使用 StringToCoTaskMemUTF8(String) 方法配置的 Unmanaged 字串指標。

ZeroFreeGlobalAllocAnsi(IntPtr)

釋放之前使用 SecureStringToGlobalAllocAnsi(SecureString) 方法配置的 Unmanaged 字串指標。

ZeroFreeGlobalAllocUnicode(IntPtr)

釋放之前使用 SecureStringToGlobalAllocUnicode(SecureString) 方法配置的 Unmanaged 字串指標。

適用於