DllImportAttribute.CallingConvention DllImportAttribute.CallingConvention DllImportAttribute.CallingConvention DllImportAttribute.CallingConvention Field

定義

エントリ ポイントの呼び出し規約を示します。Indicates the calling convention of an entry point.

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 開発者が使用して、DllImportAttributeの代わりに、Declareステートメントは、マネージ コードで DLL 関数を定義します。In some cases, Visual Basic developers use the DllImportAttribute, instead of the Declare statement, to define a DLL function in managed code. 設定、CallingConventionフィールドは、そのような場合の 1 つです。Setting the CallingConvention field is one of those cases.

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

public ref class LibWrap
{
    // 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()
{
    LibWrap::printf("\nPrint params: %i %f", 99, 99.99);
    LibWrap::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
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列挙型メンバー。You set this field to one of the CallingConvention enumeration members. 既定値、CallingConventionフィールドはWinapi、順番に既定でStdCall規則。The default value for the CallingConvention field is Winapi, which in turn defaults to StdCall convention.

適用対象

こちらもご覧ください