简体   繁体   English

COM MFC应用程序不显示窗口

[英]COM MFC application don't show window

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. 我有一个具有ATL支持的MFC应用程序,其想法是当有人创建在mfc应用程序中声明的接口实例时,此实例创建并显示一个窗口。

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. 如果com客户端是cmd.exe,则一切正常,我制作了一个快速的com客户端,该实例是该接口的实例,并且当出现这些实例时,窗口将根据需要显示。

But if this instantiation is done in another com objects (for example atl server objects (services)) the window is not displayed. 但是,如果此实例化是在另一个com对象(例如atl服务器对象(服务))中完成的,则不会显示该窗口。 Note that the mfc process is created under the DcomLaunch process but no window is displayed. 请注意,mfc进程是在DcomLaunch进程下创建的,但没有显示任何窗口。 Everything works fine but the window is not show in my desktop. 一切正常,但窗口未显示在桌面上。

Two questions: 两个问题:

1) why my window is not displayed in this situation? 1)为什么在这种情况下我的窗口没有显示?

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! 2)当我使用控制台应用程序创建相同的界面时,只会创建mfc应用程序的一个进程,而不会启动多少个控制台应用程序,并且如果服务尝试实例化多个对象,则将创建多个mfc进程创建! 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? 如何使第一个mfc进程始终与响应客户端呼叫的进程相同?

(i think this is all due to security settings... but i already try to change some and nothing...) (我认为这都是由于安全设置而引起的...但是我已经尝试过更改某些内容而已...)

Thanks 谢谢

Nuno no野

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. 在Vista之前,您可以通过给定服务属性的“登录”标签上的“允许服务与桌面进行交互”复选框来使服务与桌面进行交互(例如,打开窗口)。 If you're targetting Vista, this isn't an option. 如果您的目标是Vista,则不能选择此选项。

However, given this is the DcomLaunch service you're dealing with, you clearly don't want to do that. 但是,鉴于这是您要处理的DcomLaunch服务,您显然不想这样做。

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 创建的用户界面只能在会话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. 同样,由于以上内容仅适用于Vista之前的版本,并且仍然是一个坏主意,因此,要公开UI的服务通常被接受的“最佳实践”是拥有一个单独的应用程序,其中包含与用户设备进行通信的UI您选择使用的任何IPC机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM