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

x
?
Solved

Datatype Conversion in VC++.

Posted on 2002-05-03
7
Medium Priority
?
1,439 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

971 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