C struct of delegates is clobbered when one is called
I'm passing a struct containing delegates to an native call in a DLL that wants a struct full of function pointers. The values it receives are all valid. However, when execution returns to the native DLL from the managed method (which runs flawlessly), all the members of native struct seem to get clobbered.
What I can't figure out is whether this is because they're all getting garbage collected, or I mixed up the calling conventions somewhere. Here's what happens to the native struct before and after it calls into the managed code:
a struct containing 4 pristine function pointers:
0x00198568
003421ca0x0019856C
003423520x00198570
003423920x00198574
003423d2Afterwards, all 4 members are clobbered, and the word immediately following the struct contains the address of the beginning of the struct.
0x00198568
001984280x0019856C
000000c80x00198570
000000010x00198574
000000000x00198578
00198568In short, the memory containing a C struct with 4 pointers into managed code turns into what looks like something from the stack after one of the function pointers is called. It's worth bringing up the fact that my DLL uses cdecl.
I've tried adding GCHandles to the C# struct, and also to each of the delegates it contains. I've also tried declaring the delegate types used in the struct with the attribute UnmanagedFunctionPointer(CallingConvention.Cdecl). None of which made any difference.
Does anyone have any other ideas?

