{"id":44984,"date":"2015-04-29T07:00:00","date_gmt":"2015-04-29T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/04\/29\/is-the-atom-returned-by-registerclassex-a-real-atom\/"},"modified":"2015-04-29T07:00:00","modified_gmt":"2015-04-29T07:00:00","slug":"is-the-atom-returned-by-registerclassex-a-real-atom","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150429-00\/?p=44984","title":{"rendered":"Is the atom returned by RegisterClass(Ex) a &#034;real&#034; atom?"},"content":{"rendered":"<p>A customer was debugging some code that calls <code>Register&shy;Class<\/code> on a class that&#8217;s already been registered. In this case, it was registered by another DLL in the same process. Normally, this wouldn&#8217;t be a problem, because <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/04\/18\/409205.aspx\"> each DLL passes its own instance handle to <code>Register&shy;Class<\/code><\/a> so that there are no name collisions. However, in this case, both DLLs are passing the <code>CS_GLOBAL&shy;CLASS<\/code> flag, which means that collisions can occur after all.\n The customer found that the call to <code>ERROR_CLASS_EXISTS<\/code>, which makes sense in the case of a collision in the global class table. The code then calls <code>Find&shy;Atom<\/code> to look up the class name, but <code>Find&shy;Atom<\/code> fails, saying, &#8220;No such atom.&#8221;\n Does this mean that the class atom created by <code>Register&shy;Class<\/code> isn&#8217;t a <i>real<\/i> atom? How can you get the atom for a window class that somebody else has registered?\n Okay, let&#8217;s look at these questions in order.\n Is the atom a <i>real<\/i> atom? Well, if you ask the atom, it&#8217;ll say, &#8220;I feel real to me.&#8221; But remember that <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms649053(v=vs.85).aspx\"> there are many atom tables<\/a> in the system.<\/p>\n<ul>\n<li>The global atom table. <\/li>\n<li>One local atom table for each process. <\/li>\n<li>The registered clipboard format atom table. <\/li>\n<li>The registered window class atom table. <\/li>\n<li>Possibly others, too. <\/li>\n<\/ul>\n<p> The <code>Find&shy;Atom<\/code> function searches the process&#8217;s local atom table, so if you go looking for a registered window class atom there, you&#8217;re going to come up empty.\n There is no way to query the registered window class atom table directly. You only get indirect access to create items in it through <code>Register&shy;Class<\/code>, and that atom can in turned by used <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/10\/11\/240744.aspx\"> as a synonym for the class name<\/a>.<\/p>\n<p> Now, it so happens that although the <code>Get&shy;Class&shy;Info<\/code> function formally returns a <code>BOOL<\/code>, i.e., an integer that is zero on failure or nonzero on success, the success case of <code>Get&shy;Class&shy;Info<\/code> actually returns the class atom. This behavior is <i>not documented<\/i>, but the ATL library relies on it, so if the undocumented behavior changes in the future, it&#8217;ll have an app compat shim to keep ATL happy. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer was debugging some code that calls Register&shy;Class on a class that&#8217;s already been registered. In this case, it was registered by another DLL in the same process. Normally, this wouldn&#8217;t be a problem, because each DLL passes its own instance handle to Register&shy;Class so that there are no name collisions. However, in this [&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-44984","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer was debugging some code that calls Register&shy;Class on a class that&#8217;s already been registered. In this case, it was registered by another DLL in the same process. Normally, this wouldn&#8217;t be a problem, because each DLL passes its own instance handle to Register&shy;Class so that there are no name collisions. However, in this [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44984","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=44984"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44984\/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=44984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=44984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=44984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}