{"id":41083,"date":"2004-01-12T07:00:00","date_gmt":"2004-01-12T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/01\/12\/why-cant-i-getprocaddress-a-function-i-dllexported\/"},"modified":"2004-01-12T07:00:00","modified_gmt":"2004-01-12T07:00:00","slug":"why-cant-i-getprocaddress-a-function-i-dllexported","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040112-00\/?p=41083","title":{"rendered":"Why can&#039;t I GetProcAddress a function I dllexport&#039;ed?"},"content":{"rendered":"<p><a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/vccelng\/htm\/msmod_20.asp\"> The dllexport attribute tells the linker to generate an export table entry for the specified function.  This export entry is <b>decorated<\/b>. This is necessary to support <code>dllexport<\/code>ing of overloaded functions. But it also means that the string you pass to <code>GetProcAddress<\/code> needs to be decorated.\n<a href=\"http:\/\/weblogs.asp.net\/oldnewthing\/archive\/2004\/01\/07\/48303.aspx\"> As we learned earlier<\/a>, the decoration scheme varies from architecture to architecture and from calling convention to calling convention. So, for example, if the function is exported from a PPC DLL, you would have to do <code>GetProcAddress(hinst, \"..SomeFunction\")<\/code>, but if it is exported from an 80386 DLL as extern &#8220;C&#8221; __stdcall, you would need <code>GetProcAddress(hinst, \"_SomeFunction@8\")<\/code>, but if it&#8217;s __fastcall you would need <code>GetProcAddress(hinst, \"@SomeFunction@8\")<\/code>.\nWhat&#8217;s more, C++ decoration varies from compiler vendor to compiler vendor. A C++ exported function might require <code>GetProcAddress(hinst, \"?SomeFunction@@YGXHH@Z\")<\/code> if compiled with the Microsoft C++ compiler, but some other decorated string if compiled with the Borland C++ compiler.\nSo if you intend people to be able to <code>GetProcAddress<\/code> for functions and you intend your code to be portable to multiple platforms, or if you intend them  to be able to use your DLL from a language other than C\/C++ or use a C++ compiler different from Microsoft Visual Studio, then you must export the function by its undecorated name.\nWhen a DLL is generated, the linker produces a matching LIB file which translates the decorated names to undecorated names. So, for example, the LIB file has an entry that says, &#8220;If somebody asks for the function _GetTickCount@0, send them to kernel32!GetTickCount.&#8221;\n Exercise: If <code>dllexport<\/code> ties you to an architecture, compiler, and language (by exporting decorated names), then why does MSVCRT.DLL use it?\n<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The dllexport attribute tells the linker to generate an export table entry for the specified function. This export entry is decorated. This is necessary to support dllexporting of overloaded functions. But it also means that the string you pass to GetProcAddress needs to be decorated. As we learned earlier, the decoration scheme varies from architecture [&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-41083","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The dllexport attribute tells the linker to generate an export table entry for the specified function. This export entry is decorated. This is necessary to support dllexporting of overloaded functions. But it also means that the string you pass to GetProcAddress needs to be decorated. As we learned earlier, the decoration scheme varies from architecture [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/41083","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=41083"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/41083\/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=41083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=41083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=41083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}