tags:

views:

162

answers:

2

Is there a way to host the .NET CLR runtime and register MethodImplOptions.InternalCall functions? (This is not a topic about P/Invoke)

A: 

IMetaDataImport is your best bet, but can't really vouch for that. This seems like a specific task for C++/CLI.

arul
Way off the mark, -1
Anton Tykhyy
What exactly is "way off the mark" here? If there's no way to make InternalCall work using the COM api, P/Invoke is not an option, then C++/CLI is the best(only?) way to go managed->unmanaged.
arul
InternalCall is below the level of CLI, so C++/CLI. jameszhao's question is very specific about what he wants.
Anton Tykhyy
+3  A: 

SSCLI code (specifically clr\src\vm\ecall.cpp) suggests that there is no way to register InternalCall methods, because the crucial gECClasses table is hardcoded.

Anton Tykhyy
Is the actual API different from the Shared Source version?
jameszhao00
They sure are, but how?.. I can only suggest firing up your IDA and — public symbols in one hand, SSCLI code in the other — diving into `mscorwks.dll`.
Anton Tykhyy
I've seen a number of people ask this question on forums - they either want to call something in a C++ DLL and think this might be the way to do it, or else they never say what they want to do. The answer either way is "No". Out of interest, why are you wanting to do this?
Daniel Earwicker
FWIW, I've debugged into mscorwks.dll at the assembler level to fix issues with the .NET loader and investigate behaviour of `tail. call`, and can confirm in both cases that there was an exact correspondence between SSCLI and the actual machine code. From what I've seen, large chunks of the SSCLI are common with the CLR, and only sensitive things like GC and codegen are significantly different, with other things left out.
Barry Kelly
@Earwicker. I need to avoid the marshaling cost of P/Invok. In this case C++/CLI is probably the way I'll go. Plus I was wondering if I can create some additional MSIL functionality in the VM.
jameszhao00
@James: if so, I would separate the performance-critical code which needs to avoid p/invoke into an unmanaged library and write it in C/C++. Or indeed use C++/CLI. This should be much, much easier and much more portable.
Anton Tykhyy