Returning strings back to C++ from VB6

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.
s_sciortinoAsked:
Who is Participating?
 
jhanceConnect With a Mentor Commented:
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
 
peterchen092700Commented:
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
 
s_sciortinoAuthor Commented:
In answer to the question "In what format does the C++ prog expect the string?" The answer is a pointer to a BSTR.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
jhanceCommented:
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
 
peterchen092700Commented:
yep, code, we want code! we live on it, from it, for it!
0
 
s_sciortinoAuthor Commented:
His solution helped us solve the problem...
0
 
peterchen092700Commented:
cool... so the VC++ program could change...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.