?
Solved

Datatype Conversion in VC++.

Posted on 2002-05-03
7
Medium Priority
?
1,432 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
[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
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
Crius earned 100 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 100 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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