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.
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++.
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?)

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.
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.

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