Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

_bstr_t  to CString?

Posted on 2000-04-30
3
Medium Priority
?
4,569 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

927 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