EVENT_OBJECT_DESTROY Notes

[This is preliminary documentation and subject to change.]

In the case of window objects only, both the parent and the child send this event. The child window sends the event when it is destroyed, and the parent sends it after destruction is complete. Note that the child window is responsible for sending this event before the parent. It is assumed that all the children of an object are destroyed when the parent is destroyed. This event is also sent when an application is shutting down.

Calling IAccessible properties at this point can cause a crash—in particular, when the call references a DLL that is unloaded first. Calling the IAccessible::get_accName method is a good example. It eventually calls SysAllocString, a Win32 API call. exported by oleaut32.dll. If oleaut32.dll is unloaded first, it crashes. Therefore, upon receiving the EVENT_OBJECT_DESTROY, call these properties only for visible windows. Only invisible windows are dangerous because some of them are destroyed after a majority of the system has already been destroyed. To get the name of the invisible window, try using GetWindowText, a Win32 API call.