Announcement

Collapse
No announcement yet.

The next piece in my puzzle... iActiveScript with Controls...

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

  • The next piece in my puzzle... iActiveScript with Controls...

    Ok well I am starting to "white board" a method for doing this...

    I have been a VB programmer for 8 years now and I am come to know and love the "CallByName" function. It is a crucial part of a scripting engine. So I found an amazing piece of code by Jose.

    Code:
    FUNCTION TB_CallByName ( _
        BYVAL pthis AS DWORD, _                                    ' *IDispatch
        BYVAL vNameOrId AS VARIANT, _                              ' Name or identifier
        BYVAL callType AS LONG, _                                  ' Call type
        BYREF vParams() AS VARIANT, _                              ' Array of variants
        BYREF vResult AS VARIANT, _                                ' Variant result
        BYREF pex AS EXCEPINFO _                                   ' EXCEPINFO structure
        ) EXPORT AS LONG                                           ' Error code
    
        DIM dw_puArgErr AS DWORD, DISPID_PROPERTYPUT AS LONG, IID_NULL AS GUID
        DIM vArgs(0) AS VARIANT, udt_DispParams AS DISPPARAMS
        DIM hr AS LONG, strName AS STRING, DispID AS LONG
        DIM nParams AS LONG, i AS LONG, idx AS LONG
    
        ' Check for null pointer
        IF pthis = 0 THEN FUNCTION = %E_POINTER : EXIT FUNCTION
    
        ' Get the DispID
        IF VARIANTVT(vNameOrId) = %VT_BSTR THEN
           strName = UCODE$(VARIANT$(vNameOrId))
           hr = IDispatch_GetIDOfName(pthis, strName, DispID)
           IF hr THEN
              FUNCTION = hr
              EXIT FUNCTION
           END IF
        ELSE
           DispID = VARIANT#(vNameOrId)
        END IF
    
        ' Copy the array in reversed order
        IF VARPTR(vParams()) THEN
           nParams = UBOUND(vParams) - LBOUND (vParams) + 1
           IF nParams > 0 THEN
              REDIM vArgs(nParams - 1)
              idx = nParams - 1
              FOR i = LBOUND(vParams) TO UBOUND(vParams)
                 IF VARIANTVT(vParams(i)) = %VT_EMPTY THEN
                    vArgs(idx) = ERROR %DISP_E_PARAMNOTFOUND
                 ELSE
                    vArgs(idx) = vParams(i)
                 END IF
                 DECR idx
                 IF idx < 0 THEN EXIT FOR
              NEXT
           END IF
       END IF
    
       IF CallType = 4 OR CallType = 8 THEN  ' %DISPATCH_PROPERTYPUT and %DISPATCH_PROPERTYPUTREF
          DISPID_PROPERTYPUT = -3
          udt_DispParams.CountNamed = 1
          udt_DispParams.NamedDispId = VARPTR(DISPID_PROPERTYPUT)
       END IF
    
       udt_DispParams.CountArgs = nParams
       IF nParams > 0 THEN udt_DispParams.VariantArgs = VARPTR(vArgs(0))
    
       FUNCTION = IDispatch_Invoke(pthis, DispID, IID_NULL, 0, CallType, udt_DispParams, vResult, pex, dw_puArgErr)
    
    END FUNCTION
    So now, lets say I want to call a function method from my own class... Would I just set my class to inherit iDispatch? and then pass the pointer into the function and call methods? How would I correctly pass arrays... I know how to do this in VB6, but I am still a "noob" in PB...
Working...
X