CallingConvention 列挙体
アセンブリ: mscorlib (mscorlib.dll 内)
構文
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Enumeration CallingConvention
メンバ名 | 説明 | |
---|---|---|
Cdecl | 呼び出し元がスタックを消去します。これを使用すると、varargs で関数を呼び出すことができます。Printf など、受け取るパラメータの数が可変のメソッドで使用します。 | |
FastCall | この呼び出し規約はサポートされていません。 | |
StdCall | 呼び出し先がスタックを消去します。これは、プラットフォーム呼び出しでアンマネージ関数を呼び出すための既定の規約です。 | |
ThisCall | 最初のパラメータは this ポインタで、レジスタ ECX に格納されます。その他のパラメータは、スタックにプッシュされます。この呼び出し規約は、アンマネージ DLL からエクスポートしたクラスのメソッドを呼び出すために使用します。 | |
Winapi | このメンバは実際には呼び出し規約ではありません。代わりに、既定のプラットフォーム呼び出し規約を使用します。たとえば、Windows では StdCall、Windows CE .NET では Cdecl が既定値になります。 |
マネージ コードで呼び出し規約を指定するときは、CALLCONV 列挙体ではなく、必ず CallingConvention 列挙体を使用してください。後者は、COM 定義のためだけに存在します。CallingConvention 列挙体は、プラットフォーム呼び出しシグネチャを動的に出力するために、DllImportAttribute および System.Reflection.Emit のクラスの一部で使用されます。
Cdecl 呼び出し規約を適用する例を次に示します。呼び出し元によってスタックはクリーンアップされるため、これは必ず使用する必要があります。
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
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"); } }
using namespace System; using namespace System::Runtime::InteropServices; public ref class LibWrap { public: // 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)] 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 ); }; int main() { LibWrap::printf( "\nPrint params: %i %f", 99, 99.99 ); LibWrap::printf( "\nPrint params: %i %s", 99, "abcd" ); }
import System.*; import System.Runtime.InteropServices.*; public class LibWrap { // VJ# 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]... ) /** @attribute DllImport("msvcrt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl) */ public static native int printf(String format, int i, double d); /** @attribute DllImport("msvcrt.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl) */ public static native int printf(String format, int i, String s); } //LibWrap public class App { public static void main(String[] args) { LibWrap.printf("\nPrint params: %i %f", 99, 99.99); LibWrap.printf("\nPrint params: %i %s", 99, "abcd"); } //main } //App
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
呼出規約
(calling convention から転送)
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2020/11/24 14:20 UTC 版)
呼出規約(よびだしきやく)ないし呼出慣例(よびだしかんれい)(英: calling convention)は、コンピュータの命令セットアーキテクチャごとに取り決められるABIの一部で、サブルーチンが呼出される際に従わねばならない制限などの標準である。名前修飾について、データを渡す「実引数」、戻るべきアドレスである「リターンアドレス」、データを戻す「返戻値」などを、スタックなどに対してどのように格納するのか、また各レジスタを、呼び出し側とサブルーチンのどちらの側が保存するか、等といった取決めの集まりである。言語が同じでも、分割コンパイルされリンカでリンクされる相互のプロシージャ間では、呼出し呼出されるならば同一の呼出規約に従っていなければならない。一方で、違う言語の間でも、同一の呼出規約を経由して相互にプロシージャを呼出すこともできる。
- ^ ボーランド __fastcall 呼出規約では、残りの引数は Pascal 呼出規約 と同様に左から右の順にスタックに積まれる。“変数修飾子 - RAD Studio XE2”. Delphi® XE2 および C++Builder® XE2 オンライン ヘルプ. Embarcadero Technologies, Inc. (2012年4月30日). 2013年1月22日閲覧。
- calling conventionのページへのリンク