{"id":963,"date":"2014-05-19T07:00:00","date_gmt":"2014-05-19T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/05\/19\/creating-a-simple-shell-item-just-as-fake-as-a-simple-pidl\/"},"modified":"2014-05-19T07:00:00","modified_gmt":"2014-05-19T07:00:00","slug":"creating-a-simple-shell-item-just-as-fake-as-a-simple-pidl","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140519-00\/?p=963","title":{"rendered":"Creating a simple shell item, just as fake as a simple pidl"},"content":{"rendered":"<p>\nContinuing from\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/05\/03\/10415778.aspx\">\nCreating a simple pidl:\nFor the times you care enough to send the very fake<\/a>:\nInstead of\ncreating a simple pidl,\nwe&#8217;ll create a simple shell item.\n<\/p>\n<p>\nThe idea is the same.\nWe build a file system bind context containing the information about\nthe fake file,\nand we pass that bind context to the\n<code>SH&shy;Create&shy;Shell&shy;Item<\/code> function.\n<\/p>\n<p>\nTake\nthat program that creates a simple pidl\nand make these changes:\n<\/p>\n<pre>\nHRESULT <font COLOR=\"blue\">CreateSimpleShellItemFromPath<\/font>(\n _In_ const WIN32_FIND_DATAW *pfd,\n _In_ PCWSTR pszPath,\n <font COLOR=\"blue\">_In_ REFIID riid, _Outptr_ void **ppv<\/font>)\n{\n *<font COLOR=\"blue\">ppv<\/font> = nullptr;\n CComPtr&lt;IBindCtx&gt; spbc;\n HRESULT hr = CreateFileSysBindCtx(pfd, &amp;spbc);\n if (SUCCEEDED(hr)) {\n  hr = <font COLOR=\"blue\">SHCreateItemFromParsingName<\/font>(pszPath, spbc, <font COLOR=\"blue\">riid, ppv<\/font>);\n }\n return hr;\n}\nvoid DoStuffWith(_In_ <font COLOR=\"blue\">IShellItem2 *psi2<\/font>)\n{\n \/\/ Print the file name\n <font COLOR=\"blue\">PCWSTR pszName;<\/font>\n if (<font COLOR=\"blue\">SUCCEEDED(psi2-&gt;GetDisplayName(\n         SIGDN_DESKTOPABSOLUTEPARSING,\n         &amp;pszName<\/font>)) {\n  wprintf(L\"Path is \\\"%ls\\\"\\n\", <font COLOR=\"blue\">pszName<\/font>);\n  <font COLOR=\"blue\">CoTaskMemFree(pszName);<\/font>\n }\n \/\/ Print the file size\n <font COLOR=\"blue\">ULONGLONG ullSize;<\/font>\n if (SUCCEEDED(<font COLOR=\"blue\">psi2-&gt;GetUInt64(<\/font>PKEY_Size, <font COLOR=\"blue\">&amp;ullSize<\/font>))) {\n  wprintf(L\"Size is %I64u\\n\", <font COLOR=\"blue\">ullSize<\/font>);\n }\n}\nint __cdecl wmain(int argc, PWSTR argv[])\n{\n <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/05\/20\/135841.aspx\">CCoInitialize<\/a> init;\n if (SUCCEEDED(init)) {\n  WIN32_FIND_DATAW fd = {};\n  fd.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;\n  fd.nFileSizeLow = 42;\n  <font COLOR=\"blue\">CComPtr&lt;IShellItem2&gt; spsi2;<\/font>\n  if (SUCCEEDED(<font COLOR=\"blue\">CreateSimpleShellItemFromPath<\/font>(&amp;fd,\n                L\"Q:\\\\Whatever.txt\", <font COLOR=\"blue\">IID_PPV_ARGS(&amp;spsi2)<\/font>))) {\n   DoStuffWith(<font COLOR=\"blue\">spsi2<\/font>);\n  }\n }\n return 0;\n}\n<\/pre>\n<p>\nInstead of creating a simple pidl,\nwe create a simple shell item\nand then extract the same information from it it as before,\njust doing it the\n<code>IShell&shy;Item<\/code> way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Continuing from Creating a simple pidl: For the times you care enough to send the very fake: Instead of creating a simple pidl, we&#8217;ll create a simple shell item. The idea is the same. We build a file system bind context containing the information about the fake file, and we pass that bind context to [&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-963","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Continuing from Creating a simple pidl: For the times you care enough to send the very fake: Instead of creating a simple pidl, we&#8217;ll create a simple shell item. The idea is the same. We build a file system bind context containing the information about the fake file, and we pass that bind context to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/963","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=963"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/963\/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=963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}