Announcement

Collapse
No announcement yet.

SafeArrayCreate

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

  • SafeArrayCreate

    Hi,

    I need to create a dynamic array that needs to be a SafeArray. I
    found that the parameters are:

    the VARTYPE, dimension and SAFEARRAYBOUND (Type). The SAFEARRAYBOUND type
    has 2 members. The Lower Bound (0) and the number of elements however
    I don't know how many items it will contain hence the dynamic safearray
    Has anybody done this before ? This is all OLE stuff btw.

    Hope this makes sense to somebody.

    ------------------
    So here we are, this is the end.
    But all that dies, is born again.
    - From The Ashes (In This Moment)

  • #2
    Steven,

    have you had a look at VBAPI32.INC which came along with PB/DLL? This sould help you.

    Knuth

    ------------------
    http://www.softAware.de

    Comment


    • #3
      Thanks Knuth !

      This should make my life a bit easier. Still I guess you can't
      have dynamic SafeArrays - you always need to specify the upper-
      bound. Although with the use of the vbArrayRedim function I
      should be able to circumvent this.

      Thanks.

      Steven

      ------------------
      So here we are, this is the end.
      But all that dies, is born again.
      - From The Ashes (In This Moment)

      Comment


      • #4
        Hm...

        Don't know what to do. The SafeArrayPutElement doesn't seem to
        work for me. I have the following code

        Code:
          
            %VT_BSTR = 8
            Dim SafeArrayBoundDt As SAFEARRAYBOUND
        
            SafeArrayBoundDt.lLBound   = 0
            SafeArrayBoundDt.cElements = 100
        
            psa = SafeArrayCreate(%VT_BSTR, 1, SafeArrayBoundDt)
        
            If psa = 0 Then
               Print "Error creating SafeArray."
            Else
               Print "Successfully created SafeArray."
            End If
        
            Dim x(0:1)  As Long
            Dim xPtr    As Long   ' No pointer here - will be passed by reference.
            Dim Datastr As AsciiZ Ptr
            Dim TextStr As String
        
            x(0) = 0
            xPtr = VarPtr(x(0))
        
            TextStr = "Hello"
        
            DataStr = VarPtr(TextStr)
        
            Print SafeArrayPutElement(psa, xPtr, DataStr)
        Tried different variations with AsciiZ and String ptr but I get
        this strange result. It should print 0




        ------------------
        So here we are, this is the end.
        But all that dies, is born again.
        - From The Ashes (In This Moment)

        Comment

        Working...
        X