I'm a little closer. I thought this was working.
MapApplication acmapapp = HostMapApplicationServices.Application;
Project.ProjectModel myproj = acmapapp.ActiveProject;
Query.QueryModel atsq = myproj.CreateQuery();
atsq.Clear();
atsq.Mode = Constants.QueryType.QueryDraw;
// query root
Query.QueryBranch qroot = acgis.Query.QueryBranch.Create();
Query.LocationCondition loccond = new acgis.Query.LocationCondition();
loccond.LocationType = Constants.LocationType.LocationCrossing;
Point3dCollection atspts = new Point3dCollection();
// window pts in utm
atspts.Add(new Point3d(_br_utm.X, _br_utm.Y, 0));
atspts.Add(new Point3d(_br_utm.X, _tl_utm.Y, 0));
atspts.Add(new Point3d(_tl_utm.X, _tl_utm.Y, 0));
atspts.Add(new Point3d(_tl_utm.X, _br_utm.Y, 0));
// boundary
Query.PolygonBoundary pb = new Query.PolygonBoundary(atspts);
loccond.Boundary = pb;
// branch
Query.QueryBranch qloc = Query.QueryBranch.Create();
qloc.AppendOperand(loccond);
// append branch to root
qroot.AppendOperand(qloc);
Project.DrawingSet ds = myproj.DrawingSet;
ds.AttachDrawing("some dwg file");
atsq.Define(qroot);
ObjectIdCollection atslines = new ObjectIdCollection();
atslines = atsq.Execute(ds);
ds.DetachDrawing("same dwg file as above");
qroot.Clear();
qloc.Clear();
atsq.Clear();
myproj.Dispose();
// acmapapp.ErrorStack.EntriesCount = 1 at this point (37 object(s) queried from...
acmapapp.ErrorStack.Clear(); <-------------------- seems to work
acmapapp.Dispose();
But, if I try an UNDO, the message appears. It is obviously sent somewhere other than ErrorStack.