|
-
July 2nd, 2002, 10:41 AM
#1
how to convert CString to Variant???
ive found so many examples on how to convert a variant to a cstring but none on the reverse?
basically, i GetWindowText from a text box in the form of a CString and want to use that value as a REFERENCE_TIME which is of type LongLong.
this is what i have:
////////////////////////////////////////
CString s;
VARIANT v;
e_Start.GetWindowText(s);
//conversion code goes here
e_pVEdit->SetStartTime(v.llVal);
}
////////////////////////////////////////
e_Start is the text box of course, and e_pVEdit is a class object with the method SetStartTime which takes a REFERENCE_TIME argument which is essentially a LongLong value.
i just can't figure out how to turn s into v?????
-
July 2nd, 2002, 10:54 AM
#2
I think you need to convert from CString to BSTR first.
Maybe something like:
CString csMyString = _T("TEST");
bstr_t bstrString = csMyString.AllocSysString();
_variant_t vString;
vString.vt = VT_BSTR;
vString.BSTR = bstrString;
Not tested. But maybe something like above??
Mike B
-
July 2nd, 2002, 10:58 AM
#3
Why change it to BSTR first? what next?
If my understanding is right, maybe something like this.
v.llval = atoi64((LPSTCTR)s);
-
July 2nd, 2002, 01:15 PM
#4
neight of your replies worked, unless there is something terribly wrong with me
CString s;
VARIANT v;
e_End.GetWindowText(s);
v.vt = VT_BSTR;
v.bstrVal = s.AllocSysString();
this only set the bstrVal correctly, cuz when i check the v.llVal, it is always 0???
Last edited by ipsteal; July 2nd, 2002 at 01:45 PM.
-
July 2nd, 2002, 01:51 PM
#5
What data type is llVal. I don't even see that in the VARIANT list.
Mike B
-
July 2nd, 2002, 02:09 PM
#6
sorry, I should have read it more clearly:
basically, i GetWindowText from a text box in the form of a CString and want to use that value as a REFERENCE_TIME which is of type LongLong.
How would you get a type "LongLong" from a CString anyhow? Can you not use COleDateTime or something?
COleDateTime date;
if(date.ParseDateTime(dateString))
{
_variant_t vDate;
vDate.vt = VT_DATE;
vDate.Date = date;
}
This maybe way off what you want, but I am not sure what REFERENCE_TIME is, or what you are actually trying to do?
Mike B
-
July 2nd, 2002, 02:35 PM
#7
i got it, maybe not the best way, but it works
here is my solution:
//////////////////////////////////////////
CString s;
e_End.GetWindowText(s);
int t;
sscanf(s,"%d",&t);
.
.
//yadda yadda
.
.
e_pVEdit->SetEndTime((REFERENCE_TIME &)t);
//////////////////////////////////////////
that works good enough for me 
thanks for the help though
-
July 2nd, 2002, 02:36 PM
#8
If the CString is a number representing time, could you not do something like:
CString s;
e_Start.GetWindowText(s);
double dValue = atof(s);
e_pVEdit->SetStartTime((LONGLONG)(dValue * 10000000) ;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|