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

注釈

マネージド コードで呼び出し規約を CallingConvention 指定するには、 CALLCONV 常に 列挙型ではなく 列挙型を使用します。 後者は、COM 定義のためにのみ存在します。 列挙型はCallingConvention、 および のいくつかのクラスSystem.Reflection.EmitによってDllImportAttribute使用され、プラットフォーム呼び出しシグネチャを動的に出力します。

適用対象

こちらもご覧ください