Events not workin when form is hidden (ActiveX)

Fax C++/ActiveX related topics

Moderator: Technical Support Team

Events not workin when form is hidden (ActiveX)

Postby kd-max » Mon Mar 22, 2010 4:13 pm

I using Fax.OCX with Delphi 2007 (Delphi 7 also). In windows service everything work properly except events. Windows messages not captured by OCX component even if hidden (service) form created. The same situation with VCL form application: if form is hidden then event handlers doesn't fired. If form is visible then everything is fine.
kd-max
 
Posts: 3
Joined: Mon Mar 22, 2010 4:01 pm

Re: Events not workin when form is hidden (ActiveX)

Postby dustinaleksiuk » Tue Mar 23, 2010 5:18 pm

In order to get this to work, we had to build a Windows Form that we use in our service. There are a few things we had to do:

1. Show our form. ie. myForm.Show(); (it never actually shows because it's running in a service)
2. Go to the properties of your windows service and select "Interact with the desktop" or whatever it's called.
3. To avoid some weird threading exceptions we had to decorate our start method in our ServiceBase class with the [STAThread] attribute, as well as set the apartment state on our thread in the OnStart. Some code is below:

Note: this is really irritating. How hard would it be to release this stuff as a regular DLL that doesn't need the windows message pump to function?


protected override void OnStart(string[] args)
{
Thread serviceThread = new Thread(Start);
serviceThread.SetApartmentState(ApartmentState.STA);
serviceThread.Start();
}

protected override void OnStop()
{
}

[STAThread]
private void Start()
{
try
{
Form1 form1 = new Form1();

form1.Show();

form1.SetCommPort("COM4", eventLog1);

for (int i = 0; i < 1; i++)
{
form1.SendFax("COM4", "94038000387", @"C:\fax_modem_test_blackice\test_tiffg3.tif", false, eventLog1);
}
}
catch (Exception e)
{
eventLog1.WriteEntry(e.ToString());
}
}
dustinaleksiuk
 
Posts: 3
Joined: Fri Feb 12, 2010 1:28 pm

Re: Events not workin when form is hidden (ActiveX)

Postby kd-max » Wed Mar 24, 2010 4:58 am

Hi,

Thank you very much dustinaleksiuk! Your post solved my problem. The problem really was in form.show() method. Now everything work properly and I can continue development of project.

Note: The OCX control not available for placing on form in Delphi 2005/2007. But it is possible to add it manually by editing YourForm.dfm file. To place control add text like this:
object FAX: TFAX
Left = 144
Top = 96
Width = 16
Height = 16
TabOrder = 0
OnIdle = FAXIdle
...
ControlData = {
03000400A7010000A70100000000000000000000000000000000000000000100
02000100010100000C47434C415353312853464329}
end
kd-max
 
Posts: 3
Joined: Mon Mar 22, 2010 4:01 pm

Re: Events not workin when form is hidden (ActiveX)

Postby dustinaleksiuk » Fri Mar 26, 2010 10:14 am

Hi Kd-Max,

After I posted that, we had a few issues with that method. It looks like the BlackIce stuff really depends on the windows message pump to do it's own work and when we really tested we had serious issues. Instead of doing a form.Show(), we now do this:

Form1 form1 = new Form1();
ApplicationContext context = new ApplicationContext(form1);
Application.Run(context);

This software is extremely reliable for actually sending faxes, but horrible to actually implement in our server-side application. I would have bought this software immediately if they would abstract out the actual faxing code with a good .NET wrapper API that isn't an ActiveX control. We will likely not use it. It's impossible to predict what the black box ActiveX control will do.
dustinaleksiuk
 
Posts: 3
Joined: Fri Feb 12, 2010 1:28 pm

Re: Events not workin when form is hidden (ActiveX)

Postby Dalinda » Tue Jan 27, 2015 12:01 am

This is exceptionally pleasant and good post....you shook posting it....thanks a ton for posting it....!! :roll: :twisted: :P




___________________
Johni
Dalinda
 
Posts: 1
Joined: Mon Jan 26, 2015 11:58 pm


Return to Fax C++ / ActiveX



Who is online

Users browsing this forum: No registered users and 1 guest