How to catch the event of " close the document" ?

Hello,

Need help.

I want to catch the event of "close the part document" in C++.

My purpose is to clear up the memeory, which have been open and disconnect the Add-in before closing the PartDoc.

I have tried to catch the event "swAppCommandCloseNotify" and "swAppDestroyNotify", but it doesn't work.

Thank you.

SolidworksApi macros