Brill, thanks mate. I'll look into the IISSample.LookupTable.
Printable View
Code:sName = "Hide" ' << change to another known method in the class
does it can get more disp id?
Code:Dim vv(2) As Long
Dim lDispIDList(2) As Long
Dim S(2) As String
S(0) = "Caption"
S(1) = "aa"
S(2) = "Hide"
vv(0) = StrPtr(S(0))
vv(1) = StrPtr(S(1))
vv(2) = StrPtr(S(2))
Call c.CallFunction_COM(IID_Dispatch, IDispatchIDsOfNames, CR_LONG, CC_STDCALL, VarPtr(aGUID(0)), VarPtr(vv(0)), 1&, 0&, VarPtr(lDispIDList(0)))
i only use this code can hide form2,but pIndex = DispCallFunc(*)<>0 why?
i do GetLastDllErr
do you have a full sample?
The second similar question, is it possible to write the event callback on the VB6 class object, implement the IUnknown interface, and delete all the redundant interfaces in the class?
This way I don't have to create a module with each callback and implement the virtual IUnknown interface.
, ParamArray ArgP() As VariantCode:Function CallComByMethod(Obj1 As Object, MethodName As String, ParamArray ArgP() As Variant) As Variant
Const IUnknownRelease As Long = 8&
Const IDispatchIDsOfNames As Long = 20&
Const IDispatchInvoke As Long = 24&
Dim IID_Dispatch As Long, lDispID As Long
Dim aGUID(0 To 3) As Long, sName As String
Dim DP As DISPPARAMS, vRtn As Variant
Dim C As New cUniversalDLLCalls
sName = "{00020400-0000-0000-C000-000000000046}" ' GUID for IDispatch
C.CallFunction_DLL "ole32.dll", "IIDFromString", STR_NONE, CR_LONG, CC_STDCALL, StrPtr(sName), VarPtr(aGUID(0))
' ensure object implements IDispatch...
C.CallFunction_COM ObjPtr(Obj1), 0&, CR_LONG, CC_STDCALL, VarPtr(aGUID(0)), VarPtr(IID_Dispatch)
If IID_Dispatch <> 0& Then
Erase aGUID()
Call C.CallFunction_COM(IID_Dispatch, IDispatchIDsOfNames, CR_LONG, CC_STDCALL, VarPtr(aGUID(0)), VarPtr(MethodName), 1&, 0&, VarPtr(lDispID))
If lDispID > 0 Then
Dim Arg() As Variant
Dim i As Long, ub As Long
ub = UBound(ArgP)
If ub <> -1 Then
ReDim Arg(ub)
For i = 0 To ub
'以相反的顺序填充它并确保每个参数的正确 vartype
Arg(i) = ArgP(ub - i)
'Arg(i) = VarPtr(ArgP(ub - i))
Next
DP.rgVarg = VarPtr(ArgP(0))
'DP.rgVarg = VarPtr(Arg(0))
DP.cArgs = ub + 1
End If
Call C.CallFunction_COM(IID_Dispatch, IDispatchInvoke, CR_LONG, CC_STDCALL, lDispID, VarPtr(aGUID(0)), 0&, 1&, VarPtr(DP), VarPtr(vRtn), 0&, 0&)
Debug.Print "return value if any: "; vRtn
CallComByMethod = vRtn
Else
Debug.Print "method ["; sName; "] not found"
End If
' Release the interface at some point. QueryInterface calls AddRef internally
C.CallFunction_COM IID_Dispatch, IUnknownRelease, CR_LONG, CC_STDCALL
End If
End Function
How about reversing the order of the parameters, because my parameters also return values, so I can't create a variant copy.