Solved

Returning strings back to C++ from VB6

Posted on 2001-06-26
7
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

736 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