Solved

Datatype Conversion in VC++.

Posted on 2002-05-03
7
1,405 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now