Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting a COleVariant

Posted on 2001-09-08
3
Medium Priority
?
656 Views
Last Modified: 2008-03-06
In C++, is there a nice, easy, guarunteed way to convert a COleVariant (or VARIANT) string to a CString?
0
Comment
Question by:Ahriman
  • 2
3 Comments
 
LVL 6

Expert Comment

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

Check this example:
http://www.trustsoft.com/eng/varient.htm
0
 
LVL 6

Accepted Solution

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

     COleVariant varX("#156Z");
     CString        strAsdf;
     strAsdf=(LPCWSTR)varX.bstrVal;
     AfxMessageBox(strAsdf);
0
 

Author Comment

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

916 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