Installing C-Sharp services in Windows

J

Jeevan

Hi,

I am creating a Window Service in C-Sharp. The Window Service has a
reference to an OCX file created in VC++. In OnStart method I have created
an instance of the class, of the OCX file and called a method of the class.
Compilation was successful.

I created a Windows installer setup(.MSI), for installing the service. The
installation was successful. I started my service from the Services
Management Console. It started and stopped immediately, throwing the below
Exception in the System Application Log:
_______________________________________________________
Service cannot be started. System.Runtime.InteropServices.COMException
(0x8000FFFF): Catastrophic failure
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at FOCCLib.FOCCClass.Connect(String serverAddr, String port)
at WindowsService1.Service1.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object
state)
_______________________________________________________

Please help me in resolving this issue.

Thanks in advance,
Jeevan
 
W

Willy Denoyette [MVP]

Jeevan said:
Hi,

I am creating a Window Service in C-Sharp. The Window Service has a
reference to an OCX file created in VC++. In OnStart method I have created
an instance of the class, of the OCX file and called a method of the
class. Compilation was successful.

I created a Windows installer setup(.MSI), for installing the service. The
installation was successful. I started my service from the Services
Management Console. It started and stopped immediately, throwing the below
Exception in the System Application Log:
_______________________________________________________
Service cannot be started. System.Runtime.InteropServices.COMException
(0x8000FFFF): Catastrophic failure
at System.RuntimeType.ForwardCallToInvokeMember(String memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at FOCCLib.FOCCClass.Connect(String serverAddr, String port)
at WindowsService1.Service1.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object
state)
_______________________________________________________

Please help me in resolving this issue.

Thanks in advance,
Jeevan

OCX objects have special requirements not fullfilled when instantiated from
Windows Services.
1. They need an STA apartment to live in, Windows Services threads are MTA
by default.
2. They need a ActiveX container as a host - for instance a Windows Form,
Windows Services don't/shouldn't provide such container as they should be
designed to run without a UI.

Or simply stated, don't try to use OCX's in non interactive applications.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top