Announcement

Collapse
No announcement yet.

%VT_RECORD example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • %VT_RECORD example

    Hy everybody,

    Does somebody have an idea or example on how to use the %VT_RECORD
    in a record. I have a function that passes over a variant and that
    variant could be of type %VT_RECORD but I have no idea how to use
    it. I would like to be able to store the %VT_RECORD (which is a
    type) into a String

    E.g.

    Function MyVariantFunction(vVar as VARIANT) As String
    Local Output as String
    If VariantVT(vVar) = %VT_RECORD Then
    ' Do something here .... and...
    OutPut = Variant$(vVar) ' However with a %VT_RECORD this doesn't work.
    End If
    ' Other stuff here maybe ... .. ..
    Function = Output
    End Function

    Thanks in advance
    Steven

    ------------------
    I'd rather be hated for who I am, then being loved for who I am not.
    So here we are, this is the end.
    But all that dies, is born again.
    - From The Ashes (In This Moment)

  • #2
    http://www.powerbasic.com/support/pb...ad.php?t=13303
    'don't have a %vt_record defined in win32api.inc did you try with safearray?
    'or use variantvt(?) to see what type it shows before passing to the function
    'wouldn't use variable output
    '
    '
    Code:
    #compile exe
    #dim all
    #include "win32api.inc"
    declare  function myvariantfunction(vtest as variant) as string
    function pbmain () as long
      local vtest  as variant
      local soutput as string
      vtest = string$(17,"z")
      print "type before call shows"variantvt(vtest)  '8 vt_bstr
      soutput = myvariantfunction(vtest)
      print soutput, len(soutput)  'see if 17 is returned, success
      waitkey$
    end function
    '
    function myvariantfunction(vvar as variant) as string
      local soutput as string  'reserved word so changed to soutput
      print "type in function is " variantvt(vvar)
      'if variantvt(vvar) = %vt_record then
      if variantvt(vvar) = %vt_bstr then
         print "vt_bstr success in function"
         ' do something here .... and...
         soutput = variant$(vvar) ' however with a %vt_record this doesn't work.
      else
         print "not vt_bstr in function"
      end if
      ' other stuff here maybe ... ..  ..
      function = soutput
    end function
    '
    '
    'safearray structure?
    '%vt_record not in win32api.inc
    'your example uses reserved word output, change that
    ' http://support.microsoft.com/?kbid=309329

    ------------------


    [this message has been edited by mike doty (edited september 07, 2006).]

    Comment


    • #3
      The VARIANTAPI structure in Win32Api.inc is incomplete, so use this one:

      Code:
      ' ========================================================================================
      ' VARIANT
      ' ========================================================================================
      
      TYPE BRECORD
        pvRecord  AS DWORD
        pRecInfo  AS DWORD  ' IRecordInfo interface
      END TYPE
      
      UNION VARIANTDATA_UNION
        lVal                          AS LONG         ' VT_I4
        bVal                          AS BYTE         ' VT_UI1
        iVal                          AS INTEGER      ' VT_I2
        fltVal                        AS SINGLE       ' VT_R4
        dblVal                        AS DOUBLE       ' VT_R8
        boolVal                       AS INTEGER      ' VT_BOOL
        scode                         AS LONG         ' VT_ERROR
        cyVal                         AS CUR          ' VT_CY
        date                          AS DOUBLE       ' VT_DATE
        bstrVal                       AS DWORD        ' VT_BSTR
        punkVal                       AS DWORD        ' VT_UNKNOWN
        pdispVal                      AS DWORD        ' VT_DISPATCH
        parray                        AS DWORD        ' VT_ARRAY
        pbVal                         AS BYTE PTR     ' VT_BYREF|VT_UI1
        piVal                         AS INTEGER PTR  ' VT_BYREF|VT_I2
        plVal                         AS LONG PTR     ' VT_BYREF|VT_I4
        pfltVal                       AS SINGLE PTR   ' VT_BYREF|VT_R4
        pdblVal                       AS DOUBLE PTR   ' VT_BYREF|VT_R8
        pboolVal                      AS INTEGER PTR  ' VT_BYREF|VT_BOOL
        pscode                        AS LONG PTR     ' VT_BYREF|VT_ERROR
        pcyVal                        AS CUR PTR      ' VT_BYREF|VT_CY
        pdate                         AS DOUBLE PTR   ' VT_BYREF|VT_DATE
        pbstrVal                      AS DWORD PTR    ' VT_BYREF|VT_BSTR
        ppunkVal                      AS DWORD PTR    ' VT_BYREF|VT_UNKNOWN
        ppdispVal                     AS DWORD PTR    ' VT_BYREF|VT_DISPATCH
        pparray                       AS DWORD PTR    ' VT_BYREF|VT_ARRAY
        pvarVal                       AS DWORD PTR    ' VT_BYREF|VT_VARIANT
        pByRef                        AS DWORD PTR    ' Generic BYREF (void*)
        cVal                          AS BYTE         ' VT_I1
        uiVal                         AS WORD         ' VT_UI2
        ulVal                         AS DWORD        ' VT_UI4
        intVal                        AS LONG         ' VT_INT
        uintVal                       AS DWORD        ' VT_UINT
        pdecVal                       AS DWORD PTR    ' VT_BYREF|VT_DECIMAL
        pcVal                         AS BYTE PTR     ' VT_BYREF|VT_I1
        puiVal                        AS WORD PTR     ' VT_BYREF|VT_UI2
        pulVal                        AS DWORD PTR    ' VT_BYREF|VT_UI4
        pintVal                       AS LONG PTR     ' VT_BYREF|VT_INT
        puintVal                      AS DWORD PTR    ' VT_BYREF|VT_UINT
        br                            AS BRECORD      ' VT_RECORD
      END UNION
      
      TYPE VARIANT_STRUCT
        vt         AS WORD  'VARTYPE
        wReserved1 AS WORD
        wReserved2 AS WORD
        wReserved3 AS WORD
        VARIANTDATA_UNION
      END TYPE
      To retrieve pointers to the record data and the IRecord interface we can do:
      Code:
         LOCAL hr AS LONG
         LOCAL pvData AS DWORD
         LOCAL pRecInfo AS DWORD
         LOCAL vField AS VARIANT
         LOCAL pv AS VARIANT_STRUCT PTR
      
         IF VARIANTVT(vVar) = %VT_RECORD THEN
            pv = VARPTR(vVar)
            pvData = @pv.br.pvRecord
            pRecInfo = @pv.br.pRecInfo
         END IF
      Now that we have the pointers we can retrieve the data of each field:
      Code:
         IF pvData <> %NULL AND pRecInfo <> %NULL THEN
            hr = hr = IRecordInfo_GetField(pRecInfo, pvData, "<field name>", vField)
         END IF
      Change "<field name>" with the name of the UDT's member.

      And this is the wrapper function IRecordInfo_GetField:
      Code:
      ' ****************************************************************************************
      ' GetField method
      ' Returns a pointer to the VARIANT containing the value of a given field name.
      ' ****************************************************************************************
      FUNCTION IRecordInfo_GetField (BYVAL pthis AS DWORD PTR, BYVAL pvData AS DWORD, BYVAL strFieldName AS STRING, BYREF pvarField AS VARIANT) AS LONG
      
          LOCAL HRESULT AS LONG
          strFieldName = UCODE$(strFieldName & $NUL)
          IF pthis = %NULL THEN FUNCTION = %E_POINTER : EXIT FUNCTION
          CALL DWORD @@pthis[10] USING IRecordInfo_GetField(pthis, pvData, strFieldName, pvarField) TO HRESULT
          FUNCTION = HRESULT
      
      END FUNCTION
      ' ****************************************************************************************



      ------------------
      Website: http://com.it-berater.org
      SED Editor, TypeLib Browser, COM Wrappers.
      Forum: http://www.forum.it-berater.org
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        Or, if you have the definition of the record, you can do this
        Code:
              
        LOCAL pStruct  AS Struct PTR
            
        pStruct = @pv.br.pvRecord
        Then you can access the members of the structure directly.

        ------------------
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com
        Dominic Mitchell
        Phoenix Visual Designer
        http://www.phnxthunder.com

        Comment


        • #5
          Thanks everyone !

          ------------------
          I'd rather be hated for who I am, then being loved for who I am not.
          So here we are, this is the end.
          But all that dies, is born again.
          - From The Ashes (In This Moment)

          Comment

          Working...
          X