Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. ATL dialog with ActiveX control used inside Windows service

ATL dialog with ActiveX control used inside Windows service

Scheduled Pinned Locked Moved ATL / WTL / STL
comquestionc++dockerhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Suchit
    wrote on last edited by
    #1

    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?

    J 1 Reply Last reply
    0
    • S Suchit

      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?

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      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 or template <typename ThreadingModel> CComObjectRootEx. Make sure you inherit from CComObjectRootEx<CComMultiThreadModel> and use the Lock() and Unlock() methods appropriately. You can also use the type ObjectLock if you need to lock temporarily using the RAII idiom. ObjectLock lock(this); calls Lock() at construction time and Unlock() 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!

      S 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        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 or template <typename ThreadingModel> CComObjectRootEx. Make sure you inherit from CComObjectRootEx<CComMultiThreadModel> and use the Lock() and Unlock() methods appropriately. You can also use the type ObjectLock if you need to lock temporarily using the RAII idiom. ObjectLock lock(this); calls Lock() at construction time and Unlock() 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!

        S Offline
        S Offline
        Suchit
        wrote on last edited by
        #3

        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).

        J 1 Reply Last reply
        0
        • S Suchit

          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).

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          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!

          S 1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            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!

            S Offline
            S Offline
            Suchit
            wrote on last edited by
            #5

            I am sorry about saying that this problem is solved. Actaully the problem of crash/exception remains where it was. However initially hosting activex control in invisible, and modeless ATL dialogs was not achieved by me, now it is possible.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups