ILGenerator.EmitCalliとは? わかりやすく解説

ILGenerator.EmitCalli メソッド (OpCode, CallingConvention, Type, Type[])

間接的な呼び出しに対してアンマネージ呼び出し規約指定してMSIL (Microsoft Intermediate Language) ストリームに Calli 命令書き込みます

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

Public Overridable Sub EmitCalli
 ( _
    opcode As OpCode, _
    unmanagedCallConv As CallingConvention, _
    returnType As Type, _
    parameterTypes As Type() _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim unmanagedCallConv As CallingConvention
Dim returnType As Type
Dim parameterTypes As Type()

instance.EmitCalli(opcode, unmanagedCallConv, returnType, parameterTypes)
public virtual void EmitCalli (
    OpCode opcode,
    CallingConvention unmanagedCallConv,
    Type returnType,
    Type[] parameterTypes
)
public:
virtual void EmitCalli (
    OpCode opcode, 
    CallingConvention unmanagedCallConv, 
    Type^ returnType, 
    array<Type^>^ parameterTypes
)
public void EmitCalli (
    OpCode opcode, 
    CallingConvention unmanagedCallConv, 
    Type returnType, 
    Type[] parameterTypes
)
public function EmitCalli (
    opcode : OpCode, 
    unmanagedCallConv : CallingConvention, 
    returnType : Type, 
    parameterTypes : Type[]
)

パラメータ

opcode

ストリーム書き込む MSIL 命令

unmanagedCallConv

使用するアンマネージ呼び出し規約

returnType

結果Type

parameterTypes

命令必要な引数の型。

解説解説
使用例使用例

次のコード例は、EmitCalli メソッド使用して動的なクラス外部にあるアンマネージ型のメソッド呼び出す方法示してます。

      Dim myMthdBuilder As MethodBuilder = myTypeBuilder.DefineMethod("MyMethod",
 _
                    MethodAttributes.Public, _
                    returnType, mthdParamTypes)
  
      ' We will assume that an external unmanaged type "LegacyNumber"
 has been loaded, and
      ' that it has a method "ToString" which returns a string.

      Dim unmanagedMthdMI As MethodInfo = Type.GetType("LegacyNumber").GetMethod("ToString")
      Dim myMthdIL As ILGenerator = myMthdBuilder.GetILGenerator()
  
      ' Code to emit various IL opcodes here ...
      ' Load a reference to the specific object instance onto the stack.

      myMthdIL.Emit(OpCodes.Ldc_I4, addrOfLegacyNumberObject)
      myMthdIL.Emit(OpCodes.Ldobj, Type.GetType("LegacyNumber"))
  
      ' Make the call to the unmanaged type method, telling it that
 the method is
      ' the member of a specific instance, to expect a string 
      ' as a return value, and that there are no explicit parameters.

      myMthdIL.EmitCalli(OpCodes.Calli, System.Runtime.InteropServices.CallingConvention.ThisCall,
 _
                  GetType(String), New
 Type() {})

' More IL code emission here ...
MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("MyMethod", 
                  MethodAttributes.Public,
                  returnType, mthdParamTypes);
                            
// We will assume that an external unmanaged type "LegacyNumber"
 has been loaded, and
// that it has a method "ToString" which returns a string.
 
MethodInfo unmanagedMthdMI = Type.GetType("LegacyNumber").GetMethod("ToString");
ILGenerator myMthdIL = myMthdBuilder.GetILGenerator();

// Code to emit various IL opcodes here ...

// Load a reference to the specific object instance onto the stack.

myMthdIL.Emit(OpCodes.Ldc_I4, addrOfLegacyNumberObject);
myMthdIL.Emit(OpCodes.Ldobj, Type.GetType("LegacyNumber"));

// Make the call to the unmanaged type method, telling it that the method
 is
// the member of a specific instance, to expect a string 
// as a return value, and that there are no explicit parameters.
myMthdIL.EmitCalli(OpCodes.Calli, 
           System.Runtime.InteropServices.CallingConvention.ThisCall,
               typeof(string),
           new Type[] {});

// More IL code emission here ...

MethodBuilder^ myMthdBuilder = myTypeBuilder->DefineMethod( "MyMethod"
,
                               MethodAttributes::Public,
                               returnType, mthdParamTypes );

// We will assume that an external unmanaged type "LegacyNumber"
 has been loaded, and
// that it has a method "ToString" which returns a String.

MethodInfo^ unmanagedMthdMI = Type::GetType( "LegacyNumber" )->GetMethod(
 "ToString" );
ILGenerator^ myMthdIL = myMthdBuilder->GetILGenerator();

// Code to emit various IL opcodes here ...

// Load a reference to the specific Object instance onto the stack.

myMthdIL->Emit( OpCodes::Ldc_I4, addrOfLegacyNumberObject );
myMthdIL->Emit( OpCodes::Ldobj, Type::GetType( "LegacyNumber" ) );

// Make the call to the unmanaged type method, telling it that the method
 is
// the member of a specific instance, to expect a String
// as a return value, and that there are no explicit parameters.
myMthdIL->EmitCalli( OpCodes::Calli,
                     System::Runtime::InteropServices::CallingConvention::ThisCall
,
                     String::typeid,
                     gcnew array<Type^>( 0 ) );

// More IL code emission here ...
MethodBuilder myMthdBuilder = myTypeBuilder.DefineMethod("MyMethod",
    MethodAttributes.Public, returnType, mthdParamTypes);

// We will assume that an external unmanaged type "LegacyNumber"
 
// has been loaded, and that it has a method "ToString" which
 returns
// a string.
MethodInfo unmanagedMthdMI = Type.GetType(
    "LegacyNumber").GetMethod("ToString");
ILGenerator myMthdIL = myMthdBuilder.GetILGenerator();

// Code to emit various IL opcodes here ...
// Load a reference to the specific object instance onto the stack.
myMthdIL.Emit(OpCodes.Ldc_I4, addrOfLegacyNumberObject);
myMthdIL.Emit(OpCodes.Ldobj, Type.GetType("LegacyNumber"));

// Make the call to the unmanaged type method, telling it that the 
// method is the member of a specific instance, to expect a string 
// as a return value, and that there are no explicit parameters.
myMthdIL.EmitCalli(OpCodes.Calli, 
    System.Runtime.InteropServices.CallingConvention.ThisCall, 
    String.class.ToType(), new Type[] {});
// More IL code emission here ...
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.EmitCalli メソッド (OpCode, CallingConventions, Type, Type[], Type[])

間接的な呼び出しに対してマネージ呼び出し規約指定してMSIL (Microsoft Intermediate Language) ストリームに Calli 命令書き込みます

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

Public Overridable Sub EmitCalli
 ( _
    opcode As OpCode, _
    callingConvention As CallingConventions, _
    returnType As Type, _
    parameterTypes As Type(), _
    optionalParameterTypes As Type() _
)
Dim instance As ILGenerator
Dim opcode As OpCode
Dim callingConvention As CallingConventions
Dim returnType As Type
Dim parameterTypes As Type()
Dim optionalParameterTypes As Type()

instance.EmitCalli(opcode, callingConvention, returnType, parameterTypes, optionalParameterTypes)
public virtual void EmitCalli (
    OpCode opcode,
    CallingConventions callingConvention,
    Type returnType,
    Type[] parameterTypes,
    Type[] optionalParameterTypes
)
public:
virtual void EmitCalli (
    OpCode opcode, 
    CallingConventions callingConvention, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    array<Type^>^ optionalParameterTypes
)
public void EmitCalli (
    OpCode opcode, 
    CallingConventions callingConvention, 
    Type returnType, 
    Type[] parameterTypes, 
    Type[] optionalParameterTypes
)
public function EmitCalli (
    opcode : OpCode, 
    callingConvention : CallingConventions, 
    returnType : Type, 
    parameterTypes : Type[], 
    optionalParameterTypes : Type[]
)

パラメータ

opcode

ストリーム書き込む MSIL 命令

callingConvention

使用するマネージ呼び出し規約

returnType

結果Type

parameterTypes

命令必要な引数の型。

optionalParameterTypes

varargs 呼び出し省略可能な引数の型。

例外例外
例外種類条件

InvalidOperationException

optionalParameterTypesnull 参照 (Visual Basic では Nothing) でないにもかかわらずcallingConvention に CallingConventions.VarArgs フラグ含まれていません。

解説解説

Calli 命令ストリーム書き込むには、EmitCalli使用しますEmit使用しないください

optionalParameterTypes省略可能な引数指定する場合callingConventionCallingConventions.VarArgs フラグ含まれている必要があります

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ILGenerator クラス
ILGenerator メンバ
System.Reflection.Emit 名前空間

ILGenerator.EmitCalli メソッド



このページでは「.NET Framework クラス ライブラリ リファレンス」からILGenerator.EmitCalliを検索した結果を表示しています。
Weblioに収録されているすべての辞書からILGenerator.EmitCalliを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からILGenerator.EmitCalli を検索

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

辞書ショートカット

すべての辞書の索引

「ILGenerator.EmitCalli」の関連用語

ILGenerator.EmitCalliのお隣キーワード
検索ランキング

   

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



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

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS