{"id":94,"date":"2003-12-15T22:05:00","date_gmt":"2003-12-15T22:05:00","guid":{"rendered":"http:\/\/jclark.org\/weblog\/Programming\/Microsoftish\/crackurl.html"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-30T04:00:00","slug":"crackurl","status":"publish","type":"post","link":"https:\/\/jclark.org\/weblog\/2003\/12\/15\/crackurl\/","title":{"rendered":"UrlGetPart, and the Parts it Won&#8217;t Get"},"content":{"rendered":"<p>This is a narrow post.  If you don&#8217;t understand or don&#8217;t care, do skip it (you won&#8217;t be missing much).  For the rest, and for the search engines, here&#8217;s some trivia.<\/p>\n<p>There are a <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/shellcc\/platform\/shell\/reference\/shlwapi\/path\/path.asp\">bunch of handy functions<\/a> in the Win32 Shell <span class=\"caps\">API<\/span> for handling file paths and URLs, provided by <span class=\"caps\">SHLWAPI.DLL.  <\/span>One of these, <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/shellcc\/platform\/shell\/reference\/shlwapi\/path\/urlgetpart.asp\">UrlGetPart<\/a>, is described thusly:<\/p>\n<blockquote><p>Accepts a [sic] <span class=\"caps\">URL<\/span> string and returns a specified part of that <span class=\"caps\">URL.<\/span><\/p><\/blockquote>\n<p>Very handy function, until you realize that the one part of an <span class=\"caps\">URL<\/span> you can&#8217;t specify to be returned is the path.  For example, in the (fictitious) url:<\/p>\n<p><a>http:\/\/bond:007@example.com\/topsecret\/martini.cgi?method=shaken+not+stirred<\/code>code&gt;http:\/\/bond:007@example.com\/topsecret\/martini.cgi?method=shaken+not+stirred&lt;\/code<\/a><\/p>\n<p>I can use UrlGetPart to retrieve the scheme (http:), the username (bond), the password (007), the host (example.com), and the query (?method=shaken+not+stirred), but I <em>cannot<\/em> retrieve the path (\/topsecret\/martini.cgi).<\/p>\n<p>So, How do extract the path from an <span class=\"caps\">URL<\/span> using UrlGetPart?  You don&#8217;t.  Instead, use <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/wininet\/wininet\/internetcrackurl.asp\">InternetCrackUrl<\/a>, in wininet.dll.  If you need to do this from <span class=\"caps\">VB6 <\/span>(and this may work with <span class=\"caps\">VB5,<\/span> but I&#8217;ve not tried it), take a look at <a href=\"http:\/\/www.vbip.com\/wininet\/wininet_url_class_01.asp\">this helper class<\/a>, which also supports a few other handy <span class=\"caps\">URL<\/span>-handling functions.   <\/p>","protected":false},"excerpt":{"rendered":"<p>This is a narrow post. If you don&#8217;t understand or don&#8217;t care, do skip it (you won&#8217;t be missing much). For the rest, and for the search engines, here&#8217;s some trivia. There are a bunch of handy functions in the Win32 Shell API for handling file paths and URLs, provided by SHLWAPI.DLL. One of these, [&hellip;]<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-microsoftish"],"_links":{"self":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":0,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"wp:attachment":[{"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jclark.org\/weblog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}