How to use an OCX file in a windows service?

ajeeshco

Well-known member
Joined
Sep 19, 2006
Messages
257
Location
Cochin, India
Programming Experience
3-5
Hi all,
I was converting a windows application to a windows service. The problem is with an ocx file. The windows application is using a server.ocx file and I created an instance of that ocx control by drag n drop from tool box in that windows application. Now when I tried to convert that application to a service I couldnot use that ocx file by drag n drop. Then, as an experiment to use that ocx file, I added a windows form in to the windows service project,added the ocx control and handled all the events of the ocx control in that form. Also I added two public functions called Initialize() and UnInitialize() and I called these functions in the OnStart and OnStop methods of the service. Then I am getting the following error in the InitializeComponent():

System.Threading.ThreadStateException was unhandled
Message="ActiveX control 'edbf9a1a-f766-47c8-a529-59edff2b105b' cannot be instantiated because the current thread is not in a single-threaded apartment."

I would like to know whether there is any other way to add an ocx control to the windows service, Also where can I put the STAThread attribute. Thanks in advance.:)
 
Back
Top