How do you export a method to a CIL DLL so that your own program can call it?

I reviewed ECMA 335 and I found a link to the .export keyword, which seems promising but has very little documentation. I found similar questions in StackOverflow regarding this in C #. However, none of this has led me to any useful so far.

On the bottom line: I have a CIL DLL, and I want to call some of my static methods from my own C ++ application.

+8
cil pinvoke
source share
2 answers

In newer versions of ILAsm, you can simply:

 .method public static void Foo () { .export [1] // code ... } 

This exports Foo to index 1 in the export table. Export ordinals must be unique and consistent.

In older versions you will need:

 .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 export you want.)

.vtentry indicates which vtable: slot to store the in method. (Table identifiers are sequential and therefore depend on the order of declaration.)

New ILAsms do all this for you, provided that you are not using the export table for anything else.

Note that all this is very disproportionate.

+14
source share

You must expose your DLL as com dll. Com does the work of using native.net interop. You cannot run IL code in everything except VM.net.

+1
source share

All Articles