{"id":28533,"date":"2007-01-02T10:00:04","date_gmt":"2007-01-02T10:00:04","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2007\/01\/02\/why-cant-i-getprocaddress-for-createwindow\/"},"modified":"2007-01-02T10:00:04","modified_gmt":"2007-01-02T10:00:04","slug":"why-cant-i-getprocaddress-for-createwindow","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20070102-04\/?p=28533","title":{"rendered":"Why can&#039;t I GetProcAddress for CreateWindow?"},"content":{"rendered":"<p>\nOccasionally, I&#8217;ll see people having trouble trying to\n<code>GetProcAddress<\/code> for functions like\n<code>CreateWindow<\/code> or <code>ExitWindows<\/code>.\nUsually, it&#8217;s coming from people who are\ntrying to write p\/invoke signatures,\nfor p\/invoke does a <code>GetProcAddress<\/code> under the covers.\nWhy can&#8217;t you <code>GetProcAddress<\/code> for these functions?\n<\/p>\n<p>\nBecause they&#8217;re not really functions.\nThey&#8217;re function-like macros:\n<\/p>\n<pre>\n#define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\\\nnWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\\\nCreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\\\nnWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\n#define CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y,\\\nnWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\\\nCreateWindowExW(0L, lpClassName, lpWindowName, dwStyle, x, y,\\\nnWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\n#ifdef UNICODE\n#define CreateWindow  CreateWindowW\n#else\n#define CreateWindow  CreateWindowA\n#endif \/\/ !UNICODE\n#define ExitWindows(dwReserved, Code) ExitWindowsEx(EWX_LOGOFF, 0xFFFFFFFF)\n<\/pre>\n<p>\nIn fact, as you can see above <code>CreateWindow<\/code> is doubly\na macro.\nFirst, it&#8217;s a redirecting macro\nthat expands to either <code>CreateWindowA<\/code>\nor <code>CreateWindowW<\/code>, depending on whether or not you are compiling\n<code>UNICODE<\/code>.\nThose are in turn function-like macros that call the real\nfunction <code>CreateWindowExA<\/code> or <code>CreateWindowExW<\/code>.\nAll this is handled by the compiler if you include the\n<code>winuser.h<\/code> header file,\nbut if for some reason you want to <code>GetProcAddress<\/code>\nfor a function-like macro like <code>CreateWindow<\/code>, you&#8217;ll have\nto manually expand the macro to see what the real function is\nand pass that function name to <code>GetProcAddress<\/code>.\n<\/p>\n<p>\nSimilar remarks apply to inline functions.\nThese functions can&#8217;t be obtained via <code>GetProcAddress<\/code>\nbecause they aren&#8217;t exported at all; they are provided to you\nas source code in the header file.\n<\/p>\n<p>\nNote that whether something is a true function or a function-like\nmacro (or an inline function) can depend on your target platform.\nFor example, <code>GetWindowLongPtrA<\/code> is a true exported\nfunction on 64-bit Windows, but on 32-bit Windows,\nit&#8217;s just a macro that resolves\nto <code>GetWindowLongA<\/code>.\nAs another example,\nthe <code>Interlocked<\/code> family of functions are\nexported functions on the x86 version of Windows but are\ninlined functions on all other Windows architectures.\n<\/p>\n<p>\nHow can you figure all this out?\nRead the header files.\nThat&#8217;ll show you whether the function you want is a\nredirecting macro,\na function-like macro,\nan inline function,\nan intrinsic function,\nor a proper exported function.\nIf you can&#8217;t figure it out from the header files, you can always\njust write a program that calls the function you&#8217;re interested in\nand then look at the disassembly to see what actually got generated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally, I&#8217;ll see people having trouble trying to GetProcAddress for functions like CreateWindow or ExitWindows. Usually, it&#8217;s coming from people who are trying to write p\/invoke signatures, for p\/invoke does a GetProcAddress under the covers. Why can&#8217;t you GetProcAddress for these functions? Because they&#8217;re not really functions. They&#8217;re function-like macros: #define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, [&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-28533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Occasionally, I&#8217;ll see people having trouble trying to GetProcAddress for functions like CreateWindow or ExitWindows. Usually, it&#8217;s coming from people who are trying to write p\/invoke signatures, for p\/invoke does a GetProcAddress under the covers. Why can&#8217;t you GetProcAddress for these functions? Because they&#8217;re not really functions. They&#8217;re function-like macros: #define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28533","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=28533"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/28533\/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=28533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=28533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=28533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}