CallingConvention CallingConvention CallingConvention CallingConvention Enum

Definición

Especifica la convención de llamada necesaria para llamar a métodos implementados en código no administrado.Specifies the calling convention required to call methods implemented in unmanaged code.

public enum class CallingConvention
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum CallingConvention
type CallingConvention = 
Public Enum CallingConvention
Herencia
CallingConventionCallingConventionCallingConventionCallingConvention
Atributos

Campos

Cdecl Cdecl Cdecl Cdecl 2

El llamador limpia la pila.The caller cleans the stack. Esto permite llamar a funciones con varargs, que resulta apropiado para métodos que aceptan un número variable de parámetros, como Printf.This enables calling functions with varargs, which makes it appropriate to use for methods that accept a variable number of parameters, such as Printf.

FastCall FastCall FastCall FastCall 5

No se admite esta convención de llamada.This calling convention is not supported.

StdCall StdCall StdCall StdCall 3

El destinatario de la llamada limpia la pila.The callee cleans the stack. Esta es la convención predeterminada para la llamada a funciones no administradas con invocación de plataforma.This is the default convention for calling unmanaged functions with platform invoke.

ThisCall ThisCall ThisCall ThisCall 4

El primer parámetro es el puntero this y se almacena en ECX de registro.The first parameter is the this pointer and is stored in register ECX. Los demás parámetros se insertan en la pila.Other parameters are pushed on the stack. Esta convención de llamada se utiliza para llamar a métodos en clases exportadas desde un archivo DLL no administrado.This calling convention is used to call methods on classes exported from an unmanaged DLL.

Winapi Winapi Winapi Winapi 1

Este miembro no es una convención de llamada en realidad, sino que utiliza la convención de llamada de plataforma predeterminada.This member is not actually a calling convention, but instead uses the default platform calling convention. Por ejemplo, en Windows la convención de llamada predeterminada es StdCall y en Windows CE.NET es Cdecl.For example, on Windows the default is StdCall and on Windows CE.NET it is Cdecl.

Ejemplos

En el ejemplo siguiente se muestra cómo aplicar el Cdecl convención de llamada, que se debe usar porque se limpia la pila del llamador.The following example demonstrates how to apply the Cdecl calling convention, which you must use because the stack is cleaned up by the caller.

using namespace System;
using namespace System::Runtime::InteropServices;
public ref class LibWrap
{
public:

   // CallingConvention.Cdecl must be used since the stack is 
   // cleaned up by the caller.
   // int printf( const char *format [, argument]... )

   [DllImport("msvcrt.dll",CharSet=CharSet::Unicode, CallingConvention=CallingConvention::Cdecl)]
   static int printf( String^ format, int i, double d );

   [DllImport("msvcrt.dll",CharSet=CharSet::Unicode, CallingConvention=CallingConvention::Cdecl)]
   static int printf( String^ format, int i, String^ s );
};

int main()
{
   LibWrap::printf( "\nPrint params: %i %f", 99, 99.99 );
   LibWrap::printf( "\nPrint params: %i %s", 99, "abcd" );
}

using System;
using System.Runtime.InteropServices;

internal static class NativeMethods
{
    // C# doesn't support varargs so all arguments must be explicitly defined.
    // CallingConvention.Cdecl must be used since the stack is 
    // cleaned up by the caller.

    // int printf( const char *format [, argument]... )

    [DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    internal static extern int printf(String format, int i, double d);

    [DllImport("msvcrt.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
    internal static extern int printf(String format, int i, String s);
}

public class App
{
    public static void Main()
    {
        NativeMethods.printf("\nPrint params: %i %f", 99, 99.99);
        NativeMethods.printf("\nPrint params: %i %s", 99, "abcd");
    }
}
Imports System
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices

Friend Class LibWrap
    ' Visual Basic does not support varargs, so all arguments must be 
    ' explicitly defined. CallingConvention.Cdecl must be used since the stack 
    ' is cleaned up by the caller. 
    ' int printf( const char *format [, argument]... )

    <DllImport("msvcrt.dll", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl)>
    Friend Overloads Shared Function printf(
        ByVal format As String, ByVal i As Integer, ByVal d As Double) As Integer
    End Function

    <DllImport("msvcrt.dll", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl)>
    Friend Overloads Shared Function printf(
        ByVal format As String, ByVal i As Integer, ByVal s As String) As Integer
    End Function
End Class 'LibWrap

Public Class App
    Public Shared Sub Main()
        LibWrap.printf(ControlChars.CrLf + "Print params: %i %f", 99, 99.99)
        LibWrap.printf(ControlChars.CrLf + "Print params: %i %s", 99, "abcd")
    End Sub 'Main
End Class 'App

Comentarios

Use siempre la CallingConvention enumeración en lugar de CALLCONV enumeración para especificar una convención de llamada en código administrado.Always use the CallingConvention enumeration rather than the CALLCONV enumeration to specify a calling convention in managed code. Este último existe solo para las definiciones COM.The latter exists only for the sake of COM definitions. El CallingConvention enumeración la utiliza DllImportAttribute y varias clases de System.Reflection.Emit dinámicamente emitir las firmas de invocación de plataforma.The CallingConvention enumeration is used by DllImportAttribute and several classes in System.Reflection.Emit to dynamically emit platform invoke signatures.

Se aplica a

Consulte también: