UnmanagedCallConvAttribute 類別

定義

指定呼叫 Unmanaged 程式碼中實作之 P/Invoke 方法所需的呼叫慣例。

public ref class UnmanagedCallConvAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)]
public sealed class UnmanagedCallConvAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple=false, Inherited=false)>]
type UnmanagedCallConvAttribute = class
    inherit Attribute
Public NotInheritable Class UnmanagedCallConvAttribute
Inherits Attribute
繼承
UnmanagedCallConvAttribute
屬性

範例

下列範例會使用 UnmanagedCallConvAttribute 宣告 P/Invokes 來指定呼叫慣例。

cdecl使用呼叫慣例:

// Target will be invoked using the cdecl calling convention
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
[DllImport("NativeLibrary", EntryPoint = "native_function_cdecl")]
internal static extern int NativeFunction(int arg);

// Target will be invoked using the cdecl calling convention and with the GC transition suppressed
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl), typeof(CallConvSuppressGCTransition) })]
[DllImport("NativeLibrary", EntryPoint = "native_function_cdecl")]
internal static extern int NativeFunction_NoGCTransition(int arg);

stdcall使用呼叫慣例:

// Target will be invoked using the stdcall calling convention
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall) })]
[DllImport("NativeLibrary", EntryPoint = "native_function_stdcall")]
internal static extern int NativeFunction(int arg);

// Target will be invoked using the stdcall calling convention and with the GC transition suppressed
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall), typeof(CallConvSuppressGCTransition) })]
[DllImport("NativeLibrary", EntryPoint = "native_function_stdcall")]
internal static extern int NativeFunction_NoGCTransition(int arg);

備註

當這個屬性套用至未設定或設定為 Winapi 的方法 DllImportAttributeCallingConvention 時,.NET 執行時間會使用 CallConvs 來判斷 P/Invoke 的呼叫慣例。

如果套用至不含 DllImportAttributeCallingConvention 設定為 以外的 Winapi 專案的方法,則會忽略這個屬性。

建構函式

UnmanagedCallConvAttribute()

初始化新的 UnmanagedCallConvAttribute 執行個體。

欄位

CallConvs

選擇性。 指出 Unmanaged 目標呼叫慣例的類型。

屬性

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於