Is there a way to host the .NET CLR runtime and register MethodImplOptions.InternalCall functions? (This is not a topic about P/Invoke)
Asked
Active
Viewed 1,033 times
2 Answers
3
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
- 19,370
- 5
- 54
- 56
-
Is the actual API different from the Shared Source version? – jameszhao00 Aug 23 '09 at 07:57
-
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 Aug 23 '09 at 08:03
-
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 Aug 23 '09 at 08:26
-
2FWIW, 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 Aug 23 '09 at 10:31
-
@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 Aug 23 '09 at 16:51
-
@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 Aug 24 '09 at 06:43
0
IMetaDataImport
is your best bet, but can't really vouch for that. This seems like a specific task for C++/CLI.

arul
- 13,998
- 1
- 57
- 77
-
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 Aug 23 '09 at 06:36
-
InternalCall is below the level of CLI, so C++/CLI. jameszhao's question is very specific about what he wants. – Anton Tykhyy Aug 23 '09 at 07:45