Original Post
Good Morning GameDev, I am not getting much luck on IRC lately, so I figured I would try here, as gamedev is usually fairly responsive. I am using C# and .NET 4.0 (MSVS 2010) I recently ran into the need to pass a managed type THROUGH an unmanaged callback. (EnumThreadWindows in this case). Both the function and its callback work with an IntPtr, and both "endpoints" are in managed code. So basically I need an IntPtr to a managed class (struct actually, although I am fairly positive its the same internally). Since both endpoints are in managed code, I do not believe the intptr even really needs to be valid in an unmanaged context. As a temporary fix I am passing an int in intptr's place, and storing that in an ad-hoc nasty collection. This _IS_ a huge bottleneck and truthfully dispicable code. It needs to go. Hopefully one of you .NET geniuses can help with this one :) Thanks, Richard edit: to further clarify, I am using the following PINVOKE signatures for the enumwindow code
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumThreadWindows(uint dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
public delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);