Search notes:

IUnknown (VBA)

Although Windows/development/COM/IUnknown seems to play a rather important role in VBA, it is not mentioned in the VBA specification.

Call function when Excel exits

On Github, I found an interesting gist by kumatti1 that somehow makes use of the IUnknown interface: after running main in Excel, the function release will be executed when Excel is closed.
Unfortunately, I don't really get how this works …
'
'      https://github.com/kumatti1/COM_Test/blob/master/Module1.bas
'

option  explicit
declare ptrSafe sub RtlMoveMemory lib "kernel32" (dest as any, src as any, byVal length as longPtr)

private pVtbl        as longPtr
private func(0 to 2) as longPtr
private iUnk         as IUnknown


private function release(this as longPtr) as long ' {
    msgBox "Exiting Excel"
end function ' }

sub main() ' {


 '  if iUnk is nothing then
 '     debug.print "is nothing"
 '  end if

    debug.print "iUnk:  " & varPtr(iUnk)

    func(2) = vba.int(addressOf release)

    pVtbl  = varPtr(func(0))

    RtlMoveMemory iUnk, varPtr(pVtbl), 4

end sub ' }
Github repository about-VBA, path: /IUnknown/release.bas

stdole

It seems(!) that IUnknown is exhibited through the stdole «library»
dim unk as stdole.iUnknown

See also

A pointer to the IUnknown interface of an object is returned by the objPtr() function.
IUnknown
IDispatch (VBA)
IEnumVARIANT

Index