{"id":93051,"date":"2016-02-18T07:00:00","date_gmt":"2016-02-18T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=93051"},"modified":"2019-03-13T10:30:34","modified_gmt":"2019-03-13T17:30:34","slug":"20160218-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160218-00\/?p=93051","title":{"rendered":"Nasty gotcha: VarCmp vs VariantCompare"},"content":{"rendered":"<p>There are two functions for comparing <code>VARIANT<\/code>s. One comes from the COM team, called <code>VarCmp<\/code>. Assuming a successful comparison, it returns <\/p>\n<table BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Comparison<\/th>\n<th>Return value<\/th>\n<\/tr>\n<tr>\n<td>Less than<\/td>\n<td>0 = <code>VARCMP_LT<\/code><\/td>\n<\/tr>\n<tr>\n<td>Equal to<\/td>\n<td>1 = <code>VARCMP_EQ<\/code><\/td>\n<\/tr>\n<tr>\n<td>Greater than<\/td>\n<td>2 = <code>VARCMP_GT<\/code><\/td>\n<\/tr>\n<\/table>\n<p>This is consistent with the other <code>Var&shy;Xxx<\/code> functions. <\/p>\n<p>On the other hand, the <code>Variant&shy;Compare<\/code> function comes from the shell, and it returns <\/p>\n<table BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Comparison<\/th>\n<th>Return value<\/th>\n<\/tr>\n<tr>\n<td>Less than<\/td>\n<td ALIGN=\"right\">&minus;1<\/td>\n<\/tr>\n<tr>\n<td>Equal to<\/td>\n<td ALIGN=\"right\">0<\/td>\n<\/tr>\n<tr>\n<td>Greater than<\/td>\n<td ALIGN=\"right\">+1<\/td>\n<\/tr>\n<\/table>\n<p>Yuck. <\/p>\n<p>So be careful which one you&#8217;re calling and how you&#8217;re testing the result. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Similar names, different return values.<\/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-93051","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Similar names, different return values.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93051","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=93051"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93051\/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=93051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=93051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=93051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}