Announcement

Collapse
No announcement yet.

passing a variant array of variants

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

  • passing a variant array of variants

    Hi all,
    I am in need of a method to pass a variant array of variants as
    a parameter to a COM method call. Has anyone tried this before?
    It is probably no simple thing to do either..

    Any help would be great.. thanks


    ------------------
    Sr. Software Development Engineer and Sr. Information Security Analyst,
    CEH, Digital Forensic Examiner

  • #2
    Code:
    TYPE SAFEARRAYBOUND
       cElements AS DWORD
       lLbound   AS LONG
    END TYPE
    
    DECLARE FUNCTION SafeArrayCreate LIB "OLEAUT32.DLL" ALIAS "SafeArrayCreate" (BYVAL vt AS WORD, BYVAL cDims AS DWORD, BYREF rgsabound AS SAFEARRAYBOUND) AS DWORD
    DECLARE FUNCTION SafeArrayPutElement LIB "OLEAUT32.DLL" ALIAS "SafeArrayPutElement" (BYVAL psa AS DWORD, BYVAL rgIndices AS DWORD, BYVAL pv AS DWORD) AS LONG
    
       ' Create a SafeArray with four elements
       DIM rgsabound AS SAFEARRAYBOUND
       DIM psa AS DWORD
       rgsabound.lLBound = 1
       rgsabound.cElements = 4
       psa = SafeArrayCreate(%VT_VARIANT, 1, rgsabound)
    
       DIM vPrm1 AS VARIANT
       DIM vPrm2 AS VARIANT
       DIM vPrm3 AS VARIANT
       DIM vPrm4 AS VARIANT
       DIM ix AS LONG
    
       ix = 1
       vPrm1 = <some value>
       SafeArrayPutElement(psa, BYVAL VARPTR(ix), BYVAL VARPTR(vPrm1))
       ix = 2
       vPrm2 = <some value>
       SafeArrayPutElement(psa, BYVAL VARPTR(ix), BYVAL VARPTR(vPrm2))
       ix = 3
       vPrm3 = <some value>
       SafeArrayPutElement(psa, BYVAL VARPTR(ix), BYVAL VARPTR(vPrm3))
       ix = 4
       vPrm4 = <some value>
       SafeArrayPutElement(psa, BYVAL VARPTR(ix), BYVAL VARPTR(vPrm4))
    
       ' Insert the SafeArray into a variant
       DIM vArray AS VARIANT
       DIM lpv AS VARIANTAPI PTR
       lpv = VARPTR(vArray)
       @lpv.vt = %VT_ARRAY OR %VT_VARIANT
       @lpv.vd.parray = psa
    
       ' Call the method using vArray as one of the parameters
       ............
    
       ' Destroy the SafeArray
       vArray = EMPTY

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




    [This message has been edited by José Roca (edited March 03, 2005).]
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Jose,
      thanks for writing but what I have been able to do is this

      Dim vArray as variant
      Dim sArray() as variant

      Redim sArray(1)

      sArray(0) = "hello"
      sArray(1) = "to you"

      Let vArray = sArray()

      'here is where I make my method call
      'and reassign the value hello to goodbye
      sArray() = vArray

      Msgbox sArray(0) 'displays goodbye

      seems alot simpler to do here.. am I missing something?




      ------------------
      Sr. Software Development Engineer and Sr. Information Security Analyst,
      CEH, Digital Forensic Examiner

      Comment


      • #4
        am I missing something
        Nothing if it works. However, using the API functions you can deal with
        %VT_BYREF variants if needed, something that was not possible before PBWin 8.0.


        ------------------
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          PBWin 9

          e.g. ByteArray as Variant (as parameter from COM method)

          Code:
          DIM vArray      AS VARIANT
          DIM bBytArr(3) AS BYTE
          bBytArr(0) = <Byte1>
          bBytArr(1) = <Byte2>
          bBytArr(2) = <Byte3>
          bBytArr(3) = <Byte4>
          
          LET vArray = bBytArr()
          ...
          Call the method using vArray as one of the parameters
           ...
          ...
          Yours sincerely

          Comment

          Working...
          X