[Mono-devel-list] .export Directive in IL

Kornél Pál kornelpal at hotmail.com
Thu Jun 30 04:20:52 EDT 2005

> From: Jonathan S. Chambers
> Thanks for the answers. I'm just experimenting with methods to call
> managed code from unmanaged code without using COM interop, i.e. something
> that would work on both .Net and Mono. Any advice would be appreciated.

As the function is exported by the DLL as usual and the PE format is well
documented the exported addresses could be obtained from the PE file if Mono
stores the in the memory as PE and the address of the header can be obtained
form Mono. (I don't know whether it is possible.) But it cannot be used with
standard operating system dependent library handling functions because it is
a PE file that is native only to Windows. As you have seen in your example
IL code COMIMAGE_FLAGS_32BITSREQUIRED is required because pointers are
stored as int32 in the vtable that makes the DLL processor dependent.
Furthermore as you have to obtain the address of PE header from the runtime
your unmanaged code could not be runtime independent.

As a conclusion there is no use to communicate this way with your managed
code regadles it is implemented by Mono.

Windows is the only platform where managed modules can be loaded as native
modules and the operating system loads the runtime for you as well. Thus you
have to load Mono runtime into you process, load the managed module and
execute some code using exported functions of Mono runtime.

But this is not what you want. If you want to make your code runtime
independent you have to execute a managed executable. It can be executed
using the runtime you want. .NET Framework, Mono or Portable.NET. Then you
can use P/Invoke to load and initialized you own or a third party unmanaged
library. To make unmanaged code able to call managed code you can pass some
delegates (marshaled as function pointers) to the initialization function in
the umanaged library for example and then it will be able to call them any
time it wants.


More information about the Mono-devel-list mailing list