?
Solved

Returning strings back to C++ from VB6

Posted on 2001-06-26
7
Medium Priority
?
220 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 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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