{"id":9783,"date":"2011-08-29T07:00:00","date_gmt":"2011-08-29T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/08\/29\/why-cant-i-use-psguid_storage-like-a-guid\/"},"modified":"2011-08-29T07:00:00","modified_gmt":"2011-08-29T07:00:00","slug":"why-cant-i-use-psguid_storage-like-a-guid","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20110829-00\/?p=9783","title":{"rendered":"Why can&#039;t I use PSGUID_STORAGE like a GUID?"},"content":{"rendered":"<p>\nThe <code>stgprop.h<\/code> header file defines a GUID called\n<code>PSGUID_STORAGE<\/code>, but a customer was having trouble\nusing it.\n<\/p>\n<pre>\n    GUID guid;\n    ...\n    \/\/ This generates a strange compiler error\n    if (IsEqualGUID(guid, PSGUID_STORAGE)) { ... }\n<\/pre>\n<p>\nThe strange compiler error the customer referred to is the following:\n<\/p>\n<pre>\ntest.cpp(136) : error C2143: syntax error : missing ')' before '{'\ntest.cpp(136) : error C2059: syntax error : ')'\ntest.cpp(136) : error C2143: syntax error : missing ';' before '{'\ntest.cpp(136) : error C2059: syntax error : '{'\ntest.cpp(136) : error C2059: syntax error : ')'\ntest.cpp(137) : error C2059: syntax error : '}'\ntest.cpp(137) : error C2143: syntax error : missing ';' before '}'\ntest.cpp(137) : error C2059: syntax error : '}'\n<\/pre>\n<p>\n&#8220;I don&#8217;t see what the compiler is complaining about.\nThe parentheses appear to be properly matched before the left brace.&#8221;\n<\/p>\n<p>\nRemember, what you see is not necessarily what the compiler sees.\nLet&#8217;s take another look at this mysterious GUID:\n<\/p>\n<pre>\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms691088(VS.85).aspx\">#define PSGUID_STORAGE<\/a>  { 0xb725f130,           \\\n                          0x47ef, 0x101a,       \\\n                          { 0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac } }\n<\/pre>\n<p>\nWell there&#8217;s your problem.\nAfter the preprocessor does its substitution, the line becomes\n<\/p>\n<pre>\n    if (IsEqualGUID(guid, { 0xb725f130,\n              0x47ef, 0x101a,\n              { 0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac } })) { ... }\n<\/pre>\n<p>\nand that&#8217;s not legal C\/C++.\n(Though with a little tweaking,\n<a HREF=\"http:\/\/gcc.gnu.org\/onlinedocs\/gcc-3.1.1\/gcc\/Compound-Literals.html\">\nyou can get GCC to accept it<\/a>.)\nThe <code>PSGUID_STORAGE<\/code>\nsymbols is intended to be used as an initializer:\n<\/p>\n<pre>\nconst GUID StorageGuid = PSGUID_STORAGE;\n<\/pre>\n<p>\n&#8220;How did you know that?&#8221;\n<\/p>\n<p>\nI didn&#8217;t, but I went to the effort of looking at the definition\nin the header file and figuring it out from inspection.\n<\/p>\n<p>\nWhy is it defined this way instead of\n<\/p>\n<pre>\nDEFINE_GUID(PSGUID_STORAGE, 0xb725f130, 0x47ef,\n        0x101a, 0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac);\n<\/pre>\n<p>\n?\n<\/p>\n<p>\nBecause this GUID is\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms691088.aspx\">\nused as the\nFMTID of a\n<code>PROPERTY&shy;KEY<\/code><\/a>.\n<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb773381.aspx\">\nThe <code>PROPERTY&shy;KEY<\/code><\/a> structure<\/a>\nlooks like this:\n<\/p>\n<pre>\ntypedef struct {\n  GUID  fmtid;\n  DWORD pid;\n} PROPERTYKEY;\n<\/pre>\n<p>\nThe intended usage is evidently\n<\/p>\n<pre>\nconst PROPERTYKEY\nPKEY_STORAGE_DIRECTORY = { PSGUID_STORAGE, PID_STG_DIRECTORY };\n<\/pre>\n<p>\nSince the C language does not permit global variables to be initialized\nfrom other global variables (or at least it didn&#8217;t at the time\n<code>PROPERTY&shy;KEY<\/code>s were defined; who knows what crazy\nfeatures will show up in C1X),\n<code>PSGUID_STORAGE<\/code> needs to be a macro which expands\nto an initializer rather than being a global variable.\n<\/p>\n<p>\nToday&#8217;s question was really just settling the prerequisites for\ntomorrow&#8217;s topic.\nStay tuned.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The stgprop.h header file defines a GUID called PSGUID_STORAGE, but a customer was having trouble using it. GUID guid; &#8230; \/\/ This generates a strange compiler error if (IsEqualGUID(guid, PSGUID_STORAGE)) { &#8230; } The strange compiler error the customer referred to is the following: test.cpp(136) : error C2143: syntax error : missing &#8216;)&#8217; before &#8216;{&#8216; [&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-9783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The stgprop.h header file defines a GUID called PSGUID_STORAGE, but a customer was having trouble using it. GUID guid; &#8230; \/\/ This generates a strange compiler error if (IsEqualGUID(guid, PSGUID_STORAGE)) { &#8230; } The strange compiler error the customer referred to is the following: test.cpp(136) : error C2143: syntax error : missing &#8216;)&#8217; before &#8216;{&#8216; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/9783","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=9783"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/9783\/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=9783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=9783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=9783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}