From: David Lowndes on 13 Apr 2010 08:31 >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 13 Apr 2010 10:15 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.
|
Pages: 1 Prev: Visual Studio 2010 Next: I need a good book to learn CAsyncSocket and Csocket |