Solved

Problem with BSTR in VC++/DCOM.

Posted on 1998-09-24
4
327 Views
Last Modified: 2012-08-14
For oleautomation I am passing a BSTR from client program.The server is accepting it gracefully, but I want to convert the BSTR variable in server side to a char * or char array.My server can't use MFC as set previously.I tried with OLE2T/T2OLE etc. please help me in this matter.


Thanking u in anticipation,
Baidehish Dwibedy.
India.
0
Comment
Question by:bdwibedy
  • 2
4 Comments
 

Author Comment

by:bdwibedy
ID: 1173590
no
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 1173591
Use 'VectorFromBstr()' to receive an array of SAFEARRAYs of type 'VT_UI1'. You'll get the chars evaluating *(asa[ i].pvData)
0
 
LVL 2

Expert Comment

by:rayb
ID: 1173592
Cheap and dangerous way:
(Only dangerous if localization is an issue)
char buffer[max_buffer_size];
sprintf( buffer, "%S", bstr );  // Note that it's %'capital S'

Or you could use the MultiByteToWideChar function.
0
 
LVL 2

Expert Comment

by:rayb
ID: 1173593
Sorry, I meant to say the WideCharToMultiByte function.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

840 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