Converting a COleVariant

Posted on 2001-09-08
Last Modified: 2008-03-06
In C++, is there a nice, easy, guarunteed way to convert a COleVariant (or VARIANT) string to a CString?
Question by:Ahriman
  • 2

Expert Comment

ID: 6467717
It looks as if the W2A() function does the trick.
I'm trying it, but am getting an error.

Check this example:

Accepted Solution

Triskelion earned 100 total points
ID: 6467790
Got it.
Cast the .bstrVal to a LPCWSTR.

     COleVariant varX("#156Z");
     CString        strAsdf;

Author Comment

ID: 6468481
Thanks - nice one! Looks as though this should also be unicode-compliant (if ever needed). Thanks again.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 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…
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.

861 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