BSTR's, BSTR->string, and maps 
Author Message
 BSTR's, BSTR->string, and maps

There are lots of postings about going from char strings to BSTR's.  I need
to go the other way.  Maybe.

A VB call passes a (BSTR) string and a float to a DLL (ATL COM) function.
The BSTR is "wide", so every other byte is a null.

I want the dll to stuff that string away, along with the value, for later
retrieval keyed on the string.  To do that, i use a CMapStringToOb.  It
(and just about any alternative, as far as I can tell) wants a
null-terminated string.  Right now, it treats the string as though it were
one character long; the second byte is seen as the string terminator.

How do i use a BSTR in a map?  Is it necessary to convert the BSTR to a
single wide string to use it?  Is there something to do that conversion, or
do i have to take the nulls out "manually"?  It seems like an absurd waste
of processor.

Geez, i need to take a course if i'm going to keep my sanity.  Thanks for
any help.

Herb Munson



Mon, 26 Mar 2001 03:00:00 GMT  
 BSTR's, BSTR->string, and maps
Herb -
    If you're sure that the string won't be saved in one NLS (language
system) and used in another, you can use WideCharToMultiByte on the DLL side
to convert it to a 'regular' string, and MultiByteToWideChar to convert it
back to Unicode as needed.  Don't even think about trying to "take the nulls
out" yourself, not only is it a waste of time, you will get seriously hosed
when you encounter the few characters that don't follow that pattern.

--
     Jim Mack
     MicroDexterity, Inc

     http://www.microdexterity.com



Quote:

>There are lots of postings about going from char strings to BSTR's.  I need
>to go the other way.  Maybe.

>A VB call passes a (BSTR) string and a float to a DLL (ATL COM) function.
>The BSTR is "wide", so every other byte is a null.

>I want the dll to stuff that string away, along with the value, for later
>retrieval keyed on the string.  To do that, i use a CMapStringToOb.  It
>(and just about any alternative, as far as I can tell) wants a
>null-terminated string.  Right now, it treats the string as though it were
>one character long; the second byte is seen as the string terminator.

>How do i use a BSTR in a map?  Is it necessary to convert the BSTR to a
>single wide string to use it?  Is there something to do that conversion, or
>do i have to take the nulls out "manually"?  It seems like an absurd waste
>of processor.



Mon, 26 Mar 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. BSTR FAR* sz => (const char *)sz

2. converting bstr to string

3. xmldoc.xml & string = bstr / Problem with encoding

4. Passing String (BSTR) from VB5 to VC++ - stress test fails

5. xmldoc.xml & string = bstr / Problem with encoding

6. Is BSTR in C++ is equal to String in VB

7. Getting BSTR string pointer from a dll without varptr

8. converting from a LPSTR to a BSTR ( visual basic string )

9. Why does VB6 use BSTR for strings?

10. Getting BSTR string pointer from a dll without varptr

11. converting from a LPSTR to a BSTR ( visual basic string )

12. Some body know what's mean bstr?

 

 
Powered by phpBB® Forum Software