Skip to content

Instantly share code, notes, and snippets.

@otaks
Created July 6, 2017 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otaks/a5c2ed670857896cfad870818f8c713b to your computer and use it in GitHub Desktop.
Save otaks/a5c2ed670857896cfad870818f8c713b to your computer and use it in GitHub Desktop.
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