ATL dialog with ActiveX control used inside Windows service
-
I need to take an opinion on whether our approach is right (described below): Problem We have a ATL windows service which also exposes one COM class - say MainServer. MainServer interacts with other internal COM objects and a VB ActiveX control. Client application can instantiate MainServer component and fire some methods on it. The VB ActiveX control needs a form container - so we are using ATL dialog (invisible, modeless) to host it. And fire methods on the dialog. Output Service when tested through control panel GUI, it works perfectly and we can fire methods on ActiveX control through its container in ServiceWinMain(), Run() and other methods. But when tested with Client application which instantiates MainServer and fires methods, we have an unspecified exception. My questions are: 1. Is it possible to host ATL dialog like I mentioned in a Windows service? 2. What is the best way to make this application thread safe? 3. Is this approach right?
-
I need to take an opinion on whether our approach is right (described below): Problem We have a ATL windows service which also exposes one COM class - say MainServer. MainServer interacts with other internal COM objects and a VB ActiveX control. Client application can instantiate MainServer component and fire some methods on it. The VB ActiveX control needs a form container - so we are using ATL dialog (invisible, modeless) to host it. And fire methods on the dialog. Output Service when tested through control panel GUI, it works perfectly and we can fire methods on ActiveX control through its container in ServiceWinMain(), Run() and other methods. But when tested with Client application which instantiates MainServer and fires methods, we have an unspecified exception. My questions are: 1. Is it possible to host ATL dialog like I mentioned in a Windows service? 2. What is the best way to make this application thread safe? 3. Is this approach right?
Someone wrote: 2. What is the best way to make this application thread safe? Is STAs possible when running as a service? If so, then COM solves it for you. If not, I'd use the locking mechanisms built into ATL to protect the COM objects against unsafe parallell access. I suppose your COM component inherits from either
CComObjectRoot
ortemplate <typename ThreadingModel> CComObjectRootEx
. Make sure you inherit fromCComObjectRootEx<CComMultiThreadModel>
and use theLock()
andUnlock()
methods appropriately. You can also use the typeObjectLock
if you need to lock temporarily using the RAII idiom.ObjectLock lock(this);
callsLock()
at construction time andUnlock()
at destruction time. Other than that I can't be of much more help as I don't have experience with COM servers in services. -- Arigato gozaimashita! -
Someone wrote: 2. What is the best way to make this application thread safe? Is STAs possible when running as a service? If so, then COM solves it for you. If not, I'd use the locking mechanisms built into ATL to protect the COM objects against unsafe parallell access. I suppose your COM component inherits from either
CComObjectRoot
ortemplate <typename ThreadingModel> CComObjectRootEx
. Make sure you inherit fromCComObjectRootEx<CComMultiThreadModel>
and use theLock()
andUnlock()
methods appropriately. You can also use the typeObjectLock
if you need to lock temporarily using the RAII idiom.ObjectLock lock(this);
callsLock()
at construction time andUnlock()
at destruction time. Other than that I can't be of much more help as I don't have experience with COM servers in services. -- Arigato gozaimashita! -
Thanks Jörgen, Solution did not require me to use Locks. But your answer did give a spark to think in a particular direction and finally I reached a solution. Suchit. (why doesn't my name appear besides by posting? I am logged in using my CodeProject ID).
You're welcome! May I ask how you solved it? Someone wrote: why doesn't my name appear besides by posting? I am logged in using my CodeProject ID I believe it's because you are using HTML commands in your name. Your name shows up as <font face= in the email notification. Try changing your CP settings. -- Arigato gozaimashita!
-
You're welcome! May I ask how you solved it? Someone wrote: why doesn't my name appear besides by posting? I am logged in using my CodeProject ID I believe it's because you are using HTML commands in your name. Your name shows up as <font face= in the email notification. Try changing your CP settings. -- Arigato gozaimashita!