{"id":96365,"date":"2017-06-08T07:00:00","date_gmt":"2017-06-08T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=96365"},"modified":"2019-03-13T01:12:40","modified_gmt":"2019-03-13T08:12:40","slug":"20170608-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170608-00\/?p=96365","title":{"rendered":"What will GetLastError() return after a failed InitOnceExecuteOnce?"},"content":{"rendered":"<p>The documentation for <code>Init&shy;Once&shy;Execute&shy;Once<\/code> says <\/p>\n<blockquote CLASS=\"q\"><p>If the function fails, the return value is zero. To get extended error information, call <b>Get&shy;Last&shy;Error<\/b>. <\/p><\/blockquote>\n<p>On the other hand, the documentation for the <code>Init&shy;Once&shy;Callback<\/code> says <\/p>\n<blockquote CLASS=\"q\"><p>If the function returns <b>FALSE<\/b>, the block is not marked as initialized and the call to <b>Init&shy;Once&shy;Execute&shy;Once<\/b> fails. To communicate additional error information, call <b>Set&shy;Last&shy;Error<\/b>. before returning <b>FALSE<\/b>. <\/p><\/blockquote>\n<p>The second paragraph implies that the <code>Init&shy;Once&shy;Execute&shy;Once<\/code> function does not itself call <code>Get&shy;Last&shy;Error<\/code>, because if it did, then that would wipe out the value set by the callback. Is that really the case? <\/p>\n<p>Yes, that&#8217;s really the case. The remark in the first paragraph about calling <code>Get&shy;Last&shy;Error<\/code> presupposes that your callback uses <code>Get&shy;Last&shy;Error<\/code> to report why it wasn&#8217;t able to initialize. <\/p>\n<p>I agree, however, that the documentation is misleading here. <\/p>\n<p>But if your callback wants to return status information more complex than a single &#8220;success\/failed&#8221;, you are probably better served by the <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20161222-00\/?p=94995\">synchronous two-phase initialization pattern<\/a>, which makes it a lot easier to return more complex information. You can even use it to <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20170406-00\/?p=95915\">throw a C++ exception<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whatever you tell it to.<\/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-96365","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Whatever you tell it to.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/96365","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=96365"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/96365\/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=96365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=96365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=96365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}