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
Solved

Datatype Conversion in VC++.

Posted on 2002-05-03
7
1,408 Views
Last Modified: 2013-11-20
hi all,

 I am novice to VC++. Can anyone help me  to convert the _variant_t datatype to CString.I am little bit confused with datatypes(_bstr_t,LPCSTR,_variant_t and their conversion). plz give the ways when to use which datatype.
0
Comment
Question by:bkkabi
  • 2
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
Crius earned 25 total points
ID: 6988582
Hmm, well:

_bstr_t is a smart pointer that represents a Visual Basic string. It's used in many COM (Component Object model) calls.

LPCSTR is a long pointer to a constant string. const char *

_variant_t is a smart pointer that represents a Visual Basic variant. A variant is a variable that can be anything - a float, double, string, integer, short, long, you name it.

Now, to convert a _variant_t to a CString is a bit of fun.
Try:
CString1 = (char*)((_bstr_t)_variant_t1);
where CString1 is a CString and _variant_t1 is a _variant_t.
Basically, we are calling operator _bstr_t of the variant, which takes the variant's value and returns it in a _bstr_t, and then calling the operator char * of the returned _bstr_t which is just a character pointer, which can be assigned directly to a CString.
0
 
LVL 4

Assisted Solution

by:mblat
mblat earned 25 total points
ID: 6989311
actually

 CString1 = _variant_t1.bstrVal;

will work just fine.... and also take care if you are writing UNICODE app...


Hope it helps...
0
 

Expert Comment

by:myexpert2002
ID: 6989503


  Thank u Crius,mblat. Both of u solved my problem. Is there any document where i can refer this datatype conversion.If so provide me the URLs so that i can refer to it.


0
 

Expert Comment

by:myexpert2002
ID: 6989514


  Thank u Crius,mblat. Both of u solved my problem. Is there any document where i can refer this datatype conversion.If so provide me the URLs so that i can refer to it.


0
 
LVL 3

Expert Comment

by:Crius
ID: 6991714
MSDN library contains all this information. It is available on the web as well.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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