Using regular System.Reflection.Emit, I can emit an unmanaged calli with 
the following:

ILGenerator il;
il.EmitCalli(OpCodes.Calli,
    CallingConvention.Winapi,
    typeof(void),
    new Type[] { typeof(int), typeof(string) });

Winapi translates to the default calling convention for the current 
platform (stdcall on Windows, cdecl otherwise) and this works as expected.

I am trying to recreate this call with Cecil:

IlProcessor il;
var site = new CallSite(module.Import(typeof(void))
{
    CallingConvention = MethodCallingConvention.Default
};
site.Parameters.Add(module.Import(typeof(int));
site.Parameters.Add(module.Import(typeof(string));
il.Emit(OpCodes.Calli, site);

But the string now comes out wrong on the unmanaged side.

If I specify MethodCallingConvention.Stdcall, this specific case works 
correctly, but the solution becomes Windows-specific. (Other methods with 
4+ parameters still appear to fail, but this could also be a bug in my 
code.)

If I use Xamarin Studio 4.2.1 to disassemble the dll, I get the following:


ldarg.0
ldarg.1
calli System.Void(System.Int32,System.String)

i.e. the calli signature does not indicate any specific calling convention 
or the fact that it is calling an unmanaged method. I do not know if this 
is a bug in the Xamarin Studio disassembler (isn't it actually using 
Cecil?) or a genuine cause for concern (no signature means managed 
fastcall, which might explain the garbled string, correct?)

I am using the git master from jbevain/cecil (commit 8425de4db6).

Ideas welcome!

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to