CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Variants.

  1. #1
    Join Date
    Apr 1999
    Posts
    2

    Variants.

    I use Variants all the time (mainly COleVariant), however today I simply wanted to construct a Variant using a CString. I hit my head against the wall many times, trying crappy things like

    * T2OLE (with SysAlloc whatever)
    * _variant_t.SetString
    * var.pbVal = "such and such"
    * COleVariant(str), var=olevar.Detach()

    and I couldn't get it to work at all. I feel like an idiot, but could someone purlease put me out of my misery.

    CString into Variant.

    Consider Phlebas


  2. #2
    Join Date
    May 1999
    Location
    Ottawa, Ont
    Posts
    120

    Re: Variants.

    Hi,

    first of all there is no way that you can put a CString in to a VARIANT you first have to pass the CString to a BSTR then you will be able to add the BSTR to the VARIANT;

    eg.


    CString szSomeStr("Some text");

    BSTR bstrSomeStr = szSomeStr.AllocSysString ( ); VARIANT vSomeVariant;
    vSomeVariant.vt = VT_BSTR;
    vSomeVariant.bstrVal = bstrSomeStr;





    and that should do it...

    Rick


  3. #3
    Join Date
    May 1999
    Location
    Ottawa, Ont
    Posts
    120

    Re: Variants.

    Hi,

    first of all there is no way that you can put a CString in to a VARIANT you first have to pass the CString to a BSTR then you will be able to add the BSTR to the VARIANT;

    eg.


    CString szSomeStr("Some text");

    BSTR bstrSomeStr = szSomeStr.AllocSysString ( ); VARIANT vSomeVariant;
    vSomeVariant.vt = VT_BSTR;
    vSomeVariant.bstrVal = bstrSomeStr;





    and that should do it...

    Rick


  4. #4
    Join Date
    May 1999
    Location
    Seattle, WA USA
    Posts
    423

    Re: Variants.

    Can't you just sayCString MyString("String");
    COleVariant MyVariant (MyString);

    ColeVariant has an LPCSTR constructor, and CString has an LPCSTR operator.

    HTH
    --michael


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