Announcement

Collapse
No announcement yet.

SafeArrayCreate

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

  • Steven Pringels 3
    replied
    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




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

    Leave a comment:


  • Steven Pringels 3
    replied
    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

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

    Leave a comment:


  • Knuth Konrad
    replied
    Steven,

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

    Knuth

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

    Leave a comment:


  • Steven Pringels 3
    started a topic SafeArrayCreate

    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.

    ------------------
Working...
X