we are currently digging through some really old C++/CLI-Code (Old Syntax .NET Beta) and were a bit surprised to see something like this:
System::String ^sou
I believe it is because the compiler is turning it into this IL:
call vararg int32 modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) printf(int8 modopt([mscorlib]System.Runtime.CompilerServices.IsSignUnspecifiedByte) modopt([mscorlib]System.Runtime.CompilerServices.IsConst)*, ..., string)
Which ends up as a pinvoke call to printf
, so the runtime is being a little sneaky by marshalling it for you. You are still in a managed runtime, and the runtime will provide marhsalling as a service when it's needed.
Some notes:
It seems that clr!GenericPInvokeCalliHelper
is doing this lifting on the x86 .NET 4 Workstation CLR.
the following doesn't work
That's because that is straight C++. It has no chance to go through marshalling because it isn't needed.