DDE:实现通过 Shell 和 ddeexec 正确启动的应用程序

发布于 2024-12-12 18:39:32 字数 1033 浏览 0 评论 0原文

我正在尝试实现一个将自身注册为 DDE 服务器的应用程序,以便它正确响应我们的自定义“.qsx”文件类型,就像 WinWord 响应“.docx”文件类型一样。

即,

  1. 如果应用程序已经在运行并且有人双击了“.qsx”文件,那么我们希望已经打开的应用程序接收 DDE 打开命令并打开相关文件。
  2. 但是,如果应用程序尚未运行,那么 shell 应该启动我们的应用程序,然后与应用程序建立 DDE 连接并告诉它像以前一样打开文件。

我们的第 1 部分工作完美。

但是,对于第 2 部分,Shell 启动命令,但随后失败并显示“将命令发送到程序时出现问题”。这对应于从“ShellExecute”Windows API 函数返回的返回代码“SE_ERR_DDEFAIL”(29)。

事实上,我编写了一个名为“ShellExecute.exe”的自定义控制台应用程序,它可以完全独立于 explorer.exe 重现此问题。

如果我运行 ShellExecute.exe 并且我们的“DDE 服务器”应用程序已经启动,则它可以正常工作。 如果我为“.docx”文档运行 ShellExecute.exe 并且 WinWord 未运行,则 WinWord 会正确启动并加载该文档 如果我为“.qsx”文档运行 ShellExecute.exe 并且我们的应用程序未运行,则 ShellExecuteEx 会启动该应用程序,但在我们的服务器应用程序有机会注册为 DDE 之前立即返回 SE_ERR_DDEFAIL服务器。

由于某种原因,对于 WinWord,ShellExecute 似乎会等待它启动。

我尝试在运行 procmon.exe 的情况下运行这两种情况,以查看 ShellExecute 可能在注册表中查找哪些内容,以区分我们的情况与 WinWord.exe,但我找不到任何内容。

我真正需要的是 ShellExecute 算法的源代码,以便我可以找出为什么它适用于 WinWord 但不适用于我们的自定义扩展。

谁能详细解释一下 ShellExecute 是如何启动应用程序的,以及它如何知道“等待”应用程序注册为 DDE 服务器?

I am trying to implement an application which registers itself as a DDE Server so that it responds correctly to our custom ".qsx" filetype, just as WinWord responds to the ".docx" filetype.

i.e.

  1. If the application is already running and someone double-clicks on a ".qsx" file then we want the already open application to receive the DDE open command and to open the relevant file.
  2. However, if the application is not already running then the shell should launch our application, and then establish a DDE connection with the application and tell it to open the file as before.

We have part 1 working flawlessly.

However, for part 2, the Shell launches the command, but then fails with "There was a problem sending the command to the program". This corresponds to return code "SE_ERR_DDEFAIL" (29) returned from the "ShellExecute" Windows API function.

In fact, I have written a custom console application called "ShellExecute.exe" that can reproduce this problem exactly independently of explorer.exe.

If I run ShellExecute.exe and our "DDE server" app is already up, it works correctly.
If I run ShellExecute.exe for a ".docx" document and WinWord is not running, WinWord launches correctly and loads the document
If I run ShellExecute.exe for our ".qsx" document and our app is not running, ShellExecuteEx launches the application but immediately returns with SE_ERR_DDEFAIL before our server app has even had a chance to register as a DDE server.

For some reason then it seems that for WinWord, ShellExecute waits for it to start up.

I've tried running both cases with procmon.exe running to see what ShellExecute might be looking for in the registry that differentiates our case from WinWord.exe, but I can't find anything.

What I really need is the source code of the ShellExecute algorithm so that I can find out why it is working for WinWord but not for our custom extension.

Can anyone explain, in precise detail, what ShellExecute does to launch an application and how in particular it knows to "wait" for the application to register as a DDE server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮邮递员 2024-12-19 18:39:32

在 XP+ 上运行的应用程序应使用 IDropTarget 以避免当窗口挂起时 DDE 的问题。

使用 DDE 时,shell 假定您的 DDE 服务器在您开始消息循环之前已启动并运行...

Applications running on XP+ should use IDropTarget to avoid the problems with DDE when there are hung windows.

When using DDE the shell assumes your DDE server is up and running before you start your message loop...

飘逸的'云 2024-12-19 18:39:32

请不要使用 DDE。这是一种非常过时的做法,会导致各种问题并挂起并依赖于注册表。

现代方法是使用全局互斥锁。如果你搜索 Stack Overflow,你会发现很多人都在问同样的问题 (也许从这里开始)

Please don't use DDE. It is a ridiculously obsolete way of doing that that causes all kinds of problems and hangs and depends on the registry.

The modern way to do this is with a global mutex. If you search Stack Overflow you'll find dozens of people asking the same question (maybe start here)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文