デバッグ中の自分のアプリケーションから、VS2005のデバッガインスタンスを取得する。
うまくいくが、DebuggerEventsが発生しない?
http://msdn.microsoft.com/ja-jp/library/envdte.debuggerevents_events.aspx

[DllImport("ole32.dll")]
public static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);

[DllImport("ole32.dll")]
public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);

private static object GetMSDEVFromGIT(string strProgID)
{
IRunningObjectTable prot;
IEnumMoniker pMonkEnum;
try
{
GetRunningObjectTable(0, out prot);
prot.EnumRunning(out pMonkEnum);
pMonkEnum.Reset(); // Churn through enumeration.
IntPtr fetched = IntPtr.Zero;
IMoniker[] pmon = new IMoniker[1];
while (pMonkEnum.Next(1, pmon, fetched) == 0)
{
IBindCtx pCtx;
CreateBindCtx(0, out pCtx);
string str;
pmon[0].GetDisplayName(pCtx, null, out str);
if (str == strProgID)
{
object objReturnObject;
prot.GetObject(pmon[0], out objReturnObject);
object ide = (object)objReturnObject;
return ide;
}
}
}
catch
{
return null;
}
return null;
}// End CodeSample

///


///
///

private static void initializeDebugger()
{
//親プロセスのPIDを取得する
PerformanceCounter pc = new PerformanceCounter("Process", "Creating Process ID", Process.GetCurrentProcess().ProcessName);
int pID = (int)pc.NextValue();
//VS2005のMonikerを生成
string strMoniker = "!VisualStudio.DTE.8.0:" + pID.ToString();
//DTEインスタンスの取得
EnvDTE._DTE ide = (EnvDTE._DTE)GetMSDEVFromGIT(strMoniker);
if (ide != null)
{
Console.WriteLine(ide.ActiveDocument.FullName);
}
}