CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    151

    using VARIANT or converting to CString

    I'v been searching the whole Internet for the following problem :

    how to convert a CString to a Variant

    my problem :
    I'm working on an ADO database and I want to use the filter of the _recordsetPtr
    like this :

    _RecordsetPtr m_pRS ;
    CString strFilter = "Name LIKE 'a*'" ;

    m_pRS.Filter = strFilter ;

    only problem : the Filter only takes a variant

    or maybe can someone explain to me how I must use the VARIANT type?
    I already searched MSDN and the web, but nowhere any good explanation on VARIANT

    TIA

  2. #2
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Thumbs up Re: using VARIANT or converting to CString

    Quote Originally Posted by da_cobra
    how to convert a CString to a Variant
    CString to VARIANT Conversion: Method I
    Code:
      // Your CString
         CString strInput (_T ("Test String"));
       
         VARIANT varString;
       
         // Create a BSTR, assign it.
         varString.bstrVal = strInput.AllocSysString ();
       
         // Set Variant Type
         varString.vt = VT_BSTR;
       
         // Use the VARIANT
       
         // De-Allocate it: Don't forget this step if you are using Raw Variants
         ::VariantClear (&varString);
    CString to VARIANT Conversion: Method II
    Code:
      // Using the CComVariant: Smart Wrapper Class for VARIANT
    	CComVariant varSmartVariantString (strInput);
       
         // Use varSmartVariantString...
    Quote Originally Posted by da_cobra
    or maybe can someone explain to me how I must use the VARIANT type?
    Q. What is a VARIANT?
    A. A VARIANT is a structure.

    Code:
    typedef struct tagVARIANT VARIANT;
       typedef struct tagVARIANT VARIANTARG;
       struct tagVARIANT
       {
         // ... variant members...
       };
    It can support many data-types because it (the structure) contains a UNION as a member.
    The Variant Type is identified by the member VARIANT::vt
    Quote Originally Posted by da_cobra
    I already searched MSDN and the web, but nowhere any good explanation on VARIANT
    The link above contains detailed information.

    Let me know if your query is solved.

  3. #3
    Join Date
    Apr 2005
    Posts
    151

    Thumbs up Re: using VARIANT or converting to CString

    thx alot! this really helped me!!!

  4. #4
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: using VARIANT or converting to CString

    You are welcome.

    Ciao,
    Sid!

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