Hello,
I need to control a launched app for auto testing purposes. So I have the
following driver program "A" that launches simple app "B".
Driver program A launches app B successfully & sets a reference to app B's
Dll.
It has a button control event handler to initiate the controlling of App B
as follows:
private void btnControlApp_Click(object sender, System.EventArgs e)
{
Form OtherAppMainUI = null;
CScripting.GetMainAppUI(ref OtherAppMainUI);
MessageBox.Show(OtherAppMainUI.ToString());
}
Launched app B is a simple EXE & DLL where the EXE has a reference to the
DLL.
Inside app B's DLL, it exposes exactly this one object, containing a static
variable to hold a reference to the main app B's UI form:
public class CScripting
{
public static Form m_MainUI = null;
public CScripting(ref Form MainUI)
{
m_MainUI = MainUI;
}
public static void GetMainAppUI(ref Form OutForm)
{
OutForm = m_MainUI;
}
}
The main form in app B's EXE declares a variable from the app B's dll:
private CScripting m_DllObj = null;
and in constructor of app B's main form, we have the following code which
instantiates the object from app B's dll, passing in the reference to the
main app B's form:
public TstAutoControl()
{
InitializeComponent();
Form CurrentUI = this;
m_DllObj = new CScripting(ref CurrentUI);
}
The question is, why doesn't this work? When the code in the driver
program's button click event runs, the variable OtherAppMainUI never gets
the reference and the MessageBox.Show() method crashes because the object
reference is not set. I thought this would work since app B's dll object's
variable in question is static ... and therefore be available accross object
instantiations, what gives? How can I make the driver program A receive a
reference to the main form in app B? I realize I'm trying to pass this form
reference accross processes, so how do I pass info from 1 process to
another?
TIA,
--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com