UnmanagedCallConvAttribute Classe

Définition

Spécifie la convention d’appel requise pour appeler des méthodes P/Invoke implémentées dans du code non managé.

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
Héritage
UnmanagedCallConvAttribute
Attributs

Exemples

Les exemples suivants déclarent P/Invokes à l’aide de UnmanagedCallConvAttribute pour spécifier la convention d’appel.

Utilisation de la convention d’appel 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);

Utilisation de la convention d’appel 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);

Remarques

Lorsque cet attribut est appliqué à une méthode avec DllImportAttributeCallingConvention n’est pas défini ou défini sur Winapi, le runtime .NET utilise CallConvs pour déterminer la convention d’appel de P/Invoke.

Cet attribut est ignoré s’il est appliqué à une méthode sans DllImportAttribute ou avec CallingConvention défini sur autre chose que Winapi.

Constructeurs

UnmanagedCallConvAttribute()

Initialise une nouvelle instance de UnmanagedCallConvAttribute.

Champs

CallConvs

Optionnel. Types indiquant des conventions d’appel pour la cible non managée.

Propriétés

TypeId

Lors de l'implémentation dans une classe dérivée, obtient un identificateur unique pour l'objet Attribute.

(Hérité de Attribute)

Méthodes

Equals(Object)

Retourne une valeur qui indique si cette instance est égale à un objet spécifié.

(Hérité de Attribute)
GetHashCode()

Retourne le code de hachage de cette instance.

(Hérité de Attribute)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
IsDefaultAttribute()

En cas de substitution dans une classe dérivée, indique si la valeur de cette instance est la valeur par défaut pour la classe dérivée.

(Hérité de Attribute)
Match(Object)

En cas de substitution dans une classe dérivée, retourne une valeur indiquant si cette instance équivaut à un objet spécifié.

(Hérité de Attribute)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à