{"id":91351,"date":"2015-10-15T07:00:00","date_gmt":"2015-10-15T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20151015-00\/?p=91351\/"},"modified":"2019-03-13T12:20:38","modified_gmt":"2019-03-13T19:20:38","slug":"20151015-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20151015-00\/?p=91351","title":{"rendered":"What&#8217;s the difference between UuidFromString, IIDFromString, CLSIDFromString, GUIDFromString&#8230;"},"content":{"rendered":"<p>A GUID and a CLSID and an IID are all the same as a UUID, but there are separate functions for converting a string into a GUID, CLSID, IID, and UUID. Are they all equivalent? If not, what&#8217;s the difference? And which one should I use? <\/p>\n<p>The basic form for a UUID string is <code>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx<\/code> where each <code>x<\/code> is a hexadecimal digit, case-insensitive. (I personally prefer all-uppercase.) All of the parsing functions under discussion use this basic form as their basis of exploration. Some functions expect the basic form to be enclosed in curly braces; others do not. <\/p>\n<p>Let&#8217;s start with <code>Uuid&shy;From&shy;String<\/code>. It takes a string in basic form <i>without<\/i> curly braces. As a special case, if you pass <code>NULL<\/code> instead of a valid string pointer, the function still succeeds and sets the result to <code>GUID_NULL<\/code>. <\/p>\n<p>Next up is <code>IID&shy;From&shy;String<\/code>. This function takes a string in basic form <i>with<\/i> curly braces. It also has the behavior that passing <code>NULL<\/code> as the string results in success and <code>GUID_NULL<\/code>. <\/p>\n<p>Slightly more complicated is <code>CLSID&shy;From&shy;String<\/code>. In addition to accepting a brace-enclosed string (which is treated as a GUID), it also accepts a ProgId. In the ProgId case, it returns <a HREF=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms688628(v=vs.85).aspx\">the CLSID associated with that ProgId<\/a>. For example, if you ask for <code>Paint.Picture<\/code>, it will return the GUID <code>{D3E34B21-9D75-101A-8C3D-00AA001A1652}<\/code>. As with the other functions, passing <code>NULL<\/code> is valid and results in <code>GUID_NULL<\/code>. <\/p>\n<p>Last is <code>GUID&shy;From&shy;String<\/code>. This function is one of those &#8220;Not guaranteed to be supported beyond Windows Vista&#8221; functions, so you should probably steer clear. (Another clue that calling it is probably a bad idea: The function is not exposed in any header file or import library.) But if you insist: It accepts a brace-enclosed string, and <code>NULL<\/code> is <i>not<\/i> allowed. Furthermore, it ignores any garbage after the trailing brace. This function was <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/05\/19\/8518565.aspx\">not intended for public consumption<\/a>, so these strange quirks are not entirely unexpected. <\/p>\n<p>Let&#8217;s summarize in a table, since that seems to be popular. I added a final column describing whether the function available in A\/W variants or is Unicode-only. <\/p>\n<table BORDER=\"1\" STYLE=\"border-collapse: collapse\" CELLPADDING=\"4\">\n<tr>\n<th>Function<\/th>\n<th>Expected format<\/th>\n<th>NULL allowed?<\/th>\n<th>Character set support<\/th>\n<\/tr>\n<tr>\n<td VALIGN=\"baseline\"><code>Uuid&shy;From&shy;String<\/code><\/td>\n<td VALIGN=\"baseline\"><code>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx<\/code><\/td>\n<td VALIGN=\"baseline\">Yes<\/td>\n<td VALIGN=\"baseline\">ANSI and Unicode<\/td>\n<\/tr>\n<tr>\n<td VALIGN=\"baseline\"><code>IID&shy;From&shy;String<\/code><\/td>\n<td VALIGN=\"baseline\"><code>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}<\/code><\/td>\n<td VALIGN=\"baseline\">Yes<\/td>\n<td VALIGN=\"baseline\">Unicode only<\/td>\n<\/tr>\n<tr>\n<td VALIGN=\"baseline\"><code>CLSID&shy;From&shy;String<\/code><\/td>\n<td VALIGN=\"baseline\"><code>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}<\/code><br>                   <code>ProgId<\/code><\/td>\n<td VALIGN=\"baseline\">Yes<\/td>\n<td VALIGN=\"baseline\">Unicode only<\/td>\n<\/tr>\n<tr>\n<td VALIGN=\"baseline\"><code>GUID&shy;From&shy;String<\/code><\/td>\n<td VALIGN=\"baseline\"><code>{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*<\/code><\/td>\n<td VALIGN=\"baseline\">No<\/td>\n<td VALIGN=\"baseline\">ANSI and Unicode<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Mostly the same if what you have is a stringized GUID; otherwise&#8230;<\/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-91351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Mostly the same if what you have is a stringized GUID; otherwise&#8230;<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/91351","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=91351"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/91351\/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=91351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=91351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=91351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}