addressOf operator evaluates to a long (at least on 32 Bit Windows versions) which usually are used for used for Win API callbacks (such as needed for EnumWindows or EnumChildWindows). option explicit
sub XX()
dim cbAddr as long
'
' addressOf is an operator, not a function.
' Therefore, the following is not possible,
' it causes a "Compile error, Syntax error"
'
' cbAddr = addressOf callBackSub
'
' However, cbAddr can be assigned the address of
' a call-back function or sub with the following
' construct:
cbAddr = getAddressOfCallback(addressOf callBackSub)
end sub
function getAddressOfCallback(addr as long) as long
getAddressOfCallback=addr
end function
sub callBackSub()
msgBox "xyz"
end sub
addressOf is an operator, it cannot be directly used to use the value it evaluates to directly, the following would not work: dim addr as longPtr addr = addressOf(…)
vba.int(…), it becomes possible: dim addr as longPtr addr = vba.int(addressOf(…))