エントリ ポイントの呼び出し規約を示します。
Public CallingConvention As CallingConvention
[C#]
public CallingConvention CallingConvention;
[C++]
public: CallingConvention CallingConvention;
[JScript]
public var CallingConvention : CallingConvention;
解説
このフィールドを、 CallingConvention 列挙体メンバの 1 つに設定します。 CallingConvention フィールドの既定値は WinAPI です。この場合の既定の呼び出し規約は StdCall です。
詳細については、MSDN ライブラリの呼び出し規約を参照してください。
使用例
[Visual Basic, C#] Visual Basic の開発者は、マネージ コードで DLL 関数を定義する際、 Declare ステートメントの代わりに、 DllImportAttribute を使用することがあります。 CallingConvention フィールドの設定は、このような事例の 1 つです。
Imports System
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Public Class LibWrap
' 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", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
format As String, i As Integer, d As Double) As Integer
End Function
<DllImport("msvcrt.dll", CallingConvention := CallingConvention.Cdecl)> _
Overloads Shared Function printf ( _
format As String, i As Integer, s As String) As Integer
End Function
End Class 'LibWrap
Public Class App
Public Shared Sub Main()
LibWrap.printf(ControlChars.CrLf + "Print params: %i %f", 99,
99.99)
LibWrap.printf(ControlChars.CrLf + "Print params: %i %s", 99, _
"abcd")
End Sub 'Main
End Class 'App
[C#]
using System;
using System.Runtime.InteropServices;
public class LibWrap
{
// 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)]
public static extern int printf(String format, int i, double d);
[DllImport("msvcrt.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
public static extern int printf(String format, int i, String s);
}
public class App
{
public static void Main()
{
LibWrap.printf("\nPrint params: %i %f", 99, 99.99);
LibWrap.printf("\nPrint params: %i %s", 99, "abcd");
}
}
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
DllImportAttribute クラス | DllImportAttribute メンバ | System.Runtime.InteropServices 名前空間 | CallingConvention