0

I'm using COM DTE in order to make an application where, when a document in a Visual Studio Solution is saved, a certain action is executed. For instance if a document in the solution is saved, a new compilation is triggered.

I'm using C++ but the only documentation that I was able to find out is written C# [DTE events][https://learn.microsoft.com/en-us/dotnet/api/envdte.events?view=visualstudiosdk-2017].

I tried several methods of DTE objects, but I was not able to find out the event that is triggered when a document is saved, for example using [DocumentEvents][https://learn.microsoft.com/en-us/dotnet/api/envdte.events.documentevents?view=visualstudiosdk-2017] (I omit error checking for simplicity):

    TComPtr<EnvDTE::Events> events;
    DTE->get_Events(&events);

    TComPtr<EnvDTE::_DocumentEvents> docsEvents;
    TComPtr<EnvDTE::Document> doc;
    events->get_DocumentEvents(doc, &docsEvents);

Then I'm blocked at docsEvents, that I expected that gives me the events to control (connecting them to handlers, using __hook for instance).

I was therefore wondering what was the correct call sequence to access the events of the documents in the solution (especially the one that is launched when a document of the solution is saved) (the documentation in C++ is relatively poor)

Matt
  • 31
  • 4

1 Answers1

0

You are on the right path. Now just subscribe to the DocumentSaved event.

Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66