December 27th, 2010, 06:19 PM
Please help me chase out a SafeArrayTypeMismatchException that I keep getting. I need to pass a struct to unmanaged DLL. One of the struct members is a variable-length array. Unmanaged code will populate it with data, then my C# code will use the data.
My approach is this:
1. Get IntPtr for my structure using StructureToPtr(...), do the memory allocation too, of course.
2. Call unmanaged function, and pass IntPtr as a parameter
3. Get the populated structure using PtrToStructure(...)
If for the purposes of an exercise I call StructureToPtr(...) and PtrToStructure(...) back-to-back there are no exceptions.
PtrToStructure(...) generates SafeArrayTypeMismatchException, if I put a call to unmanaged DLL between StructureToPtr(...) and PtrToStructure(...). The description for SafeArrayTypeMismatchException is "Mismatch has occurred between the runtime type of the array and the sub type recorded in the metadata."
Any suggestion, insight or reference is really appreciated!
I can post my code if needed.
Last edited by kender_a; December 27th, 2010 at 06:26 PM.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!