{"id":29293,"date":"2006-10-23T10:00:04","date_gmt":"2006-10-23T10:00:04","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/10\/23\/psychic-debugging-why-doesnt-my-program-show-up-when-i-call-shellexecute\/"},"modified":"2006-10-23T10:00:04","modified_gmt":"2006-10-23T10:00:04","slug":"psychic-debugging-why-doesnt-my-program-show-up-when-i-call-shellexecute","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20061023-04\/?p=29293","title":{"rendered":"Psychic debugging: Why doesn&#039;t my program show up when I call ShellExecute?"},"content":{"rendered":"<p>\nThis question came in from a customer (paraphrased):\n<\/p>\n<blockquote CLASS=\"q\"><p>\nIf I run my program from the command prompt, it works great,\nbut if I run it from my launcher via <code>ShellExecuteEx<\/code>,\nit never appears.\n<\/p><\/blockquote>\n<p>\nSee how good your psychic powers are at solving this problem\nbefore I give you the second question that gives away the answer.\n<\/p>\n<p>\nAny luck?\n<\/p>\n<p>\nHere&#8217;s a second question from a different source (but which\ncoincidentally came in the same day).\n<\/p>\n<blockquote CLASS=\"q\"><p>\nI&#8217;m trying to use <code>ShellExecute<\/code> to open a document.\nThe function succeeds (returns a value greater than 32),\nbut I don&#8217;t get anything on the screen.\n<\/p>\n<pre>\nif (ShellExecute(Handle, NULL, FileName, NULL,\n    NULL, NULL) &lt;= (HINSTANCE)32) ...\n<\/pre>\n<\/blockquote>\n<p>\nThe problem the second person is having lies in the last parameter\nto the <code>ShellExecute<\/code> function.\nIt&#8217;s <code>nShowCmd<\/code>, which is supposed to be an\n<code>SW_*<\/code> value, but which this person is passing as\n<code>NULL<\/code>.\nIt so happens, that the value zero corresponds to\n<code>SW_HIDE<\/code>, which explains why the program doesn&#8217;t\nappear: You told it to run hidden!\n<\/p>\n<p>\nNow go back to the first problem.\nDo you see what the person most likely did wrong?\nThe code probably went like this:\n<\/p>\n<pre>\nSHELLEXECUTEINFO sei = { sizeof(sei) };\nsei.hwnd = hwnd;\nsei.lpVerb = TEXT(\"open\");\nsei.lpFile = pszFile;\nShellExecuteEx(&amp;sei);\n<\/pre>\n<p>\nSince the <code>sei.nShow<\/code> member was not explicitly\nset,  the value was implicitly set to zero by the incomplete\ninitializer.\nAnd as we noted above, zero means <code>SW_HIDE<\/code>.\n<\/p>\n<p>\nIt turns out my psychic debugging was correct.\nThat was indeed the source of the first person&#8217;s problem.\nNow you can use your psychic powers, too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This question came in from a customer (paraphrased): If I run my program from the command prompt, it works great, but if I run it from my launcher via ShellExecuteEx, it never appears. See how good your psychic powers are at solving this problem before I give you the second question that gives away the [&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-29293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>This question came in from a customer (paraphrased): If I run my program from the command prompt, it works great, but if I run it from my launcher via ShellExecuteEx, it never appears. See how good your psychic powers are at solving this problem before I give you the second question that gives away the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29293","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=29293"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/29293\/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=29293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=29293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=29293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}