How to Get Specyfic Object from ROT
- From: xtoff <krzysztof.kozmic@xxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 13 Feb 2007 11:06:21 +0100
Hello
I know that there were posts about it but
none of it answers my specific question.
I'm automating from my c# application other
app with com based interface.
It puts its Application object in ROT so that
I can get it from there and not have to instantiate
a new one.
To make it simple let's say that the app i'm automating
is called TW4Win.
Given there are alredy several instances open, I wanna do the following:
1. Be able to present a list of them to user, so that user can select
the instance he wants to use for automating.
2. Get TW4Win.Application object from ROT that is bound to THIS window
that user selected.
3. Hide this window (with
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
Here's what i do and where i stuck:
1. To get active windows and present 'em to the user:
Process[] p = Process.GetProcessesByName("TW4Win");
//h is of type IntPtr[]
h[0] = p[0].MainWindowHandle;//and so on
2. To get the list of TW4Win.Application from ROT i use following method
[STAThread]
public Dictionary<string, TW4Win.Application> GetRunningObjectTable()
{
IBindCtx bindCtx;
Dictionary<string, TW4Win.Application> items = new Dictionary<string, TW4Win.Application>();
IRunningObjectTable rot;
IEnumMoniker monikerEnum;
IMoniker[] monikers = new IMoniker[1];
IntPtr numFetched;
string description = string.Empty;
Object o;
TW4Win.Application app;
GetRunningObjectTable(0,out rot);
rot.EnumRunning(out monikerEnum);
monikerEnum.Reset();
while (monikerEnum.Next(1, monikers, IntPtr.Zero)==0)
{
try
{
rot.GetObject(monikers[0], out o);
if (o is TW4Win.Application)
{
CreateBindCtx(0, out bindCtx);
monikers[0].GetDisplayName(bindCtx, null, out description);
app = o as TW4Win.Application;
app.ActiveApplication = true;
items.Add(description, o as TW4Win.Application);
}
}
catch { }
}
return items;
}
And here start my problems:
1. No mater how many instances are running items contains always only one element. Its due the fact, that ALL TW4Win.Application instances in
ROT seem to be the same! Both Object.Equals(); and Object.ReferenceEquals(); return true when comparing any two of them.
Moreover I have no idea how to determine which window this object belongs to.
Thank you in advance for any help.
.
- Follow-Ups:
- Re: How to Get Specyfic Object from ROT
- From: Igor Tandetnik
- Re: How to Get Specyfic Object from ROT
- Prev by Date: Change from wmp 6.4 to wmp 9 series in my ocx
- Next by Date: Re: How to register TypeLib for DirectShow filter?
- Previous by thread: Change from wmp 6.4 to wmp 9 series in my ocx
- Next by thread: Re: How to Get Specyfic Object from ROT
- Index(es):
Relevant Pages
|