{"id":32573,"date":"2006-01-23T10:00:12","date_gmt":"2006-01-23T10:00:12","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/01\/23\/if-your-callback-fails-its-your-responsibility-to-set-the-error-code\/"},"modified":"2006-01-23T10:00:12","modified_gmt":"2006-01-23T10:00:12","slug":"if-your-callback-fails-its-your-responsibility-to-set-the-error-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060123-12\/?p=32573","title":{"rendered":"If your callback fails, it&#039;s your responsibility to set the error code"},"content":{"rendered":"<p>There are many cases where a callback function is allowed to halt an operation. For example, you might decide to return <code>FALSE<\/code> to <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/windowing\/windows\/windowreference\/windowmessages\/wm_nccreate.asp\"> the <code>WM_NCCREATE<\/code> message<\/a> to prevent the window from being created, or you might decide to return <code>FALSE<\/code> to one of the many enumeration callback functions such as <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/windowing\/windows\/windowreference\/windowfunctions\/enumwindowsproc.asp\"> the <code>EnumWindowsProc<\/code> callback<\/a>. When you do this, the enclosing operation will return failure back to its caller: <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/windowing\/windows\/windowreference\/windowfunctions\/createwindow.asp\"> the <code>CreateWindow<\/code> function<\/a> returns <code>NULL<\/code>; <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/windowing\/windows\/windowreference\/windowfunctions\/enumwindows.asp\"> the <code>EnumWindows<\/code> function<\/a> returns <code>FALSE<\/code>.\n Of course, when this happens, the enclosing operation doesn&#8217;t know why the callback failed; all it knows is that it failed. Consequently, it can&#8217;t set a meaningful value to be retrieved by <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/debug\/base\/getlasterror.asp\"> the <code>GetLastError<\/code> function<\/a>.\n If you want something meaningful to be returned by the <code>GetLastError<\/code> function when your callback halts the operation, it&#8217;s the callback&#8217;s responsibility to set that value by calling <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/debug\/base\/setlasterror.asp\"> the <code>SetLastError<\/code> function<\/a>.<\/p>\n<p> This is something that is so obvious I didn&#8217;t think it needed to be said; it falls into the &#8220;because computers aren&#8217;t psychic (yet)&#8221; category of explanation. But apparently it wasn&#8217;t obvious enough, so now I&#8217;m saying it. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many cases where a callback function is allowed to halt an operation. For example, you might decide to return FALSE to the WM_NCCREATE message to prevent the window from being created, or you might decide to return FALSE to one of the many enumeration callback functions such as the EnumWindowsProc callback. When you [&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-32573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>There are many cases where a callback function is allowed to halt an operation. For example, you might decide to return FALSE to the WM_NCCREATE message to prevent the window from being created, or you might decide to return FALSE to one of the many enumeration callback functions such as the EnumWindowsProc callback. When you [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32573","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=32573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/32573\/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=32573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=32573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=32573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}