Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
table_driven.vb
Option Explicit
Private Declare Function DispCallFunc Lib "OleAut32.dll" _
(ByVal pvInstance As Long, _
ByVal oVft As Long, _
ByVal cc As Long, _
ByVal vtReturn As Integer, _
ByVal cActuals As Long, _
ByVal prgvt As Long, _
ByVal prgpvarg As Long, _
ByVal pvargResult As Long) As Long
Enum tagCALLCONV
CC_FASTCALL = 0
CC_CDECL = 1
CC_MSCPASCAL = CC_CDECL + 1
CC_PASCAL = CC_MSCPASCAL
CC_MACPASCAL = CC_PASCAL + 1
CC_STDCALL = CC_MACPASCAL + 1
CC_FPFASTCALL = CC_STDCALL + 1
CC_SYSCALL = CC_FPFASTCALL + 1
CC_MPWCDECL = CC_SYSCALL + 1
CC_MPWPASCAL = CC_MPWCDECL + 1
CC_MAX = CC_MPWPASCAL
End Enum
Enum s
SS1 = 0
SS2
End Enum
Sub test()
Dim ret As Long
Dim funcRet As Variant
Dim fp As Variant
fp = Array(AddressOf sub1, AddressOf sub2)
ret = DispCallFunc(0, fp(s.SS1), _
tagCALLCONV.CC_STDCALL, VbVarType.vbEmpty, _
0, 0, 0, VarPtr(funcRet))
End Sub
Sub sub1()
Debug.Print ("sub1")
End Sub
Sub sub2()
Debug.Print ("sub2")
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment