CallingConvention 열거형

정의

비관리 코드에서 구현된 메서드를 호출하는 데 필요한 호출 규칙을 지정합니다.

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
상속
CallingConvention
특성

필드

Cdecl 2

호출자가 스택을 정리합니다. varargs를 사용하여 함수를 호출할 수 있으므로 Printf와 같은 가변 개수의 매개 변수를 허용하는 메서드에 사용하기에 적합합니다.

FastCall 5

이 호출 규칙이 지원되지 않습니다.

StdCall 3

호출 수신자가 스택을 정리합니다.

ThisCall 4

첫 번째 매개 변수는 this 포인터이며 레지스터 ECX에 저장됩니다. 다른 매개 변수는 스택에 푸시됩니다. 이 호출 규칙은 관리되지 않는 DLL에서 내보낸 클래스의 메서드를 호출하는 데 사용됩니다.

Winapi 1

이 멤버는 실제로 호출 규칙이 아니라 기본 플랫폼 호출 규칙을 사용합니다.

예제

다음 예제에서는 호출자가 스택을 Cdecl 정리하므로 사용해야 하는 호출 규칙을 적용하는 방법을 보여 줍니다.

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

설명

항상 열거형이 아닌 열거형을 CALLCONV 사용하여 CallingConvention 관리 코드에서 호출 규칙을 지정합니다. 후자는 COM 정의를 위해서만 존재합니다. CallingConvention 열거형은 및 의 여러 클래스에서 System.Reflection.Emit 플랫폼 호출 서명을 동적으로 내보내는 데 사용됩니다DllImportAttribute.

적용 대상

추가 정보