[Mono-devel-list] calli opcode

Jonathan Pryor jonpryor at vt.edu
Fri Jul 22 07:24:34 EDT 2005

On Thu, 2005-07-21 at 22:26 -0600, Peter Dennis Bartok wrote:
> Jonathan, if you read through the DnD OLE code in the MWF win32 driver, you 
> will see that I'm doing exactly that.

This works because you're invoking a COM method, which has a
well-defined ABI (stdcall calling convention, all arguments passed on
the stack and NOT in registers, etc.).

This will NOT work for any arbitrary C++ method because each compiler
has a different calling convention (register usage, parameter order on
the stack, how to deal with exceptions).

> -----Original Message-----
> From: "Jonathan S. Chambers" <Jonathan.Chambers at ansys.com>
>      Perhaps a crazy question, but I'll ask anyway. Is it possible to call 
> an unmanaged class's member function using the calli opcode with the 
> thiscall calling convention, i.e. can I call a (virtual) method on a C++ 
> object from managed code by emitting the necessary il (via a dynamic 
> method)?

This is unlikely to work as well, because the C++ ABI is not
standardized (except on Itanium).  Consequently, whether a register is
used for the `this` pointer (and which register) is not
implementation-dependent, as well as whether a virtual function table is
used (and it's location relative to the start of the object).
Portability is...difficult. :-)

If you have control over both mono and a C++ compiler, or you're
programming against a stable ABI (COM), this technique could be useful.
Otherwise, it's looking difficult.

 - Jon

More information about the Mono-devel-list mailing list