CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2002
    Location
    Central/Upstate NY, USA
    Posts
    137

    Arrow 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?????

  2. #2
    Join Date
    Feb 2001
    Posts
    2,455
    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

  3. #3
    Join Date
    Jul 2002
    Location
    kansas
    Posts
    4
    Why change it to BSTR first? what next?

    If my understanding is right, maybe something like this.

    v.llval = atoi64((LPSTCTR)s);


  4. #4
    Join Date
    Jun 2002
    Location
    Central/Upstate NY, USA
    Posts
    137
    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.

  5. #5
    Join Date
    Feb 2001
    Posts
    2,455
    What data type is llVal. I don't even see that in the VARIANT list.

    Mike B

  6. #6
    Join Date
    Feb 2001
    Posts
    2,455
    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

  7. #7
    Join Date
    Jun 2002
    Location
    Central/Upstate NY, USA
    Posts
    137
    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

  8. #8
    Join Date
    Feb 2001
    Posts
    2,455
    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
  •  





Click Here to Expand Forum to Full Width

Featured