Solved

Converting a COleVariant

Posted on 2001-09-08
3
631 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 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