Solved

_bstr_t  to CString?

Posted on 2000-04-30
3
4,560 Views
Last Modified: 2013-11-20
I'm interfacing with an active X thing, and I don't know much about this stuff.  The object has a property which seems to be a _bstr_t.  I want to get that string and use it in VC++/MFC preferably as a CString.  (Actually, all I need to do is grab this string and show it in a control with SetWindowText.  Should be easy, huh?  I can't figure out how....
0
Comment
Question by:tullhead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 2764225
If you know that the _bstr_t doesn't contain binary data (that is, it doesn't contain embedded null characters) you can safely convert using CString's LPCWSTR constructor:

   CString str((LPCWSTR) yourBSTRt);

This conversion works, but ignores the length of the stored data. If the string has binary data, you'll need to correctly heed the length stored in the BSTR and things will get more complicated.

..B ekiM
0
 

Author Comment

by:tullhead
ID: 2764336
Hmmmm... my string is always coming back as a "-1" -- which isn't correct.  But that might be my problem, or misuse of the Active X control....  So, I'll
give the points-- thanks!

Does the -1 signify something to you?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2764381
Other than negative one?  No.  But you can look at the _bstr_t variable in the debugger to see what it is before the conversion to convince yourself that the conversion itself is really working.

..B ekiM
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
List out all word 7 358
difference between String.subString() and String.subSequence() 6 289
no14 challenge 14 77
Updating statistics with error notification email in SQL server 4 128
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question