{"id":37483,"date":"2004-10-25T07:11:00","date_gmt":"2004-10-25T07:11:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/10\/25\/accessing-the-current-modules-hinstance-from-a-static-library\/"},"modified":"2004-10-25T07:11:00","modified_gmt":"2004-10-25T07:11:00","slug":"accessing-the-current-modules-hinstance-from-a-static-library","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041025-00\/?p=37483","title":{"rendered":"Accessing the current module&#8217;s HINSTANCE from a static library"},"content":{"rendered":"<p><P>\nIf you&#8217;re writing a static library, you may have need to access\nthe <CODE>HINSTANCE<\/CODE> of the module that you have been\nlinked into.\nYou could require that the module that links you in pass the\n<CODE>HINSTANCE<\/CODE> to a special initialization function,\nbut odds are that people will forget to do this.\n<\/P>\n<P>\nIf you are using a Microsoft linker, you can take advantage of\na pseudovariable which the linker provides.\n<\/P>\n<PRE>\nEXTERN_C IMAGE_DOS_HEADER __ImageBase;\n#define HINST_THISCOMPONENT ((HINSTANCE)&amp;__ImageBase)\n<\/PRE>\n<P>\nThe pseudovariable <CODE>__ImageBase<\/CODE>\nrepresents the DOS header of the module, which happens to\nbe what a Win32 module begins with.\nIn other words, it&#8217;s the base address of the module.\nAnd the module base address is the same as its <CODE>HINSTANCE<\/CODE>.\n<\/P>\n<P>\nSo there&#8217;s your <CODE>HINSTANCE<\/CODE>.\n<\/P>\n<P>\n[Raymond is currently on vacation; this message was pre-recorded.]\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re writing a static library, you may have need to access the HINSTANCE of the module that you have been linked into. You could require that the module that links you in pass the HINSTANCE to a special initialization function, but odds are that people will forget to do this. If you are using [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-37483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If you&#8217;re writing a static library, you may have need to access the HINSTANCE of the module that you have been linked into. You could require that the module that links you in pass the HINSTANCE to a special initialization function, but odds are that people will forget to do this. If you are using [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37483","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=37483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/37483\/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=37483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=37483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=37483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}