Error C2039: 'SetDefaultDllDirectories' when targetting Visual Studio 2012 Windows XP C++ Runtime
We’re switching our legacy C++ projects from Visual C++ 2010 to the Visual C++ 2012 Runtime, now that Microsoft allows you to target Windows XP for C++ in 2012 (available in Visual Studio Update 1).
So that involves switching the Platform Target from v100:
Well upon compilation, I saw these errors for one particular project:
The key error being Error C2039: ‘SetDefaultDllDirectories’ : is not a member of ‘`global namespace” from line 638 in atlcore.h
Well if we jump into that code, we see this:
// the LOAD_LIBRARY_SEARCH_SYSTEM32 flag for LoadLibraryExW is only supported if the DLL-preload fixes are installed, so
// use LoadLibraryExW only if SetDefaultDllDirectories is available (only on Win8, or with KB2533623 on Vista and Win7)...
IFDYNAMICGETCACHEDFUNCTION(L"kernel32.dll", SetDefaultDllDirectories, pfSetDefaultDllDirectories)
return(::LoadLibraryExW(pszLibrary, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32));
It looks like that define should exist, as we’re targeting “V110_SDK71” (aka v110_xp).
Well, with a little digging, that define is getting created by the C++ MSBuild files in C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Platforms\Win32\PlatformToolsets\v110_xp\Microsoft.Cpp.Win32.v110_xp.props:
<ItemDefinitionGroup> <ClCompile> <!-- Add /D_USING_V110_SDK71_ when targeting XP --> <PreprocessorDefinitions>_USING_V110_SDK71_;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile>
Otherwise, you can simply remove the PreprocessorDefinition element itself (if you have no defines of your own), or choose to inherit from the parent or project defaults from the project properties (which will essentially do the same thing):