{"id":30793,"date":"2006-06-21T10:00:17","date_gmt":"2006-06-21T10:00:17","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/06\/21\/psychic-debugging-understanding-dde-initiation\/"},"modified":"2006-06-21T10:00:17","modified_gmt":"2006-06-21T10:00:17","slug":"psychic-debugging-understanding-dde-initiation","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060621-17\/?p=30793","title":{"rendered":"Psychic debugging: Understanding DDE initiation"},"content":{"rendered":"<p>\nYou too can use your psychic powers to debug the following problem:\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nWe have a problem with opening documents with our application\nby double-clicking them in Explorer.\nWhat&#8217;s really strange is that if we connect a debugger to Explorer\nand set a breakpoint on <code>kernel32!CreateProcessW<\/code>,\nthen wait a moment after <code>CreateProcess<\/code> returns,\nthen hit &#8216;<code>g<\/code>&#8216;,\nthen the document opens fine.\nBut if we don&#8217;t wait, then the application launches but the\ndocument does not open.\nInstead, you get the error message &#8220;Windows cannot find\n&#8216;abc.lit&#8217;. Make sure you typed the name correctly,\nand then try again.&#8221;\nHere is the command we are executing when we run into this problem:\n<\/p>\n<pre>\n\"F:\\Program Files\\LitSoft\\LitWare\\LitWare.exe\" \/dde\n<\/pre>\n<p>\nWhat is wrong?\n<\/p>\n<\/blockquote>\n<p>\nIf you&#8217;ve been reading carefully and paid attention to the explanation of\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/dataexchange\/dynamicdataexchange\/usingdynamicdataexchange.asp\">\nhow document launching via DDE works<\/a>,\nthen you already know what the problem is.\n<\/p>\n<p>\nRecall that launching documents via DDE is done by first\nlooking for a DDE server and if none is found, launching\na server manually and trying again.\nThe command line above was clearly registered as the\n<code>command<\/code> associated with a\n<code>ddeexec<\/code>.\nThere are two giveaway clues.\nFirst is the fact that the document name itself is not present anywhere\non the command line.\n(This couldn&#8217;t be a direct execution because the program wouldn&#8217;t know\nwhat document it&#8217;s supposed to be opening!)\nBut the\ngiveaway clue is the phrase <code>\/dde<\/code> on the command line.\n<\/p>\n<p>\nClearly, something is going wrong when Explorer attempts the\nsecond DDE conversation to open the document.\nThe fact that making Explorer wait a few seconds fixes the\nproblem makes the cause obvious:\nThe DDE server is being slow to get itself initialized and listening.\nExplorer launches the server and tries to talk to it,\nbut the server is not yet ready and therefore doesn&#8217;t respond to\nthe DDE initiate.\n<\/p>\n<p>\nBut how do you fix this?\n<\/p>\n<p>\nThe shell assumes that a DDE server is ready to accept connections\nwhen it goes input idle.\nOnce <code>WaitForInputIdle<\/code> on the DDE server returns,\nExplorer will make its second attempt at initiating a DDE conversation.\nThe fix is for the application to get its DDE server up and running\nbefore it starts pumping messages.\nMy guess is that the application moved its DDE server\nto a background thread to improve startup performance,\nsince the DDE server is not involved in normal program operation.\nToo bad the program forgot to get the DDE server up and running\nprior to going input idle when the <code>\/dde<\/code> flag is passed.\nThe one time it&#8217;s important to have the DDE server running and it\nmisses the boat.\n<\/p>\n<p>\nMoral of the story:\nIf you&#8217;re going to act as a DDE server,\nmake sure you do so before your primary thread starts pumping messages.\nOtherwise you have a race condition between your application startup\nand the shell trying to talk to it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You too can use your psychic powers to debug the following problem: We have a problem with opening documents with our application by double-clicking them in Explorer. What&#8217;s really strange is that if we connect a debugger to Explorer and set a breakpoint on kernel32!CreateProcessW, then wait a moment after CreateProcess returns, then hit &#8216;g&#8216;, [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-30793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You too can use your psychic powers to debug the following problem: We have a problem with opening documents with our application by double-clicking them in Explorer. What&#8217;s really strange is that if we connect a debugger to Explorer and set a breakpoint on kernel32!CreateProcessW, then wait a moment after CreateProcess returns, then hit &#8216;g&#8216;, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/30793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=30793"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/30793\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=30793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=30793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=30793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}