Hi,
I'm currently investigating the possibility of upgrading an existing website
(ISAPI written in Delphi) to an ASP.NET 2.0 application (Visual Studio
2005 - C#).
The website itself communicates with an executable (ColPro.exe) that support
COM+.
The idea is that for every user (ASP.NET session) the ColPro.exe should be
launched, that the user can set individual properties and make some
calculations using one or more ASPX pages.
The ColPro.exe application should be closed when the ASP.NET session is
closed.
I managed to implement the basic idea using early and late binding (see code
below).
However, this code only works as long as you do not fire a postback. As soon
as a postback is fired (e.g. by pressing a button) the reference to the COM
object is lost.
Any idea on how we can store the reference to our COM object?
All help is really appreciated,
Alain
protected void Button2_Click(object sender, EventArgs e)
{
t = Type.GetTypeFromProgID("ColPro.App");
o = Activator.CreateInstance(t);
object invokeResult;
invokeResult = t.InvokeMember("SetDataSet",
BindingFlags.InvokeMethod, null, o, new Object[] {"ABS"});
invokeResult = t.InvokeMember("SetRegion",
BindingFlags.InvokeMethod, null, o, new Object[] {"PPC"});
invokeResult = t.InvokeMember("Open", BindingFlags.InvokeMethod,
null, o, null);
invokeResult = t.InvokeMember("SetPigColor",
BindingFlags.InvokeMethod, null, o, new Object[] {1,"P.Yellow 183"});
invokeResult = t.InvokeMember("Quit", BindingFlags.InvokeMethod,
null, o, null);
Marshal.ReleaseComObject(o);
}
protected void Button3_Click(object sender, EventArgs e)
{
cp = new ColPro.App();
Session.Add("MyCP", cp);
string str = "ABS";
Object o = str;
cp.SetDataSet(ref o);
str = "PPC";
Object p = str;
cp.SetRegion(ref p);
cp.Open();
p = "P.Yellow 183";
cp.SetPigColor(3, ref p);
double d = 0.123;
Object q = d;
cp.SetPigValue(3, ref q);
cp.Quit();
Marshal.ReleaseComObject(cp);
}
L-E Eriksson - 26 Jan 2007 13:17 GMT
Hello!
I guess you could use the session object to keep a reference to the instance
of the com-object. But why start a separate instance of colpro.exe for every
user? This will become cumbersome for your server quickly.
Note: I know nothing about colpro.exe
Regards
L-E Eriksson
> Hi,
>
[quoted text clipped - 77 lines]
> Marshal.ReleaseComObject(cp);
> }