{"id":8823,"date":"2011-12-23T07:00:00","date_gmt":"2011-12-23T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/12\/23\/how-do-i-get-the-full-path-for-the-target-of-a-shortcut-file\/"},"modified":"2011-12-23T07:00:00","modified_gmt":"2011-12-23T07:00:00","slug":"how-do-i-get-the-full-path-for-the-target-of-a-shortcut-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20111223-00\/?p=8823","title":{"rendered":"How do I get the full path for the target of a shortcut file?"},"content":{"rendered":"<p>\nA customer was having trouble obtaining information from\na shortcut file.\n&#8220;Here is a sample program that tries to print the target\nof a shortcut file, but it only gets the file name without\na directory.\nHow do I get the full path?&#8221;\n<\/p>\n<pre>\n IShellLink *psl;\n ... code that loads the IShellLink omitted ...\n TCHAR szPath[MAX_PATH];\n WIN32_FIND_DATA wfd;\n hr = psl-&gt;GetPath(szPath, MAX_PATH, &amp;wfd, SLGP_UNCPATH);\n if (SUCCEEDED(hr)) {\n  _tprintf(TEXT(\"Got path: %s\\n\"), wfd.cFileName);\n }\n<\/pre>\n<p>\nRecall that the <code>WIN32_FIND_DATA<\/code> structure\ncontains only a file name in the <code>cFile&shy;Name<\/code> member.\nIt doesn&#8217;t have any path information.\nThe <code>WIN32_FIND_DATA<\/code> structure was\noriginally created for the <code>Find&shy;First&shy;File<\/code>\nfunction,\nand you already know the directory you are searching in\nbecause you passed it to\n<code>Find&shy;First&shy;File<\/code>.\n<\/p>\n<p>\nBut we&#8217;re not using the\n<code>WIN32_FIND_DATA<\/code> structure in\nconjunction with\n<code>Find&shy;First&shy;File<\/code>,\nso where do I get the directory from?\n<\/p>\n<p>\nIn the customer&#8217;s excitement over the\n<code>WIN32_FIND_DATA<\/code> structure,\nthey forgot about that other parameter:\n<code>szPath<\/code>.<\/p>\n<pre>\n if (SUCCEEDED(hr)) {\n  _tprintf(TEXT(\"Got path: %s\\n\"), szPath);\n }\n<\/pre>\n<p>The answer was sitting right there in front of them,\nlike an overlooked Christmas present.\n<\/p>\n<p>\n(Don&#8217;t forget, the target of the shortcut might not be a file,\nin which case\nthe call to <code>Get&shy;Path<\/code> will return <code>S_FALSE<\/code>.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer was having trouble obtaining information from a shortcut file. &#8220;Here is a sample program that tries to print the target of a shortcut file, but it only gets the file name without a directory. How do I get the full path?&#8221; IShellLink *psl; &#8230; code that loads the IShellLink omitted &#8230; TCHAR szPath[MAX_PATH]; [&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-8823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer was having trouble obtaining information from a shortcut file. &#8220;Here is a sample program that tries to print the target of a shortcut file, but it only gets the file name without a directory. How do I get the full path?&#8221; IShellLink *psl; &#8230; code that loads the IShellLink omitted &#8230; TCHAR szPath[MAX_PATH]; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8823","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=8823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8823\/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=8823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=8823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=8823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}