Solved

Problem with BSTR in VC++/DCOM.

Posted on 1998-09-24
4
323 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now