Can anyone tell me how to change this C# code to grab all instances of an
application that is running? Right now, it only will output to the first
opened single document interface application n times (n being the number of
the same SDI app running). My end goal is to be able to pass in a windows
handle and be able to get the appropriate application instance. I know this
might be a C# newsgroup question, but almost all of this code has been taken
from this newsgroup. If I get it to work, I will post source to here so
that all may use. This might be a stupid question, so if someone has a good
tutorial link they think might help me, I would be very grateful for this as
well. Thanks to anyone who takes a look!
Wes
using System;
using System.Runtime.InteropServices;
using SomeSDICom;
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();
SomeSDIComApplication app;
string displayName;
while ( ( ret = enumMkr.Next ( 1, elts, out cnt ) ) >= 0 && ( cnt >
0 ) ) {
elts[0].GetDisplayName ( bc, null, out displayName );
Console.WriteLine(displayName);
//I'm not sure what this next line of code does, but I couldn't get it to
work
// elts[0].BindToObject(bc, null, ref null, out o);
//why does this next line always connect to the same instance, even though
there are
//different monikers?
rot.GetObject(elts[0], out o);
if (displayName == "!{1365A45F-0C8F-4806-A26A-6B22AD37EC66}") {
app = ((SomeSDIComApplication) o);
//this is the line that prints out to the first instance.
//I have been trying to get it to work with AutoCAD
//but I would like to write something generic enough to work with Word or
excel as well
app.OutputSomething("Output to this running instance.\n\n");
}//if
}//while
}//constructor
}//class
}//ns
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----