Solved

Datatype Conversion in VC++.

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

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

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 112
How to know only "File created" with EventLog 3 35
countEvens challenge 2 113
scoreUp challenge 14 69
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

740 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