News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

VARIANT structure

Started by sinsi, June 28, 2024, 10:40:44 AM

Previous topic - Next topic

sinsi

Does anyone have a simple definition of VARIANT in both 32 and 64-bit?
It doesn't seem to be in the .inc files.

zedd151

Does this help...
https://masm32.com/board/index.php?topic=2845.msg29946#msg29946?

I simply used an obscure forum function called 'search'.    :tongue:
Admittedly, not sure if this is what you are looking for...

sinsi

Quote from: zedd151 on June 28, 2024, 10:44:40 AMI simply used an obscure forum function called 'search'.    :tongue:
How droll  :biggrin:

I have some code I wrote a long time ago but it includes fields like .dw2, .dw1, .wReserved2, .vt
Different to the one you linked to
VARIANT STRUCT
  dw1   dd 0CCh
  dw2   dd 0CCh
  dw3   dd 0CCh
  dw4   dd 0CCh
VARIANT   ENDS

MSDN is its usual helpful self  :badgrin:
typedef struct tagVARIANT {
  union {
    struct {
      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 __OBSOLETE__VARIANT_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 *__OBSOLETE__VARIANT_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 {
          PVOID       pvRecord;
          IRecordInfo *pRecInfo;
        } __VARIANT_NAME_4;
      } __VARIANT_NAME_3;
    } __VARIANT_NAME_2;
    DECIMAL decVal;
  } __VARIANT_NAME_1;
} VARIANT;

NoCforMe

Yikes!
Where is that structure used?
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: NoCforMe on June 28, 2024, 11:07:53 AMYikes!
Where is that structure used?

In a lot of COM interface shit stuff.

zedd151

Quote from: sinsi on June 28, 2024, 11:13:16 AM
Quote from: NoCforMe on June 28, 2024, 11:07:53 AMYikes!
Where is that structure used?

In a lot of COM interface shit stuff.
Better you than me.  :joking:
If I saw that a function would need that structure, I'd pass on it. I prefer simpler code projects.

NoCforMe

For anyone else puzzled by what, exactly, COM is, see this new topic I posted.
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: zedd151 on June 28, 2024, 12:33:54 PM
Quote from: sinsi on June 28, 2024, 11:13:16 AM
Quote from: NoCforMe on June 28, 2024, 11:07:53 AMYikes!
Where is that structure used?

In a lot of COM interface shit stuff.
Better you than me.  :joking:
If I saw that a function would need that structure, I'd pass on it. I prefer simpler code projects.
It looks scary but it's actually quite easy  :biggrin:

jj2007

Quote from: sinsi on June 28, 2024, 10:40:44 AMDoes anyone have a simple definition of VARIANT in both 32 and 64-bit?

MasmBasic.inc:

  VARTYPE typedef word
  VARIANT struct 16
  vt    VARTYPE ?    ; VARTYPE: wtypes.h says unsigned word
  wReserved1    dw ?
  wReserved2    dw ?
  wReserved3    dw ?
  UNION
  bstrVal    dd ?
  pintVal    dd ?
  parray    dd ?
  scode    dd ?
  pvRecord    dd ?    ; add whatever you need - see oaidl.h
  llVal    dq ?
  lVal    dd ?
  iVal    dw ?
  bVal    db ?
  fltVal    REAL4 ?
  dblVal    REAL8 ?
  ends
  VARIANT    ends

COM is easy, if the methods are well documented. It's a horrible mess if C++ and C# can't agree about the number of arguments to be passed etc.

sinsi

So we have 4 words then a variable-length member, depending on what vt says?

minor28

