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

Thread: VARIANT types

  1. #1
    Join Date
    May 1999
    Location
    Fort Worth Texas
    Posts
    614

    VARIANT types

    How does one set a double type to a VARIANT RT_8 type?

    Thanks


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

    Re: VARIANT types

    Hi Jim

    There are two ways of doing this:
    1)Here is some code to demonstrate the usage of the VARIANT type.
    //----
    VARIANT v_Var;
    double d = 1.6;
    v_Var.vt = VT_R8;
    v_Var.dblVal = d;
    //----
    2) You can also create a COleVariant object and pass the double in the constructor. The COleVariant will be accepted anywhere the VARIANT is called for.

    Hope this works out for you )

    Rick
    P.S. Send me a line to tell me how it worked out.


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

    Re: VARIANT types

    Hi Jim

    There are two ways of doing this:
    1)Here is some code to demonstrate the usage of the VARIANT type.
    //----
    VARIANT v_Var;
    double d = 1.6;
    v_Var.vt = VT_R8;
    v_Var.dblVal = d;
    //----
    2) You can also create a COleVariant object and pass the double in the constructor. The COleVariant will be accepted anywhere the VARIANT is called for.

    Hope this works out for you )

    Rick
    P.S. Send me a line to tell me how it worked out.


  4. #4
    Join Date
    Apr 1999
    Posts
    1

    Re: VARIANT types

    Rick,

    I've been stuck on a VARIANT problem for some time. I wonder if you could help shed some light.

    I have a MS ActiveX control. One of its methods is declared as:

    void SetOutput(const VARIANT& newValue);

    I'm quite sure that the method accepts only the BSTR part of the VARIANT. The method behaves as expected when I pack it with a BSTR with 1 or more characters:

    CString cstrTemp = "a";
    varTemp.vt= VT_BSTR;
    varTemp.bstrVal = cstrTemp.AllocSysString();
    SetOutput(varTemp);

    However, I wish to call the method with a NULL character (i.e. 0x00). The question is: How do I put a 0x00 in the VARIANT as a BSTR?

    Thanks,

    NB. the control is MSComm32.ocx


    --
    Stephen

  5. #5
    Join Date
    Apr 1999
    Posts
    4

    Re: VARIANT types

    COleVariant has these Constructors:

    COleVariant( LPCTSTR lpszSrc );
    COleVariant( LPCTSTR lpszSrc, VARTYPE vtSrc );
    COleVariant( CString& strSrc );

    I'm sure you could fill a CString or the LPCTSTR string to a Null character, and then use the VARIANT operator to pass it along as the parameter for your function. Im not able to test this out, but this may work:

    TCHAR temp[1];
    temp[0] = '\0';
    CString temp2(temp);
    COleVariant var(temp);

    The last line of code will give you your variant. Then call your function:

    FunctionCall((VARIANT)var);

    Hope this helps, again I haven't tried this out, but it should work.




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

    Re: VARIANT types

    To pass an empty VARIANT try;

    variant.vt = VT_NULL;
    or
    variant.vt = VT_EMPTY;

    in the help there is somthing about put in VT_ERROR but I'm not to shure how that works.

    Rick


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

    Re: VARIANT types

    To pass an empty VARIANT try;

    variant.vt = VT_NULL;
    or
    variant.vt = VT_EMPTY;

    in the help there is somthing about put in VT_ERROR but I'm not to shure how that works.

    Rick


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