It's too bad that WinRT doesn't implement IDispatch. I've found this old code (now archived in the Wayback Machine) showing how to call the Invoke method of IDispatch. It was using "olelib" but it works just fine with "oleexp" instead:
Code:Enum InvokeCall PropGet = INVOKE_PROPERTYGET PropLet = INVOKE_PROPERTYPUT PropSet = INVOKE_PROPERTYPUTREF Method = INVOKE_FUNC End Enum '------------------------------------------------------------------ ' Procedure : CallByNameEx ' Purpose : Calls an object function/property by name or DISPID ' taking the parameters as ParamArray. '------------------------------------------------------------------ ' Public Function CallByNameEx(Object As Object, ByVal Name As Variant, ByVal CallType As InvokeCall, ParamArray Args() As Variant) As Variant Dim lDISPID As Long Dim tDISPPARAMS As oleexp.DISPPARAMS Dim avParams() As Variant Dim lNamedParam As Long Dim lIdx As Long Dim lParamCount As Long ' Get the DISPID lDISPID = GetDISPID(Object, Name) If Not IsMissing(Args) Then ' Get parameters count lParamCount = UBound(Args) - LBound(Args) ReDim avParams(0 To lParamCount) ' Copy the array in reverse order For lIdx = 0 To lParamCount VariantCopy avParams(lParamCount - lIdx), Args(lIdx) Next With tDISPPARAMS .cArgs = lParamCount + 1 .rgPointerToVariantArray = VarPtr(avParams(0)) End With If CallType = INVOKE_PROPERTYPUT Or _ CallType = INVOKE_PROPERTYPUTREF Then lNamedParam = DISPID_PROPERTYPUT With tDISPPARAMS .cNamedArgs = 1 .rgPointerToLONGNamedArgs = VarPtr(lNamedParam) End With End If End If CallInvoke Object, lDISPID, CallType, tDISPPARAMS, CallByNameEx End Function '------------------------------------------------------------------ ' Procedure : GetDISPID ' Purpose : Returns the DISPID of a member '------------------------------------------------------------------ ' Private Function GetDISPID(ByVal Object As oleexp.IDispatch, Name As Variant) As Long ' NULL interface ID Dim IID_NULL As oleexp.UUID If IsNumeric(Name) Then ' Return the value GetDISPID = CLng(Name) Else ' Get the DISPID using the name Object.GetIDsOfNames IID_NULL, CStr(Name), 1, 0, GetDISPID End If End Function '------------------------------------------------------------------ ' Procedure : CallInvoke ' Purpose : Calls the Invoke method of IDispatch '------------------------------------------------------------------ ' Private Sub CallInvoke(ByVal Object As oleexp.IDispatch, ByVal DISPID As Long, ByVal CallType As Long, Params As oleexp.DISPPARAMS, Result As Variant) ' NULL interface ID Dim IID_NULL As oleexp.UUID ' Exception Error info Dim tEXCEPINFO As oleexp.EXCEPINFO ' Argument that produced the error Dim lArgErr As Long ' Call result Dim lResult As Long ' Invoke method/property lResult = Object.Invoke(DISPID, IID_NULL, 0, CallType, Params, VarPtr(Result), tEXCEPINFO, lArgErr) If lResult <> 0 Then ' There was an error ' If the error is DISP_E_EXCEPTION ' we can get the error description ' from the EXCEPINFO structure. If lResult = DISP_E_EXCEPTION Then With tEXCEPINFO ' Raise the error using ' the EXCEPINFO data Err.Raise .wCode, .Source, .Description, .HelpFile, .dwHelpContext End With Else ' Raise the error using the HRESULT Err.Raise lResult End If End If End Sub




Reply With Quote
