How do non-static callbacks work from native code?

It is a little strange to ask this question because I have a code that seems like it should not work, but it is, and although I am not complaining, I would like to confirm why? Lol

It’s just that I have a C ++ native DLL (CLR / managed support is not supported at all) that performs a callback from C # code. The native side stores the stdcall callback function, which is provided by the C # side. I always thought that the callback method (in C #) should be static, but non-static and BOTH lambda expressions work JUST FINE !? How does the "this" pointer marshal from native code? I always thought that native code only stores function pointers without an instance?

Now I found an article in which some guy chose the IL code for the “bridge” between the built-in and non-static managed callbacks. I also noticed this discounted method: "Marshal.GetUnmanagedThunkForManagedMethodPtr ()". This method is no longer supported, and I assume it is inline?

Summary of the issue:

  • Is thunking now built into .NET by issuing IL code? If so, in which version of .NET was this supported radically?

  • Is implicit "thunking" also supported in Mono?

  • When an IL is emitted for managed callbacks, what happens when the instance referenced by thunk is deleted? Is the IL removed or can it lead to a memory leak, so to speak?

Thank.

+5
source share
2

thunking .NET IL? , .NET ?

IL, thunk, - , .NET, this, , tail .NET.

"thunking" Mono?

" p/invoke", Mono.

IL , , , thunk?

, , . , , .

+2

interop . (no this), ( this). #, . .. , this (, ).

, (, ..), , , , .

+1

All Articles