{"id":109374,"date":"2024-02-08T07:00:00","date_gmt":"2024-02-08T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=109374"},"modified":"2024-02-08T06:49:53","modified_gmt":"2024-02-08T14:49:53","slug":"20240208-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240208-00\/?p=109374","title":{"rendered":"How do I suppress the error box that appears when a <CODE>LoadLibrary<\/CODE> fails?"},"content":{"rendered":"<p>If there is a problem loading a DLL via <code>Load\u00adLibrary<\/code> or a related function, you sometimes get a system error box that says &#8220;Contoso.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support.&#8221; How can a program suppress this error message and just have <code>Load\u00adLibrary<\/code> return <code>NULL<\/code> without fanfare?<\/p>\n<p>The so-called &#8220;error mode&#8221; controls how things behave when various categories of bad things happen. One category of failure goes under the name <code>SEM_<wbr \/>FAIL\u00adCRITICAL\u00adERRORS<\/code>. This name sounds really vague, but at the time it was introduced, it wasn&#8217;t vague at all.<\/p>\n<p>The term &#8220;critical errors&#8221; refers to <a href=\"https:\/\/github.com\/Microsoft\/MS-DOS\/blob\/master\/v2.0\/source\/INT24.txt\"> MS-DOS interrupt 24h<\/a>, known as the &#8220;critical error&#8221; interrupt. These errors were things like &#8220;No disk in drive&#8221; or &#8220;I\/O error&#8221;, and your recovery options were the famous trio of Abort, Retry, and Ignore, later revised to Abort, Retry, and Fail. Saying that you want to &#8220;fail critical errors&#8221; obviously means that when these critical errors occur, you don&#8217;t want the system to <a title=\"What is a hard error, and what makes it harder than an easy error?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240116-00\/?p=109274\"> prompt the user for action<\/a> but rather act as if the user had selected &#8220;Fail&#8221;.<\/p>\n<p>Windows expanded the category of things that were classified as &#8220;critical errors&#8221; to include &#8220;DLL not found&#8221;, so that the user could reinsert the floppy disk with the missing DLL. And in the intervening decades, various other miscellaneous file errors got tossed into the &#8220;critical errors&#8221; bucket. (<a title=\"The unintentionally-expanding scope of the SEM_NOGPFAULTERRORBOX flag\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230227-00\/?p=107875\">Sound familiar<\/a>?)<\/p>\n<p>And that leads to the answer to the question.<\/p>\n<p>To suppress error dialogs in functions like <code>Load\u00adLibrary<\/code>, you can call <code>Set\u00adError\u00adMode(<wbr \/>SEM_<wbr \/>FAIL\u00adCRITICAL\u00adERRORS)<\/code>\u00b9<\/p>\n<p>\u00b9 More precisely, you want to <a title=\"Disabling the program crash dialog\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040727-00\/?p=38323\"> add the <code>SEM_<wbr \/>FAIL\u00adCRITICAL\u00adERRORS<\/code><\/a> flag to whatever flags are already set.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>They don&#8217;t appear often, but they do appear occasionally.<\/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-109374","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>They don&#8217;t appear often, but they do appear occasionally.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109374","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=109374"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109374\/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=109374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=109374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=109374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}