tags:

views:

432

answers:

1

Hello,

I have a MFC application with ATL support, the idea is when someone creates an instance of my interface declared in the mfc application, this instantiation creates and displays a window.

This all works fine if the com client is the cmd.exe, i made a quick com client that instance the interface and when this instances occur the window is displayed as desired.

But if this instantiation is done in another com objects (for example atl server objects (services)) the window is not displayed. Note that the mfc process is created under the DcomLaunch process but no window is displayed. Everything works fine but the window is not show in my desktop.

Two questions:

1) why my window is not displayed in this situation?

2) when i create the same interface with my console app, only one process of the mfc application is created, no mater how many console app i start, and if the service try to instantiate more than one object, more than one mfc process are created! why is this, how can i avoid this. How can i make that the first mfc process is allways the same one that responds to the client calls?

(i think this is all due to security settings... but i already try to change some and nothing...)

Thanks

Nuno

+1  A: 

In general a service cannot create windows. Pre-Vista you can enable a service to interact with the desktop (for example, open a window) via the "Allow service to interact with desktop" check-box on the "Log On" tag of the given services properties. If you're targetting Vista, this isn't an option.

However, given this is the DcomLaunch service you're dealing with, you clearly don't want to do that.

Even if it was your own service you wrote most anyone would advise against you doing this anyway for a few reasons (in no particular order):

  • The UI created would be only accessible in session 0
  • Creating a window creates an attack service into your (probably) privileged process since any other process the user runs can interact with the service's window.

Again, since the above only works pre-Vista, and is a Bad Idea anyway, the generally accepted "best practice" for a service that wants to expose a UI is to have a separate application that contains the UI which communicates with the service using whatever IPC mechanism you choose to use.

imaginaryboy
Yes you are right, but what i did is what you suggest not to do :) (a service that has the "Allow service to interact with desktop" check) and it works fine.The best practice solution that you give is not bad, it only is a little annoying because is too much work for something simple but ok, i will save in my head your advise on the best practice :)Thanks
Nuno