{"id":8583,"date":"2012-01-12T07:00:00","date_gmt":"2012-01-12T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/01\/12\/why-does-createevent-fail-with-error_path_not_found-if-i-give-it-a-name-with-a-backslash\/"},"modified":"2012-01-12T07:00:00","modified_gmt":"2012-01-12T07:00:00","slug":"why-does-createevent-fail-with-error_path_not_found-if-i-give-it-a-name-with-a-backslash","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120112-00\/?p=8583","title":{"rendered":"Why does CreateEvent fail with ERROR_PATH_NOT_FOUND if I give it a name with a backslash?"},"content":{"rendered":"<p>\nA customer reported that the\n<code>Create&shy;Event<\/code> function was failing with the unusual\nerror code <code>ERROR_PATH_NOT_FOUND<\/code>:\n<\/p>\n<pre>\nHANDLE h = CreateEvent(0, FALSE, TRUE, \"willy\\\\wonka\");\nif (h == NULL) {\n DWORD dwError = GetLastError(); \/\/ returns ERROR_PATH_NOT_FOUND\n ...\n}\n<\/pre>\n<p>\nThe customer continued,\n&#8220;The documentation for\n<code>Create&shy;Event<\/code> says that the <code>lpName<\/code> parameter\nmust not contain the backslash character.\nClearly we are in error for having passed an illegal character,\nbut why are we getting the strange error code?\nThere is no file path involved.\nRight now, we&#8217;ve added <code>ERROR_PATH_NOT_FOUND<\/code>\nto our list of possible error codes, but we&#8217;d like an explanation\nof what the error means.&#8221;\n<\/p>\n<p>\nOkay, first of all, building a table of all known error codes\nis another compatibility problem waiting to happen.\nSuppose in the next version of Windows, a new error code is added,\nsay,\n<code>ERROR_REJECTED_BY_SLASHDOT<\/code>.\nWhat will your program do when it gets this new error code?\n<\/p>\n<p>\nNow back to the error code.\nThere is no file path involved here, so why is there a path-not-found\nerror?\n<\/p>\n<p>\nBecause it&#8217;s not a file system path that failed.\nIt&#8217;s an object namespace path.\n<\/p>\n<p>\nIf a backslash appears in the name of a named object,\nit is treated as a namespace separator.\n(If there is no backslash, the name is interpreted as\npart of the Local namespace.)\nAnd\nthe call fails with a path-not-found error\nsince there is no namespace called <code>willy<\/code>,\nso the path traversal inside the object namespace fails.\n<\/p>\n<p>\nThe treatment of the backslash as a namespace separator is sort\nof alluded to in the very next sentence of the documentation:\n&#8220;For more information, see <i>Kernel Object Namespaces<\/i>.&#8221;\nThe following paragraph also expands upon this idea:\n&#8220;The object can be created in a private namespace.\nFor more information, see <i>Object Namespaces<\/i>.&#8221;\nThe documentation sort of assumes you&#8217;ll follow the links and\nlearn more about those namespacey things, at which point\nyou&#8217;ll learn what that backslash in the object name really means\n(and why there is the rule about not allowing backslashes).\n<\/p>\n<p>\nBut here it is if you don&#8217;t want to try to figure it out:\n<\/p>\n<p>\n&#8220;If you put a backslash in the name, it is treated as a namespace\nseparator, and if you don&#8217;t know what a namespace is,\nthen that&#8217;s probably not what you want.\nSo don&#8217;t use backslashes unless you know what you&#8217;re doing.&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer reported that the Create&shy;Event function was failing with the unusual error code ERROR_PATH_NOT_FOUND: HANDLE h = CreateEvent(0, FALSE, TRUE, &#8220;willy\\\\wonka&#8221;); if (h == NULL) { DWORD dwError = GetLastError(); \/\/ returns ERROR_PATH_NOT_FOUND &#8230; } The customer continued, &#8220;The documentation for Create&shy;Event says that the lpName parameter must not contain the backslash character. Clearly [&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":[26],"class_list":["post-8583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>A customer reported that the Create&shy;Event function was failing with the unusual error code ERROR_PATH_NOT_FOUND: HANDLE h = CreateEvent(0, FALSE, TRUE, &#8220;willy\\\\wonka&#8221;); if (h == NULL) { DWORD dwError = GetLastError(); \/\/ returns ERROR_PATH_NOT_FOUND &#8230; } The customer continued, &#8220;The documentation for Create&shy;Event says that the lpName parameter must not contain the backslash character. Clearly [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8583","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=8583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/8583\/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=8583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=8583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=8583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}