I'm trying to create a connection to multiple instances of an open application (WRQ Reflection). Connecting to the first instance that was opened is fine using this:
Session appInstance = (Marshal.GetActiveObject("Reflection4.Session.8") as Session);
But I'd like to be able to connect to multiple instances. I've been doing alot of research and found some helpful links such as this, but that solution wont work in this situation as all the open instances have the same progId.
I've also tried looking at the window handles, which are obviously different for each instance. Using this:
Process[] processes = Process.GetProcessesByName("r4win");
foreach (Process p in processes)
{
IntPtr windowHandle = p.MainWindowHandle;
string handle = windowHandle.ToString();
MessageBox.Show(handle);
}
But I haven't been able to figure out how to create a connection to the window via the window handle.
Any assistance is appreciated.
Additional Code:
void TestROT()
{
// Look for open instances
string[] progIds = {"Reflection4.Session.8"};
List<object> instances = GetRunningInstances(progIds);
foreach (object refleObjs in instances)
{
Session session = refleObjs as Session;
session.Transmit("12345");
}
}
For this scenario, I have 2 instances of the target application running. In the above code, it will send the string 12345 to the same instance of the application, twice.
I need it to send 12345 to the first instance, and then 12345 to the second instance.