#10
I used this Variant structure in my type library browser. Bifogar exe och iTypeLib.inc.
VARIANT struct dword ;size 10h
    vt                  word ? ; VT_EMPTY
    wReserved1          word ? ;0
    wReserved2          word ? ;0
    wReserved3          word ? ;0
    Union
        lVal             sdword ?    ; VT_I4                    A 4-byte integer value is stored in lVal.
        bVal             byte ?      ; VT_UI1                An unsigned 1-byte character is stored in bVal.
        iVal             sword ?     ; VT_I2                    A 2-byte integer value is stored in iVal.
        fltVal           real4 ?     ; VT_R4                    An IEEE 4-byte real value is stored in fltVal.
        dblVal           real8 ?     ; VT_R8                    An 8-byte IEEE real value is stored in dblVal.
        boolVal          word ?      ; VT_BOOL
        scode            dword ?     ; VT_ERROR
        cyVal            qword ?     ; VT_CY                    A currency value was specified. A currency number is stored as 64-bit (8-byte), two's complement integer, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right. The value is in cyVal.
        date             qword ?     ; VT_DATE                A value denoting a date and time was specified. Dates are represented as double-precision numbers, where midnight, January 1, 1900 is 2.0, January 2, 1900 is 3.0, and so on. The value is passed in date.
                                                            ;This is the same numbering system used by most
                                                            ;spreadsheet programs, although some specify
                                                            ;incorrectly that February 29, 1900 existed, and
                                                            ;thus set January 1, 1900 to 1.0. The date can be
                                                            ;converted to and from an MS-DOS representation
                                                            ;using VariantTimeToDosDateTime, which is discussed
                                                            ;in Conversion and Manipulation Functions.
        bstrVal          dword ?     ; VT_BSTR                A string was passed; it is stored in bstrVal. This pointer must be obtained and freed by the BSTR functions, which are described in Conversion and Manipulation Functions.
        punkVal          dword ?     ; VT_UNKNOWN            A pointer to an object that implements the IUnknown interface is passed in punkVal.
        pdispVal         dword ?     ; VT_DISPATCH            A pointer to an object was specified. The pointer is in pdispVal. This object is known only to implement IDispatch. The object can be queried as to whether it supports any other desired interface by calling QueryInterface on the object. Objects that do not implement IDispatch should be passed using VT_UNKNOWN.
        parray           dword ?     ; VT_ARRAY                For VT_ARRAY | any type, the rule is analogous to the rule for VT_BSTR. All arrays in variants must be allocated with SafeArrayCreate. When releasing or changing the type of a variant with the VT_ARRAY flag set, SafeArrayDestroy is called.
        pbVal            dword ?     ; VT_BYREF+VT_UI1        For VT_BYREF | any type, the memory pointed to by the variant is owned and freed by the caller of the function.
        piVal            dword ?     ; VT_BYREF+VT_I2
        plVal            dword ?     ; VT_BYREF+VT_I4
        pfltVal          dword ?     ; VT_BYREF+VT_R4
        pdblVal          dword ?     ; VT_BYREF+VT_R8
        pboolVal         dword ?     ; VT_BYREF+VT_BOOL
        pscode           dword ?     ; VT_BYREF+VT_ERROR
        pcyVal           dword ?     ; VT_BYREF+VT_CY
        pdate            dword ?     ; VT_BYREF+VT_DATE
        pbstrVal         dword ?     ; VT_BYREF+VT_BSTR
        ppunkVal         dword ?     ; VT_BYREF+VT_UNKNOWN
        ppdispVal        dword ?     ; VT_BYREF+VT_DISPATCH
        pparray          dword ?     ; VT_BYREF+VT_ARRAY
        pvarVal          dword ?     ; VT_BYREF+VT_VARIANT
        byref            dword ?     ; VT_BYREF
        cVal             sbyte ?     ; VT_I1                    A 1-byte character value is stored in cVal.
        uiVal            word ?      ; VT_UI2                 An unsigned 2-byte integer value is stored in uiVal.
        ulVal            dword ?     ; VT_UI4                 An unsigned 4-byte integer value is stored in ulVal.
        intVal           sword ?     ; VT_INT                An integer value is stored in intVal.
        uintVal          word ?      ; VT_UINT                An unsigned integer value is stored in uintVal.
        pdecVal          dword ?     ; VT_BYREF+VT_DECIMAL
        pcVal            dword ?     ; VT_BYREF+VT_I1
        puiVal           dword ?     ; VT_BYREF+VT_UI2
        pulVal           dword ?     ; VT_BYREF+VT_UI4
        pintVal          dword ?        ; VT_BYREF+VT_int
        puintVal         dword ?        ; VT_BYREF|VT_uint
    ends
VARIANT ends   

sinsi

Thanks, minor28, so anything VT_BYREF+??? would be qword in 64-bit?

TimoVJL

VARIANT works also with pointers, so pointer size isn't same in x64 world.
MS double 64-bit, so size depends of it in 32-bit world.
May the source be with you

minor28

The app was written with RadAsm3 32-bit about 10 years ago. I have not tried to develop the app for 64-bit.

Caché GB

Caché GB's 1 and 0-nly language:MASM