{"id":4293,"date":"2009-08-27T17:15:00","date_gmt":"2009-08-27T17:15:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2009\/08\/27\/windows-sdk-v7-0v7-0a-incompatibility-workaround\/"},"modified":"2019-02-18T18:45:48","modified_gmt":"2019-02-18T18:45:48","slug":"windows-sdk-v7-0v7-0a-incompatibility-workaround","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/windows-sdk-v7-0v7-0a-incompatibility-workaround\/","title":{"rendered":"Windows SDK V7.0\/V7.0A Incompatibility Workaround"},"content":{"rendered":"<p class=\"MsoNormal\"><span>Hi,<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>My name is Nada AboElseoud and I am a QA in VC++ Libraries team. I joined MS in February 2009. I would like to talk here about an incompatibility issue with WinSDK v7.0*.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>If you are a developer who has recently migrated to WinSDK v7.0 (standalone SDK) or v7.0A (inbox with VS 2010), you may encounter these kinds of errors &ldquo;The procedure entry point K32*** could not be located in the dynamic link library KERNEL32.dll<span>&rdquo; <\/span>while running your application.<span>&nbsp; <\/span>This implies that you are running your application on an OS other than Windows7 or Windows Server 2008 R2. This blog will explain this blocking issue and provide the workaround.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Let me explain first why this issue happens.<span>&nbsp; <\/span>For performance reasons, some APIs have been moved from Psapi.dll to Kernel32.dll in Windows7 and Windows Server 2008 R2. WinSDK v7.0* is reflecting these modifications to be compatible with the new system dlls. This is <b>by design<\/b>, but wait! If you are trying to link your application to Psapi.lib and then targeting any pre Windows7 or pre Windows Server 2008 R2, you will get this runtime error. Breaking this down, all APIs from Psapi.dll are copied to Kernel32.dll in Windows7 and Windows Server 2008 R2 (Psapi.dll remain unchanged though). Linking to Psapi.lib marks these APIs as Kernel32 APIs to load them from Kernel32.dll instead. <span>&nbsp;&nbsp;<\/span>Following is the list of these APIs.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>\/\/Snapshot from Psapi.lib &ndash; WinSDK V7.0*<\/p>\n<p><\/span><\/b><\/p>\n<p class=\"MsoNormal\"><span>#if (PSAPI_VERSION &gt; 1) <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EnumProcesses&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32EnumProcesses<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EnumProcessModules&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32EnumProcessModules<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EnumProcessModulesEx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32EnumProcessModulesEx<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetModuleBaseNameA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetModuleBaseNameA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetModuleBaseNameW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetModuleBaseNameW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetModuleFileNameExA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetModuleFileNameExA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetModuleFileNameExW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetModuleFileNameExW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetModuleInformation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetModuleInformation<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EmptyWorkingSet &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;K32EmptyWorkingSet<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define QueryWorkingSet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32QueryWorkingSet<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define QueryWorkingSetEx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32QueryWorkingSetEx<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define InitializeProcessForWsWatch K32InitializeProcessForWsWatch<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetWsChanges&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetWsChanges<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetWsChangesEx&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetWsChangesEx<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetMappedFileNameW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetMappedFileNameW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetMappedFileNameA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetMappedFileNameA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EnumDeviceDrivers&nbsp;&nbsp;&nbsp;&amp;n\nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32EnumDeviceDrivers<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetDeviceDriverBaseNameA&nbsp;&nbsp;&nbsp; K32GetDeviceDriverBaseNameA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetDeviceDriverBaseNameW&nbsp;&nbsp;&nbsp; K32GetDeviceDriverBaseNameW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetDeviceDriverFileNameA&nbsp;&nbsp;&nbsp; K32GetDeviceDriverFileNameA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetDeviceDriverFileNameW&nbsp;&nbsp;&nbsp; K32GetDeviceDriverFileNameW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetProcessMemoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetProcessMemoryInfo<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetPerformanceInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32GetPerformanceInfo<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EnumPageFilesW&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32EnumPageFilesW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define EnumPageFilesA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; K32EnumPageFilesA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetProcessImageFileNameA&nbsp;&nbsp;&nbsp; K32GetProcessImageFileNameA<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#define GetProcessImageFileNameW&nbsp;&nbsp;&nbsp; K32GetProcessImageFileNameW<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#endif<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Now, it should be obvious why by calling some API (say <i>EnumProcessModules<\/i>) you get this runtime error &ldquo;The procedure entry point <i>K32EnumProcessModules<\/i> could not be located in the dynamic link library KERNEL32.dll&rdquo; pointing to a different API name.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>However, did you notice the IF condition involved?<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>#if (PSAPI_VERSION &gt; 1) <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>This means that these APIs are defined\/tagged only if the PSAPI_VERSION &gt; 1. By default this value is set to 2 and _WIN32_WINNT is set to _WIN32_WINNT_MAXVER (which is 0x601 for Win7).<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><b><span>Workaround<\/p>\n<p><\/span><\/b><\/p>\n<p class=\"MsoNormal\"><span>After reading about this issue, you may be able now to figure out the solution. Simply,<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>if you target any OS prior to Windows7 and Windows 2008 R2, what you need to do is to define _WIN32_WINNT to a previous version (before 0x601) or to define Psapi_version to 1.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>For example:<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>cl \/MD \/EHsc &nbsp;<b>\/D _WIN32_WINNT=0x501<\/b> mytest.cpp \/link Psapi.lib<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Or<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>cl \/MD \/EHsc &nbsp;<b>\/D PSAPI_VERSION=1<\/b> mytest.cpp \/link Psapi.lib<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Does this mean that this generated exe will work fine on Windows7 and Windows Server 2008 R2 as well? Definitely. As stated above, Psapi.dll is not modified and the workaround is just loading the APIs from Psapi.dll.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Otherwise, if you are just targeting Windows7 (or Windows 2008 R2), to take advantage of this performance boost, you can simply use the default predefined macros or explicitly define them as below.<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>cl \/MD \/EHsc &nbsp;<b>\/D _WIN32_WINNT=0x601<\/b> mytest.cpp \/link Psapi.lib<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Or<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>cl \/MD \/EHsc &nbsp;<b>\/D PSAPI_VERSION=2<\/b> mytest.cpp \/link Psapi.lib<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><span>&nbsp;<\/span><\/span><span><\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Hope this is helpful <\/span><span><span>J<\/span><\/span><span> <\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span>Nada <span>&nbsp;<\/span>AboElseoud<\/p>\n<p><\/span><\/p>\n<p class=\"MsoNormal\"><span><\/p>\n<p>&nbsp;<\/p>\n<p><\/span><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, My name is Nada AboElseoud and I am a QA in VC++ Libraries team. I joined MS in February 2009. I would like to talk here about an incompatibility issue with WinSDK v7.0*. If you are a developer who has recently migrated to WinSDK v7.0 (standalone SDK) or v7.0A (inbox with VS 2010), you [&hellip;]<\/p>\n","protected":false},"author":289,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[28],"class_list":["post-4293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","tag-winsdk"],"acf":[],"blog_post_summary":"<p>Hi, My name is Nada AboElseoud and I am a QA in VC++ Libraries team. I joined MS in February 2009. I would like to talk here about an incompatibility issue with WinSDK v7.0*. If you are a developer who has recently migrated to WinSDK v7.0 (standalone SDK) or v7.0A (inbox with VS 2010), you [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/289"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=4293"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/4293\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=4293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=4293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=4293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}