{"id":111423,"date":"2025-07-31T07:00:00","date_gmt":"2025-07-31T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111423"},"modified":"2025-07-31T09:02:46","modified_gmt":"2025-07-31T16:02:46","slug":"20250731-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250731-00\/?p=111423","title":{"rendered":"A consequence of the weird <CODE>wReserved<\/CODE> value at the start of the <CODE>DECIMAL<\/CODE> structure"},"content":{"rendered":"<p>Not too long ago, I explained why <a title=\"What's with the weird wReserved value at the start of the DECIMAL structure?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250516-00\/?p=111185\"> why there is a weird <code>wReserved<\/code> value at the start of the <code>DECIMAL<\/code> structure<\/a>. Markus Grohs pointed out <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250516-00\/?p=111185&amp;commentid=142741#comment-142741\"> in a comment<\/a> that the way that <code>decVal<\/code> is overlaid on top of a <code>VARIANT<\/code> means that you have to be careful about the order in which you set the fields.<\/p>\n<p>Given<\/p>\n<pre>DECIMAL value = \u27e6 some value \u27e7;\r\nVARIANT var;\r\nVariantClear(&amp;var);\r\n<\/pre>\n<p>then you have to remember to set the <code>vt<\/code> <i>last<\/i> because it is overwritten by the <code>wReserved<\/code> inside the <code>DECIMAL<\/code>.<\/p>\n<pre>\/\/ Wrong\r\nvar.vt = VT_DECIMAL;\r\nvar.decVal = value; \/\/ oops, the wReserved overwrites the var.vt.\r\n\r\n\/\/ Better\r\nvar.decVal = value; \/\/ the wReserved overwrites var.vt\r\nvar.vt = VT_DECIMAL; \/\/ but we fix it up immediately\r\n<\/pre>\n<p>The extra <code>wReserved<\/code> in the <code>DECIMAL<\/code> is like a bulky backpack that you wear as you go about your daily business. You usually forget that you have it on, until you turn around in a tight spot and accidentally knock something over.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It overwrites things by accident.<\/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-111423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It overwrites things by accident.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111423","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=111423"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111423\/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=111423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}