-
December 27th, 2010, 06:19 PM
#1
SafeArrayTypeMismatchException
Folks,
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.
- Nick
Last edited by kender_a; December 27th, 2010 at 06:26 PM.
-
December 28th, 2010, 10:05 PM
#2
Re: SafeArrayTypeMismatchException
What version of the framework you're using?
Check out this link, the article seems to be related to your problem:
http://support.microsoft.com/kb/317048
(And here's a related MSDN page: DispatchWrapper Class)
P.S. The important part of the VB code in the article translates as:
Code:
DispatchWrapper[] dispArray = new DispatchWrapper[9];
for (int i = 0; i < 9; i++)
{
// I'll assume that the objs array already exists
dispArray[i] = new DispatchWrapper(objs[i]);
}
// And then just pass dispArray instead.
-
January 1st, 2011, 11:03 PM
#3
Re: SafeArrayTypeMismatchException
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|