calling conventionとは? わかりやすく解説

CallingConvention 列挙体

アンマネージ コード実装されたメソッド呼び出すために必要な呼び出し規約指定します

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration CallingConvention
Dim instance As CallingConvention
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum CallingConvention
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class CallingConvention
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum CallingConvention
SerializableAttribute 
ComVisibleAttribute(true) 
public enum CallingConvention
メンバメンバ
解説解説

マネージ コード呼び出し規約指定するときは、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Runtime.InteropServices 名前空間
DllImportAttribute
System.Reflection.Emit

呼出規約

(calling convention から転送)

出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2020/11/24 14:20 UTC 版)

呼出規約(よびだしきやく)ないし呼出慣例(よびだしかんれい)(: calling convention)は、コンピュータ命令セットアーキテクチャごとに取り決められるABIの一部で、サブルーチンが呼出される際に従わねばならない制限などの標準である。名前修飾について、データを渡す「実引数」、戻るべきアドレスである「リターンアドレス」、データを戻す「返戻値」などを、スタックなどに対してどのように格納するのか、また各レジスタを、呼び出し側とサブルーチンのどちらの側が保存するか、等といった取決めの集まりである。言語が同じでも、分割コンパイルされリンカでリンクされる相互のプロシージャ間では、呼出し呼出されるならば同一の呼出規約に従っていなければならない。一方で、違う言語の間でも、同一の呼出規約を経由して相互にプロシージャを呼出すこともできる。


  1. ^ ボーランド __fastcall 呼出規約では、残りの引数は Pascal 呼出規約 と同様にからの順にスタックに積まれる。変数修飾子 - RAD Studio XE2”. Delphi® XE2 および C++Builder® XE2 オンライン ヘルプ. Embarcadero Technologies, Inc. (2012年4月30日). 2013年1月22日閲覧。


「呼出規約」の続きの解説一覧


英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「calling convention」の関連用語

calling conventionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



calling conventionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.
ウィキペディアウィキペディア
All text is available under the terms of the GNU Free Documentation License.
この記事は、ウィキペディアの呼出規約 (改訂履歴)の記事を複製、再配布したものにあたり、GNU Free Documentation Licenseというライセンスの下で提供されています。 Weblio辞書に掲載されているウィキペディアの記事も、全てGNU Free Documentation Licenseの元に提供されております。

©2024 GRAS Group, Inc.RSS