DllImportAttribute.CallingConvention 필드

정의

진입점의 호출 규칙을 나타냅니다.

public: System::Runtime::InteropServices::CallingConvention CallingConvention;
public System.Runtime.InteropServices.CallingConvention CallingConvention;
val mutable CallingConvention : System.Runtime.InteropServices.CallingConvention
Public CallingConvention As CallingConvention 

필드 값

예제

경우에 따라 Visual Basic 개발자는 문 대신 Declare 를 사용하여 DllImportAttribute관리 코드에서 DLL 함수를 정의합니다. 필드 설정 CallingConvention 은 이러한 경우 중 하나입니다.

using namespace System;
using namespace System::Runtime::InteropServices;

private ref class NativeMethods
{
    // Managed class methods don'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]...)
public:
    [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);
};

void 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.Ansi,
        CallingConvention = CallingConvention.Cdecl)]
    internal static extern int printf(string format, int i, double d);

    [DllImport("msvcrt.dll", CharSet = CharSet.Ansi,
        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 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)>
    Friend Shared Function printf(format As String, i As Integer, d As Double) As Integer
    End Function
    <DllImport("msvcrt.dll", CharSet:=CharSet.Ansi,
        CallingConvention:=CallingConvention.Cdecl)>
    Friend Shared Function printf(format As String, i As Integer, s As String) As Integer
    End Function
End Class

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

설명

이 필드를 열거형 멤버 중 CallingConvention 하나로 설정합니다. 필드의 CallingConvention 기본값은 이며, 이 값은 WinapiWindows 및 Cdecl 다른 모든 플랫폼에서의 규칙으로 기본값 StdCall 으로 설정됩니다.

적용 대상

추가 정보