When a program is launched via DDE, and there are multiple servers, which one is used?

Although you are more than welcome to stop using DDE (please oh please stop using it), there are still many applications which still use it (cough), and as a result, customers still have questions about it.

One customer wanted to know why, if multiple copies of a DDE-based application are running, Windows 7 will send the command to the earliest-launched copy of the program, whereas Windows XP will send the command to the most-recently-used copy. "Our employees were used to forcing the document to open in a specific window by switching to that window, thereby making it most-recently-used, then switching back to Explorer and double-clicking the document, and expecting it to open in that window. And that usually (but not always) worked. In Windows 7, it rarely works. Is there an explanation for this change in behavior other than 'internal process and window handling stuff'?"

It's internal process and window handling stuff.

If multiple DDE servers are available to handle a command, it is unspecified what order they are used.

It so happens that Windows XP uses Send­Message­Timeout with the HWND_BROADCAST window target, and it so happens that Send­Message­Timeout on Windows XP sends the messages in top-to-bottom order by z-order. If all windows are responding to messages, then it means that the window closest to the top of the z-order will get the first chance to respond. If there are unresponsive windows, then things get more complicated, and as the customer noted, the results become somewhat unpredictable. (Also, if there are unresponsive windows, your machine froze for 30 seconds.)

In Windows Vista an optimization was added: Instead of just diving in and broadcasting DDE requests to everybody in search of a server, Explorer remembers the last window that responded and goes straight to that window first, on the theory that if it knew how to handle the Open command last time, it most likely will know how to handle it this time. And it can do this even if other applications are not responding to messages.

If the optimization fails, then Explorer goes back to the slow broadcast method. But most of the time, the optimization works, and the document gets launched much faster.

Comments (7)
  1. 12BitSlab says:

    We use some backup software at work (I'll leave the name out) that has a foreground component and a background component that runs as a service.  Believe it or not, it uses DDE to comunicate between the foreground and the service.  I can't believe that software is still using DDE.  BTW, even though I won't name the product, it is from a very big company that everyone knows.

  2. Joshua says:

    Is there a way to tag a process as does not use DDE? Due to certain UI design decisions that I did not make but are a selling point, there are RPC calls in WM_CLOSE.

  3. Doug says:

    Ah, that explains why Visual Studio 2008 behaves differently on Windows 7 than it did on XP when opening files.  I usually have several instances running, and I might want to open a file in one or another instance depending on where I wanted to set breakpoints or debug something, and I used to be able to just switch to the instance I wanted, find the file in a file search tool, just open it, and it'd go to the right window.

    Now I have to find the file in Explorer (or somewhere else that supports dragging files (i.e., not the file search tool I like)) and drag it to the window.  Slightly annoying, because I used to be able to do it entirely with the keyboard.  Nice to at least know what happened, because there was no way to do a search to find out more.

  4. Killer{R} says:

    About optimizations.. I suppose if somebody would take say Windows 2000 source and then merge into its code all optimizations made in all subsequent Windows'es but do not merge any additional functionality… Then finally we would get awesome fast system!

  5. Mark S says:

    *Cue rant about Windows 7 not using Alt-Tab in Z-order anymore either*

  6. Mc says:

    We still have  VB6 code that has on screen fields that then link via DDE to word templates (so the address automatically gets filled in when they open the document).    You can't use DDE in .NET and so we've left these applications in VB6.   I wonder how many years they'll stay like that,  the applications are already getting on for 20 years old  (first written in VB3 I believe).    I expect when office goes totally cloud based and breaks things completely the code might finially be re-written in something more modern.  

  7. cheong00 says:

    DDE don't work well in UAC enabled environment. For normal process it works, but once it "runs as administrator" it won' response to DDE commands.

    It happens that I occasionally need to launch debug to my IIS process, so after launching VS as elevated process, double-click on a solution file won't work.

Comments are closed.

Skip to main content