I have reviewed ECMA 335 and I have only found a reference to the .export
keyword which seems promising but has very little documentation. I have found similar questions on StackOverflow with respect to doing this in C#. However, none of that has lead me anywhere useful so far.
The bottom line is: I have a CIL DLL and I want to invoke some of its static methods from a native C++ application.
In newer versions of ILAsm, you can simply do:
.method public static void Foo ()
{
.export [1]
// code ...
}
This exports Foo at index 1 in the export table. Export ordinals should be unique and sequential.
In older versions, you'd have to do:
.data vt = int32 (0) [n]
.vtfixup [n] int32 fromunmanaged at vt
.method public static void Foo ()
{
.vtentry 1:1
.export [1]
// code ...
}
(Where 'n' is the amount of exports you want.)
The .vtentry
indicates which vtable:slot to store the method in. (Table IDs are sequential, and therefore depend on declaration order.)
Newer ILAsms do all this work for you, provided that you don't use the export table for anything else.
Do note that all of this is very unportable.