How to Get Specyfic Object from ROT



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.

.



Relevant Pages

  • Re: Code correctness, and testing strategies
    ... I did do it in a mostly top-down way, but didn't stop the BDD ... get a skeleton app working ... writing both (and automating them in a test suite that runs without ... missing acceptance tests? ...
    (comp.lang.python)
  • Re: Automation of MS Word
    ... >> I have a VB.Net app that words just fine when automating ... if I install the app ... >> MS Office Small Business Edition 2003, ... >> Jason. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to develop a PPC application
    ... >what is your programming experience level. ... an app. ... Be careful about overly automating, as in automatically switching fare ...
    (microsoft.public.pocketpc.developer)
  • Re: User action logging
    ... I did it by automating the additon of the logging to the forms by copying ... But for a completer app that may not be so ... code to every click event) log the user activty within my app? ...
    (microsoft.public.vb.general.discussion)
  • Re: I appear to be gravitationally challenged
    ... is an app to take text off of the clipboard, ROT it, then paste it back ... I can probably write a VB app to do that. ... The first is that I'm using Noscript in Firefox and by default scripts ... scripts for all local files, no matter where they were copied from. ...
    (uk.rec.sheds)

Quantcast