Forum Discussion
Hello Rob,
In your example of the executable that loads the DLL into an assembly ("SampleAssembly") it looks like the EXE is a console program. Doesn't it need some MessageLoop to keep the EXE active and alert for requests?
The sample code in my previous message belongs to the window application. TestComplete cannot access the AppDomain object of console applications. Sorry for confusing you.
As for a more detailed example of the necessary application code, you can try doing any of the following (in the examples below, I use the UserClassLib.dll library shipped along with TestComplete's Using .NET Classes example):
1. You can add a reference to your DLL into a sample application project and create an object that returns a reference to an instance of a class declared in your DLL:
using System;
using System.Windows.Forms;
using UserClassLib;
namespace DLLSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CSalary SalaryObj = new CSalary();
}
}
}
2. Or you can create an application containing an object that loads your DLL in the application domain:
using System;
using System.Windows.Forms;
using System.Reflection;
namespace DLLSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Assembly SampleAssembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "UserClassLib.dll");
}
}
}
While the sample application is running and the SalaryObj (or SampleAssembly) object exists in the application, you can access the namespaces defined in your DLL via the AppDomain(…).dotNet property from TestComplete tests (or TestComplete’s script extensions). For example:
function Main()
{
var p = Sys.Process("DLLSample");
var dotNETObj = p.AppDomain("DLLSample.exe").dotNet;
var Salary = dotNETObj.UserClassLib.CSalary.zctor();
Salary.Initialize(6000, 0, 0, 0);
...
}
Please let us know whether any of these is helpful.
Thank you.