Records passed to unmanaged code!

  • Thread starter Thread starter Atmapuri
  • Start date Start date
A

Atmapuri

Hi!

When records are passed by reference to unmanaged code
do they need to be pinned down explicitely or not?

I must have gone over this a dozen of times, but I am still
not sure about it. I know that records are also just
objects, but maybe CLR treats them differently.

Thanks!
Atmapuri.
 
Atmapuri,

When you make calls to unmanaged code, passing a structure structures by
reference, or a class that is marshaled as a structure, the P/Invoke layer
and COM interop will pin down those objects for the lifetime of the call.
If the COM method or the unmanaged function stores the pointer, then this is
an issue, because you will have to store that structure in unmanaged memory,
and adjust it there (so that the pointer in memory is never moved).

Hope this helps.
 
Hi!

Thanks. Perfect.
Atmapuri.

Nicholas Paldino said:
Atmapuri,

When you make calls to unmanaged code, passing a structure structures by
reference, or a class that is marshaled as a structure, the P/Invoke layer
and COM interop will pin down those objects for the lifetime of the call.
If the COM method or the unmanaged function stores the pointer, then this is
an issue, because you will have to store that structure in unmanaged memory,
and adjust it there (so that the pointer in memory is never moved).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Atmapuri said:
Hi!

When records are passed by reference to unmanaged code
do they need to be pinned down explicitely or not?

I must have gone over this a dozen of times, but I am still
not sure about it. I know that records are also just
objects, but maybe CLR treats them differently.

Thanks!
Atmapuri.
 
Back
Top