I have been trying to write a utility which will walk through the running objects table and return the object based on the class name and window handle. I have most of the code so far, but now I am stuck. Whenever I walk through the ROT, my code only grabs the first instance opened of the application. It does output x times where x is the number of acad apps opened. I wish for it to iterate through each instance of AutoCAD and output something to each one. Any MS gurus out there that can tell me how to do this? I am pretty new to ROT and monikers, so if you can just point me to the right objects/methods, I would be forever grateful!
Thanks,
Wes
Code:
using System;
using System.Runtime.InteropServices;
using AutoCAD;
namespace Hei.Utility.COMConnectors {
public class ROTWalker {
[DllImport ("Ole32.Dll")]
public static extern int CreateBindCtx ( int reserved, out UCOMIBindCtx
bindCtx );
public ROTWalker() {
UCOMIBindCtx bc;
ROTWalker.CreateBindCtx ( 0, out bc );
UCOMIRunningObjectTable rot;
bc.GetRunningObjectTable ( out rot );
UCOMIEnumMoniker enumMkr;
rot.EnumRunning ( out enumMkr );
UCOMIMoniker[] elts = new UCOMIMoniker[1];
int cnt;
int ret;
Object o = new object();
AcadApplication acadApp;
while ( ( ret = enumMkr.Next ( 1, elts, out cnt ) ) >= 0 && ( cnt > 0 ) ) {
string displayName;
elts[0].GetDisplayName ( bc, null, out displayName );
Console.WriteLine(displayName);
rot.GetObject(elts[0], out o);
if (displayName == "!{1365A45F-0C8F-4806-A26A-6B22AD37EC66}") {
acadApp = ((AcadApplication) o);
acadApp.ActiveDocument.Utility.Prompt("hehehehe\n\n");
}
}
}
}
}