?
Solved

Returning strings back to C++ from VB6

Posted on 2001-06-26
7
Medium Priority
?
223 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 1200 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
Independent Software Vendors: 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!

 
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

Industry Leaders: 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

862 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