VARIANT function or variable?

This is a discussion on VARIANT function or variable? within the C Programming forums, part of the General Programming Boards category; Can anyone tell what the VARIANT function or variable is used for?Is it really needed to send serial commands using ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    56

    VARIANT function or variable?

    Can anyone tell what the VARIANT function or variable is used for?Is it really needed to send serial commands using C++?

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    VARIANT is not part of standard C. I'd imagine if the name is actually VARIANT it is really a macro anyways. can you provide more information as to help you better?

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    I have seen the VARIANT used as a declaration in C++ and was curious as to its purpose. What is its equivalent in C? Is it really needed in C?
    Last edited by NewGuy100; 07-28-2005 at 08:29 PM.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    VARIANT is not part of standard C++ either. So again, can you provide some more information as to help you better?

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    56
    Well I am trying to get better acquainted on serial communication in C and C++ and I have noticed the use of VARIANT declaration in several examples in C++ and I am curious as to its usage. Basically, I just want to know if I need it. I found that C++ sends out data in binary format so VARIANT is used to convert data to binary. I want to send Hex data through the serial port. Is it possible or do I have to convert it to Binary like in C++?
    Last edited by NewGuy100; 07-28-2005 at 09:12 PM.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    It seems to me you were looking at VB examples, rather than C or C++ examples.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    C and C++ have no standard means of performing serial communication. Whatever method you are reading about is some specific OS.

    All data is binary, your statement about sending hex data does not make sense. Do you want to send a string that looks like "0xff0xde" or numerical values? If so numbers have no base, simply their representation does.

    You should probably learn C or C++ before attempting to do things specific to your OS. And reading code is generally not a decent way to learn the language.

  8. #8
    .
    Join Date
    Nov 2003
    Posts
    307
    VARIANT is pure Windoze. It's meant to be a variable "datatype" that holds or references everything windows defines - from interfaces to ints. You cannot use it outside of windoze, AFAIK.

    From MSDN:
    Code:
    typedef struct tagVARIANT VARIANT;
    typedef struct tagVARIANT VARIANTARG;
    struct tagVARIANT
        {
        union 
            {
            struct __tagVARIANT
                {
                VARTYPE vt;
                WORD wReserved1;
                WORD wReserved2;
                WORD wReserved3;
                union 
                    {
                    LONGLONG llVal;
                    LONG lVal;
                    BYTE bVal;
                    SHORT iVal;
                    FLOAT fltVal;
                    DOUBLE dblVal;
                    VARIANT_BOOL boolVal;
                    _VARIANT_BOOL bool;
                    SCODE scode;
                    CY cyVal;
                    DATE date;
                    BSTR bstrVal;
                    IUnknown *punkVal;
                    IDispatch *pdispVal;
                    SAFEARRAY *parray;
                    BYTE *pbVal;
                    SHORT *piVal;
                    LONG *plVal;
                    LONGLONG *pllVal;
                    FLOAT *pfltVal;
                    DOUBLE *pdblVal;
                    VARIANT_BOOL *pboolVal;
                    _VARIANT_BOOL *pbool;
                    SCODE *pscode;
                    CY *pcyVal;
                    DATE *pdate;
                    BSTR *pbstrVal;
                    IUnknown **ppunkVal;
                    IDispatch **ppdispVal;
                    SAFEARRAY **pparray;
                    VARIANT *pvarVal;
                    PVOID byref;
                    CHAR cVal;
                    USHORT uiVal;
                    ULONG ulVal;
                    ULONGLONG ullVal;
                    INT intVal;
                    UINT uintVal;
                    DECIMAL *pdecVal;
                    CHAR *pcVal;
                    USHORT *puiVal;
                    ULONG *pulVal;
                    ULONGLONG *pullVal;
                    INT *pintVal;
                    UINT *puintVal;
                    struct __tagBRECORD
                        {
                        PVOID pvRecord;
                        IRecordInfo *pRecInfo;
                        }    __VARIANT_NAME_4;
                    }    __VARIANT_NAME_3;
                }    __VARIANT_NAME_2;
            DECIMAL decVal;
            }    __VARIANT_NAME_1;
    struct tagVARIANT  
       {
        union 
           {
           struct __tagVARIANT
           {
              VARTYPE vt;
              WORD wReserved1;
              WORD wReserved2;
              WORD wReserved3;
       union {
          LONGLONG                llval;             // VT_I8. 
          LONG                    lVal;              // VT_I4.
          BYTE                    bVal;              // VT_UI1.
          SHORT                   iVal;              // VT_I2.
          FLOAT                   fltVal;            // VT_R4.
          DOUBLE                  dblVal;            // VT_R8.
          VARIANT_BOOL            boolVal;           // VT_BOOL.
          _VARIANT_BOOL           bool;
          SCODE                   scode;             // VT_ERROR.
          CY                      cyVal;             // VT_CY.
          DATE                    date;              // VT_DATE.
          BSTR                    bstrVal;           // VT_BSTR.
          IUnknown                * punkVal;         // VT_UNKNOWN.
          IDispatch               * pdispVal;        // VT_DISPATCH.
          SAFEARRAY               * parray;          // VT_ARRAY|*.
          BYTE                    * pbVal;           // VT_BYREF|VT_UI1.
          SHORT                   * piVal;           // VT_BYREF|VT_I2.
          LONG                    * plVal;           // VT_BYREF|VT_I4.
          LONGLONG                * pllVal;          // VT_BYREF|VT_I8.
          FLOAT                   * pfltVal;         // VT_BYREF|VT_R4.
          DOUBLE                  * pdblVal;         // VT_BYREF|VT_R8.
          VARIANT_BOOL            * pboolVal;        // VT_BYREF|VT_BOOL.
          _VARIANT_BOOL           * pbool;
          SCODE                   * pscode;          // VT_BYREF|VT_ERROR.
          CY                      * pcyVal;          // VT_BYREF|VT_CY.
          DATE                    * pdate;           // VT_BYREF|VT_DATE.
          BSTR                    * pbstrVal;        // VT_BYREF|VT_BSTR.
          IUnknown                ** ppunkVal;       // VT_BYREF|VT_UNKNOWN.
          IDispatch               ** ppdispVal;      // VT_BYREF|VT_DISPATCH.
          SAFEARRAY               ** pparray;        // VT_ARRAY|*.
          VARIANT                 * pvarVal;         // VT_BYREF|VT_VARIANT.
          PVOID                   * byref;           // Generic ByRef.
          CHAR                    cVal;              // VT_I1.
          USHORT                  uiVal;             // VT_UI2.
          ULONG                   ulVal;             // VT_UI4.
          ULONGLONG               ullVal;            // VT_UI8.
          INT                     intVal;            // VT_INT.
          UINT                    uintVal;           // VT_UINT.
          DECIMAL                 * pdecVal          // VT_BYREF|VT_DECIMAL.
          CHAR                    * pcVal;           // VT_BYREF|VT_I1.
          USHORT                  * puiVal;          // VT_BYREF|VT_UI2.
          ULONG                   * pulVal;          // VT_BYREF|VT_UI4.
          ULONGLONG               * pullVal;         // VT_BYREF|VT_UI8.
          INT                     * pintVal;         // VT_BYREF|VT_INT.
          UINT                    * puintVal;        // VT_BYREF|VT_UINT.
          struct __tagBRECORD
          {
          PVOID                   pvRecord;
          IRecordInfo             *pRecInfo;
          }    __VARIANT_NAME_4;
       }    __VARIANT_NAME_3;
      }    __VARIANT_NAME_2;
      DECIMAL decVal;
    }    __VARIANT_NAME_1;
    
       };
    };

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21