Solved

_bstr_t  to CString?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now