Hooking global Visual Studio events

[Go to main articles index]

Just one simple reminder, but which consumed many, many hours of my time. If you obtain a pointer to a _WindowEvents object from the DTE.Events object, and you register with it so that you will receive such events, be sure to keep around a reference to the _WindowEvents object itself!

If you release the reference to the original _WindowEvents object, you will not receive any notification at all, even if nothing seems to fail. The reason is that the _WindowEvents interface reference you get is not a reference to a global object, but a new object generated for your notification requests, and it will be destroyed if you don't keep a reference around.

I guess this is also the case with other _Events objects.