CallingConvention Enum
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee geeft u de aanroepconventie op die is vereist voor het aanroepen van methoden die zijn geïmplementeerd in niet-beheerde code.
public enum class CallingConvention
public enum CallingConvention
[System.Serializable]
public enum CallingConvention
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum CallingConvention
type CallingConvention =
[<System.Serializable>]
type CallingConvention =
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CallingConvention =
Public Enum CallingConvention
- Overname
- Kenmerken
Velden
| Name | Waarde | Description |
|---|---|---|
| Winapi | 1 | Dit lid is geen oproepconventie, maar gebruikt in plaats daarvan de standaardconventie voor platformgesprekken. |
| Cdecl | 2 | De aanroeper schoont de stapel. Hierdoor kunnen functies worden aangeroepen met |
| StdCall | 3 | De aangeroepene schoont de stapel. |
| ThisCall | 4 | De eerste parameter is de |
| FastCall | 5 | Deze oproepconventie wordt niet ondersteund. |
Voorbeelden
In het volgende voorbeeld ziet u hoe u de Cdecl oproepconventie toepast, die u moet gebruiken omdat de stack door de beller wordt opgeschoond.
using namespace System;
using namespace System::Runtime::InteropServices;
private ref class NativeMethods
{
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()
{
NativeMethods::printf("\nPrint params: %i %f", 99, 99.99);
NativeMethods::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.Runtime.InteropServices
Friend Class NativeMethods
' 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
Public Class App
Public Shared Sub Main()
NativeMethods.printf(ControlChars.CrLf + "Print params: %i %f", 99, 99.99)
NativeMethods.printf(ControlChars.CrLf + "Print params: %i %s", 99, "abcd")
End Sub
End Class
Opmerkingen
Gebruik altijd de CallingConvention opsomming in plaats van de CALLCONV opsomming om een aanroepconventie in beheerde code op te geven. Deze laatste bestaat alleen in het belang van COM-definities. De CallingConvention opsomming wordt gebruikt door DllImportAttribute en verschillende klassen in System.Reflection.Emit om dynamisch platform-aanroepende handtekeningen te verzenden.