Solved

_bstr_t  to CString?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

635 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