Solved

_bstr_t  to CString?

Posted on 2000-04-30
3
4,551 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now