I am building a component using C# (but I suppose this question would apply
to VB as well). At design time, I want this component to be able to access
the development environment. As I understand it, the canonical way to do
this is to get a reference to EnvDTE.DTE. Unlike macros and add-ins, where
such a reference is provided free of charge, the only way I have found to
get a reference is using the following code:
EnvDTE.DTE dte;
dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal .GetActiveObject
("VisualStudio.DTE")
which extracts the reference from the Running Objects Table. This is great
as long as you have only one instance of Visual Studio running at the time.
But what about when there is more than one instance running? Unless I've
got this all wrong, the above code extracts the reference of the first
instance in the table, which is not necessarily the instance that the my
component is in. In my scouring of newsgroups (good ol' Google!) I have
seen vague references to iterating through the entries in the Running
Objects Table to find the one you want, but I don't see any way to be able
to tell when the object in that table is *this* instance. Is there
anything that can be accessed from inside a component's code to uniquely
identify *this* instance, as opposed to those other two instances over
there? I want to be certain that the DTE reference I've found refers to
me, not some other instance over there.
Regards,
- Alex VanderWoude