....and you get safe array type mismatch exceptions from the marshaller.
I have a C++ COM object (thank God I could find the source) that was
declared properly in the IDL for [out, retval] and requiring a VARIANT*,
everytime I tried to use this object from C# the marshaller would throw up
marshalling the return value. Now, I should mention that this COM object
works great in when used by C++ code which has to marshall the data as well.
I googled my rear off learning all kinds of interesting stuff which I hope
I'll never have to use in real life (editing CIL files the recompiling them
in order to trick the runtime marshaller), none of it worked.
I had, or course, already checked to see how the SAFEARRAYs were passed back
and, being an old time COM developer, I didn't notice anything unusual.
VT_ARRAY were declared with the appropriate type info. Bounds were set
properly, et cetera.
I checked for VTDISPATCH, I tried important the type lib with /sysarray, all
to no effect.
Basically I tried everything I could google.
Then I noticed that the memory for the array was allocated in a relatively
old fashioned manner in the C++ COM object. It didn't use SafeArrayCreate
(sp?) it did a system allocation like you used to always do in the earlier
days of automation and then setup the array (properly) with elements and
bounds et al.
Changing the data allocation to use SafeArrayCreate solved the C#
marshalling issue for me entirely.
I just wanted to put this out there so that in 3 years when I run into this
again and forget how I solved the problem I can google myself ;).
WTH
--
"I will always remain a fan of Liverpool Football Club. I'll come here again
as a friend and a fan and I will cheer the boys on." - Gérard Houllier