I have a windows service that implements a COM COM server.
When launched as an application, the methods of a COM object are called in a separate (not in the main) thread, which is just fine. Things change when the service starts - then the methods of the COM object are called in the context of the service flow, which is not cool for me.
I see that this is due to apartments, MTA, STA, etc., but I canβt figure out how to get COM to call object methods in a separate thread, and not in a service.
Maybe this is due to the registration of the com object when the service starts?
My environment is Windows 7 + delphi, but C ++ solutions are welcome.
Update 2011-04-26 :
Kudos to @sharptooth and @Chris Dickson, which made me look for a solution in the direction of message loops.
Since this is an STA, the application uses a message pump to deliver COM messages to the thread that registered the class. I have moved the registration of soklafs to a separate thread that have a message loop, and all com calls are now made in this thread. I tried this approach before, but forgot about the message pipeline, so this was the missing piece of the puzzle. Thanks guys!
Nedko source share