{"id":43573,"date":"2014-11-20T07:00:00","date_gmt":"2014-11-20T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/11\/20\/a-library-loaded-via-load_library_as_datafile-or-similar-flags-doesnt-get-to-play-in-any-reindeer-module-games\/"},"modified":"2014-11-20T07:00:00","modified_gmt":"2014-11-20T07:00:00","slug":"a-library-loaded-via-load_library_as_datafile-or-similar-flags-doesnt-get-to-play-in-any-reindeer-module-games","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20141120-00\/?p=43573","title":{"rendered":"A library loaded via LOAD_LIBRARY_AS_DATAFILE (or similar flags) doesn&#039;t get to play in any reindeer module games"},"content":{"rendered":"<p>If you load a library with the <code>LOAD_LIBRARY_AS_DATA&shy;FILE<\/code> flag, then it isn&#8217;t really loaded in any normal sense. In fact, it&#8217;s kept completely <i>off the books<\/i>.\n If you load a library with the <code>LOAD_LIBRARY_AS_DATA&shy;FILE<\/code>, <code>LOAD_LIBRARY_AS_DATA&shy;FILE_EXCLUSIVE<\/code>, or <code>LOAD_LIBRARY_AS_IMAGE_RESOURCE<\/code> flag (or any similar flag added in the future), then the library gets mapped into the process address space, but it is not a true module. Functions like <code>Get&shy;Module&shy;Handle<\/code>, <code>Get&shy;Module&shy;File&shy;Name<\/code>, <code>Enum&shy;Process&shy;Modules<\/code> and <code>Create&shy;Toolhelp32&shy;Snapshot<\/code> will not see the library, because it was never entered into the database of loaded modules.\n These &#8220;load library as&#8230;&#8221; flags don&#8217;t actually load the library in any meaningful sense. They just take the file and map it into memory manually without updating any module tracking databases. This functionality was overloaded into the <code>Load&shy;Library&shy;Ex<\/code> function, which in retrospect was probably not a good idea, because people expect <code>Load&shy;Library&shy;Ex<\/code> to create true modules, but these flags create <i>pseudo-modules<\/i>, a term I made up just now.\n It would have been less confusing in retrospect if the &#8220;load library as&#8230;&#8221; functionality were split into another function like <code>Load&shy;File&shy;As&shy;Pseudo&shy;Module<\/code>. Okay, that&#8217;s a pretty awful name, but that&#8217;s not the point. The point is to put the functionality in some function that doesn&#8217;t have the word <i>library<\/i> in its name.\n Okay, so now that we see that these pseudo-modules aren&#8217;t true modules, and they don&#8217;t participate in any <a href=\"http:\/\/en.wiktionary.org\/wiki\/reindeer_games\"> reindeer module games<\/a>. So what use are they?\n Basically, the only thing you can do with a pseudo-module is access its resources with functions like <code>Find&shy;Resource<\/code>, <code>Load&shy;Resource<\/code>, and <code>Enum&shy;Resource&shy;Types<\/code>. Note that this indirectly includes functions like <code>Load&shy;String<\/code>, and <code>Format&shy;Message<\/code> which access resources behind the scenes.<\/p>\n<p> So maybe a better name for the function would have been <code>Load&shy;File&shy;For&shy;Resources<\/code>, since that&#8217;s all the pseudo-module is good for. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you load a library with the LOAD_LIBRARY_AS_DATA&shy;FILE flag, then it isn&#8217;t really loaded in any normal sense. In fact, it&#8217;s kept completely off the books. If you load a library with the LOAD_LIBRARY_AS_DATA&shy;FILE, LOAD_LIBRARY_AS_DATA&shy;FILE_EXCLUSIVE, or LOAD_LIBRARY_AS_IMAGE_RESOURCE flag (or any similar flag added in the future), then the library gets mapped into the process address [&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-43573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you load a library with the LOAD_LIBRARY_AS_DATA&shy;FILE flag, then it isn&#8217;t really loaded in any normal sense. In fact, it&#8217;s kept completely off the books. If you load a library with the LOAD_LIBRARY_AS_DATA&shy;FILE, LOAD_LIBRARY_AS_DATA&shy;FILE_EXCLUSIVE, or LOAD_LIBRARY_AS_IMAGE_RESOURCE flag (or any similar flag added in the future), then the library gets mapped into the process address [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43573","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=43573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/43573\/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=43573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=43573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=43573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}