Cannot pass a GCHandle across AppDomains

  • Thread starter Thread starter RobbKirk
  • Start date Start date
R

RobbKirk

Guest
In managed code I have some callback that is called from unmanaged Win32 area. It is the wave recording process.

Prepared PINNED buffers are sent to that unmanaged area and when I try to Free() them with GCHandle.FromIntPtr(hDr.lpData).Free(); I get that message

Cannot pass a GCHandle across AppDomains



What technique should I apply? As I understood CLR will place that unmanaged code automatically in different domain, and this happens only in WinForms App, but it works fine as the Console App.

How to force CLR to keep that callback and the unmanaged code at the same domain?

Lucky I know why I had GPF each time before, thanks to blocking the optimization with [MethodImpl(MethodImplOptions.NoOptimization)]... now I've got understanding why - because of that domain issue.

So, please, tell me how to work around that issue? How to avoid the multi domain structure in my case?



"I = I + 1" .. Isn't it boolshit?

Continue reading...
 
Back
Top