ILGenerator::EmitCalli Method (OpCode, CallingConvention, Type^, array<Type^>^)
Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying an unmanaged calling convention for the indirect call.
Assembly: mscorlib (in mscorlib.dll)
public: virtual void EmitCalli( OpCode opcode, CallingConvention unmanagedCallConv, Type^ returnType, array<Type^>^ parameterTypes )
Parameters
- opcode
-
Type:
System.Reflection.Emit::OpCode
The MSIL instruction to be emitted onto the stream. Must be OpCodes::Calli.
- unmanagedCallConv
-
Type:
System.Runtime.InteropServices::CallingConvention
The unmanaged calling convention to be used.
- returnType
-
Type:
System::Type^
The Type of the result.
- parameterTypes
-
Type:
array<System::Type^>^
The types of the required arguments to the instruction.
The following code sample demonstrates the contextual usage of the EmitCalli method to call an unmanaged type method external to the dynamic class.
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 ...
Available since 1.1