Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#16 Make DLLs compiled by IKVM accessible from unmanaged Code

closed
nobody
None
5
2011-11-15
2010-10-18
Michael Mess
No

When compiling DLLs with IKVM they contain only managed code and are unusable from unmanaged code (C/C++).

I managed to create a DLL which is accessible by compiling with IKVM, then using ildasm to disassemble, modify the code and recompile with ildasm.
I have attached two files, the original file (IKVM output, disassembled with ildasm) and the modified code which gives code accessible from unmanaged code.

Is it possible to add the unmanaged exports by ikvmc directly for each method which contains an annotation like @DllExport ?

Discussion

  • Michael Mess
    Michael Mess
    2010-10-18

     Modified code which generates a DLL with exported symbols.
    
     
  • Michael Mess
    Michael Mess
    2010-10-18

    Current Workaround:

    To disassemble DLL code compiled with IKVM, you can type:
    ildasm.exe /OUT:MyDLL-disassembled.il MyDll.dll

    Then modify the code as follows: (We add n methods):

    * Change .corflags to 0x00000002 ( Win32BitsRequired )
    * Add .vtfixup[n] int32 fromunmanaged at virtualTable
    * Add .data virtualTable = int32[n]

    Then at the beginning of each function add:

    .vtentry 1 : i // Replace i with the function count, 1...n
    .export [i] as functionName@0 // Replace i as above, functionName is the
    name of the function, @0 are the bytes reserved for the arguments,
    __std_call function decoration used for Windows.

    To reassemble the modified code to a DLL, you can type
    ilasm.exe /OUT:MyDLL-modified.dll MyDLL-disassembled.il /DLL

    If everything goes well, you will have a new DLL with exported symbols
    which can be loaded by native C/C++ applications which do not understand
    managed code.

    You can verify the exported symbols in the resulting executable with tools
    like DependencyWalker.

     
  • Michael Mess
    Michael Mess
    2010-10-18

    Original code (IKVM output, disassembled with ildasm)

     
    Attachments
  • Jörg Thönnes
    Jörg Thönnes
    2011-11-11

    Hi Jeroen,

    can we expect any progress here? Michael has already provided a useful
    workaround which could be the base for a (simple) change.

    Thanks, Jörg

     
  • Hi Jörg,

    I must admit I kind of forgot about this feature request.

    I already did the hard part (build support for unmanaged exports in IKVM.Reflection) so it would not be very difficult to add this, but on the other hand it is not exactly a feature that gets requested often.

    I'll think about it.

    Regards,
    Jeroen

     
  • Jörg Thönnes
    Jörg Thönnes
    2011-11-11

    Hi Jeroen,

    thanks for the prompt response. It is great to hear that you already did the "hard part". There is s a lot of activity in the project which is good.

    Looking forward to a solution from you.

    Thanks, Jörg

     
  • Hi Jörg,

    I've implemented the feature and committed the code to cvs trunk. It won't be in the upcoming 7.0 release though.

    It will be in the next development snapshot (I will blog about that and also document how it works at that time).

    Regards,
    Jeroen

     
    • status: open --> closed