[Ironruby-core] Leveraging StdLib.Win32API class
James Leskovar
lists at ruby-forum.com
Fri Dec 4 21:31:59 EST 2009
Hi Tomas,
I've been playing around with DynamicMethod and generating IL at
runtime, with varying levels of success. Currently I'm using
DynamicMethod to generate the IL to load arguments, load function
address, calli and ret. My script gets access to the DynamicMethod
object, which gets passed onto a helper CLR method along with arguments
for some basic marshalling, before being passed onto
DynamicMethod.Invoke.
I've noticed though that calling .Invoke() in this manner is a magnitude
times slower than using the equivalant Win32API code. I figure I'm meant
to use CreateDelegate instead of Invoke, though I'm not sure how this is
meant to work since CreateDelegate expects a delegate type, whose
signature isn't known until runtime.
Regards,
James
Tomas Matousek wrote:
> I wouldn't recommend using Win32API. It's not well designed interop
> library.
>
> What you need is calli IL instruction. It takes a pointer to a function
> and arguments and calls the function. C# doesn't support this so you
> need some helpers. You can either emit them at run-time and call them
> via delegates (that's what our implementation of Win32API does), or you
> can write them in IL, if you know the signatures you need, compile them
> to an assembly (ilasm ILHelpers.il /dll /out=ILHelpers.dll) and use the
> assembly directly from Ruby (see attached file).
>
> Tomas
--
Posted via http://www.ruby-forum.com/.
More information about the Ironruby-core
mailing list