Solved

Returning strings back to C++ from VB6

Posted on 2001-06-26
7
214 Views
Last Modified: 2010-04-02
I have a VB class which is instantiated by a C++ program that we would like to return a string back
to the C++ program.  We changed VB class to declare the string both byref and byval and still C++ does
not understand the string being returned.  The C++ program cannot change, only the VB program can.
0
Comment
Question by:s_sciortino
  • 3
  • 2
  • 2
7 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 300 total points
ID: 6228114
Strings coming back from VB will be BSTR types.  The simplest way to deal with them is via the C++ template class _bstr_t.  You'll be getting a BSTR reference back from VB, create a _bstr_t using the BSTR constructor:

_bstr_t( BSTR bstr, bool fCopy ) throw ( _com_error );

and then you can do what you want with it in VC++.
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6228305
jhance is right - but it won't help you if you can change "only the VB program".

possible aproach would be a) copy the string to y byte buffer, or b) "inject" a C++ component that does the conversion.

In what format does the C++ prog expect the string? (i.e. how does the call to the "VB class" look like?)

Peter
0
 

Author Comment

by:s_sciortino
ID: 6228576
In answer to the question "In what format does the C++ prog expect the string?" The answer is a pointer to a BSTR.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 32

Expert Comment

by:jhance
ID: 6228597
In that case you are all set, since in VB, you have to "stand on your head" to return anything BUT a pointer to a BSTR.

How about showing some code?
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6228692
yep, code, we want code! we live on it, from it, for it!
0
 

Author Comment

by:s_sciortino
ID: 6229248
His solution helped us solve the problem...
0
 
LVL 7

Expert Comment

by:peterchen092700
ID: 6230429
cool... so the VC++ program could change...
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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

757 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

20 Experts available now in Live!

Get 1:1 Help Now