Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2003, 11:47 AM
Registered User
 
Join Date: Aug 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default UCOMIRunningObjectTable.GetObject

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");
                }
            }
        }
    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
GetObject jdhock8865 Visual Basic 2005 Basics 2 November 3rd, 2008 09:29 PM
getobject() failure- recent Loralee Access 2 November 24th, 2006 02:29 PM
getObject() and shell() question using automation juneBugz Access VBA 0 August 29th, 2005 08:46 PM
GetObject Trap bostek VBScript 2 November 24th, 2004 02:39 AM
why GetObject with IIS is not working alyeng2000 ASP.NET 1.x and 2.0 Application Design 0 September 15th, 2004 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.