ha ha..after i read your comment about the leaks it came to my mind and i was just trying to think out loud. this is what i have be mind:
1> from the instance the dll is deployed some handle counter/tracker keeps track of all the handles that are created (this part is internal there is no outside excel interface).
so even in situations like this " If you use a function that takes an argument that is a function returning a handle " the "handle tracker" is counting and keeping track of the handles. no matter where a handle gets created (whether
in c++ code or in excel cell) as long as a handle is created and memory is assigned for it the handle tracker will keep an account of it.
2> now an excel interface function (say list() ) will have functionality of listing out all the handles that are present/created.
3> another excel interface function (say delete() ) will have the functionality of deleting handles that are listed using the list() function.
i am not sure how easy/hard it is to implement step 1. If step 1 is possible then step 2 and 3 may be relatively easy to implement.