UnmanagedCallConvAttribute Classe

Definição

Especifica a convenção de chamada necessária para chamar métodos P/Invoke implementados em código não gerenciado.

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
Herança
UnmanagedCallConvAttribute
Atributos

Exemplos

Os exemplos a seguir declaram P/Invokes usando o UnmanagedCallConvAttribute para especificar a convenção de chamada.

Usando a cdecl convenção de chamada:

// 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);

Usando a stdcall convenção de chamada:

// 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);

Comentários

Quando esse atributo é aplicado a um método com DllImportAttribute o qual CallingConvention não está definido ou definido como Winapi, o runtime do .NET usará CallConvs para determinar a convenção de chamada do P/Invoke.

Esse atributo é ignorado se aplicado a um método sem DllImportAttribute ou com definido como CallingConvention algo diferente de Winapi.

Construtores

UnmanagedCallConvAttribute()

Inicializa uma nova instância UnmanagedCallConvAttribute.

Campos

CallConvs

Opcional. Tipos que indicam convenções de chamada para o destino não gerenciado.

Propriedades

TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
GetHashCode()

Retorna o código hash para a instância.

(Herdado de Attribute)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a