WIth the help of Jaafar, I'm trying to learn how to use the
And managed to get the following working:
I cannot, however, get the second example to work. The returning result is 0, though it clearly shouldn't be:
Any guidance would be appreciated.
DispCallFunc
API with 64 bit API. I have been trying to work my way through the examples at the following tutorial: Windows API DispCallFunc as function pointer in VBAAnd managed to get the following working:
VBA Code:
Private Declare PtrSafe Function DispCallFunc Lib "oleAut32.dll" (ByVal pvInstance As LongPtr, ByVal offsetinVft As LongPtr, ByVal CallConv As Long, ByVal retTYP As Integer, ByVal paCNT As Long, ByRef paTypes As Integer, ByRef paValues As LongPtr, ByRef retVAR As Variant) As Long
Public Sub someFunction()
MsgBox "DispCallFunc just called me!"
End Sub
'
Public Sub tester()
'
Dim DispCallFuncResult As Long
Dim result As Variant: result = vbEmpty
DispCallFuncResult = DispCallFunc( _
0, _
AddressOf someFunction, _
CLng(4), _
VbVarType.vbEmpty, _
0, _
0, _
0, _
VarPtr(result))
End Sub
I cannot, however, get the second example to work. The returning result is 0, though it clearly shouldn't be:
VBA Code:
Private Declare PtrSafe Function DispCallFunc Lib "oleAut32.dll" (ByVal pvInstance As LongPtr, ByVal offsetinVft As LongPtr, ByVal CallConv As Long, ByVal retTYP As Integer, ByVal paCNT As Long, ByRef paTypes As LongPtr, ByRef paValues As LongPtr, ByRef retVAR As Variant) As Long
Public Function someFunction(ByVal x As Double, ByVal y As Double) As Double
someFunction = x * y
End Function
'
Public Sub tester()
'
Dim DispCallFuncResult As Long
Dim result As Variant: result = vbEmpty
'
Dim x As Double: x = 1.234
Dim y As Double: y = 9.876
'
Dim vx As Variant: vx = CVar(x)
Dim vy As Variant: vy = CVar(y)
'
Dim varTypes(0 To 1) As Long
varTypes(0) = VarType(vx)
varTypes(1) = VarType(vy)
'
Dim varPointers(0 To 1) As LongPtr
varPointers(0) = VarPtr(vx)
varPointers(1) = VarPtr(vy)
'
DispCallFuncResult = DispCallFunc( _
0, _
AddressOf someFunction, _
CLng(4), _
VbVarType.vbDouble, _
2, _
VarPtr(varTypes(0)), _
VarPtr(varPointers(0)), _
VarPtr(result))
'
MsgBox result
End Sub
Any guidance would be appreciated.