Freigeben über


CallingConvention-Enumeration

Gibt die Aufrufkonvention für das Aufrufen von Methoden an, die in nicht verwaltetem Code implementiert sind.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration CallingConvention
'Usage
Dim instance As CallingConvention
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum CallingConvention
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class CallingConvention
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum CallingConvention
SerializableAttribute 
ComVisibleAttribute(true) 
public enum CallingConvention

Member

  Membername Beschreibung
Cdecl Der Aufrufer entleert den Stapel. Dies aktiviert Aufruffunktionen mit varargs, wodurch die Verwendung für Methoden ermöglicht wird, die eine variable Anzahl von Parametern akzeptieren, beispielsweise Printf
FastCall Diese Aufruffunktion wird nicht unterstützt. 
StdCall Der Aufgerufene entleert den Stapel. Dies ist die Standardkonvention für das Aufrufen nicht verwalteter Funktionen mit Plattformaufruf. 
ThisCall Der erste Parameter ist der this-Zeiger, der im Register ECX gespeichert wird. Weitere Parameter werden in den Stapel verschoben. Diese Aufrufkonvention wird zum Aufrufen von Methoden für Klassen verwendet, die aus einer nicht verwalteten DLL exportiert wurden. 
Unterstützt von .NET Compact Framework Winapi Dieser Member stellt keine tatsächliche Aufrufkonvention dar, sondern verwendet die Standardkonvention für Plattformaufrufe. Unter Windows ist der Standard beispielsweise StdCall, und unter Windows CE.NET ist der Standard Cdecl

Hinweise

Verwenden Sie immer die CallingConvention-Enumeration anstelle der CALLCONV-Enumeration, um eine Aufrufkonvention in verwaltetem Code anzugeben. Letztere wird ausschließlich für COM-Definitionen verwendet. Die CallingConvention-Enumeration wird von DllImportAttribute und verschiedenen Klassen in System.Reflection.Emit verwendet, um dynamisch Plattformaufrufsignaturen auszugeben.

Beispiel

Das folgende Beispiel veranschaulicht, wie die Cdecl-Aufrufkonvention angewendet wird, die verwendet werden muss, weil der Stapel vom Aufrufer bereinigt wird.

Imports System
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices

Public 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", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
    format As String, i As Integer, d As Double) As Integer
End Function

<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
    format As String, i As Integer, 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
using System;
using System.Runtime.InteropServices;

public class LibWrap
{
// 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.Ansi, CallingConvention=CallingConvention.Cdecl)]
public static extern int printf(String format, int i, double d); 

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

public class App
{
    public static void Main()
    {
        LibWrap.printf("\nPrint params: %i %f", 99, 99.99);
        LibWrap.printf("\nPrint params: %i %s", 99, "abcd");
    }
}
using namespace System;
using namespace System::Runtime::InteropServices;
public ref class LibWrap
{
public:

   // 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::Ansi,CallingConvention=CallingConvention::Cdecl)]
   static int printf( String^ format, int i, double d );

   [DllImport("msvcrt.dll",CharSet=CharSet::Ansi,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" );
}
import System.*;
import System.Runtime.InteropServices.*;

public class LibWrap
{
    // VJ# 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]... )
    /** @attribute DllImport("msvcrt.dll", CharSet = CharSet.Ansi, 
        CallingConvention = CallingConvention.Cdecl)
     */
    public static native int printf(String format, int i, double d);

    /** @attribute DllImport("msvcrt.dll", CharSet = CharSet.Ansi, 
        CallingConvention = CallingConvention.Cdecl)
     */
    public static native int printf(String format, int i, String s);
} //LibWrap

public class App
{
    public static void main(String[] args)
    {
        LibWrap.printf("\nPrint params: %i %f", 99, 99.99);
        LibWrap.printf("\nPrint params: %i %s", 99, "abcd");
    } //main
} //App

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

System.Runtime.InteropServices-Namespace
DllImportAttribute
System.Reflection.Emit