From: David Lowndes on
>If I run the C++
>client application in a debugger I can definitely see the old C++ COM
>server returns the string as one byte wide characters (despite the IDL
>defining BSTR type).

That sounds like the old code is written to assume an ANSI string
masquerading as a BSTR - possibly the old code used
SysAllocStringByteLen to put an ANSI string into a BSTR.

Dave
From: Scott Ballard on
On Apr 13, 6:31 am, David Lowndes <Dav...(a)example.invalid> wrote:
> >If I run the C++
> >client application in a debugger I can definitely see the old C++ COM
> >server returns the string as one byte wide characters (despite the IDL
> >defining BSTR type).
>
> That sounds like the old code is written to assume an ANSI string
> masquerading as a BSTR - possibly the old code used
> SysAllocStringByteLen to put an ANSI string into a BSTR.
>
> Dave

Yes, Dave that's exactly what the old C++ code was doing. I modified
the new C# code to P/Invoke SysAllocStringByteLen and everything works
fine now. I never thought of jamming the ANSI output of
SysAllocStringByteLen into a C# string. The C# string looks strange
in the debugger (since it reads two bytes per character and the ANSI
string is only one byte per character), but it works! I would like to
thank you and Giovanni for making me consider SysAllocStringByteLen.

Regards,

Scott B.