Solved

Problem with BSTR in VC++/DCOM.

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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 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 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.

760 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

18 Experts available now in Live!

Get 1:1 Help Now